Add ol.Map.freeze/thaw
This commit is contained in:
@@ -42,6 +42,18 @@ ol.Map = function(target, opt_values, opt_viewportSizeMonitor) {
|
||||
|
||||
goog.base(this);
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.animating_ = false;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {number}
|
||||
*/
|
||||
this.freezeCount_ = 0;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {HTMLDivElement}
|
||||
@@ -120,6 +132,13 @@ ol.Map.prototype.forEachLayerRenderer = function(f, opt_obj) {
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
*/
|
||||
ol.Map.prototype.freeze = function() {
|
||||
++this.freezeCount_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return {goog.math.Coordinate|undefined} Center.
|
||||
*/
|
||||
@@ -365,6 +384,28 @@ ol.Map.prototype.recalculateExtent_ = function() {
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @protected
|
||||
*/
|
||||
ol.Map.prototype.redraw = function() {
|
||||
if (!this.animating_) {
|
||||
if (this.freezeCount_ === 0) {
|
||||
this.redrawInternal();
|
||||
} else {
|
||||
this.dirty_ = true;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @protected
|
||||
*/
|
||||
ol.Map.prototype.redrawInternal = function() {
|
||||
this.dirty_ = false;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {goog.math.Coordinate} center Center.
|
||||
*/
|
||||
@@ -394,8 +435,10 @@ ol.Map.prototype.setDefaultCenterAndResolution_ = function() {
|
||||
* @param {ol.Extent} extent Extent.
|
||||
*/
|
||||
ol.Map.prototype.setExtent = function(extent) {
|
||||
this.whileFrozen(function() {
|
||||
this.setCenter(extent.getCenter());
|
||||
this.setResolution(this.getResolutionForExtent(extent));
|
||||
}, this);
|
||||
};
|
||||
|
||||
|
||||
@@ -433,3 +476,30 @@ ol.Map.prototype.setSize = function(size) {
|
||||
ol.Map.prototype.setProjection = function(projection) {
|
||||
this.set(ol.MapProperty.PROJECTION, projection);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {function(this: T)} f Function.
|
||||
* @param {T=} opt_obj Object.
|
||||
* @template T
|
||||
*/
|
||||
ol.Map.prototype.whileFrozen = function(f, opt_obj) {
|
||||
this.freeze();
|
||||
try {
|
||||
f.call(opt_obj);
|
||||
} finally {
|
||||
this.thaw();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
*/
|
||||
ol.Map.prototype.thaw = function() {
|
||||
goog.asserts.assert(this.freezeCount_ > 0);
|
||||
if (--this.freezeCount_ === 0) {
|
||||
if (!this.animating_ && !this.dirty_) {
|
||||
this.redrawInternal();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -110,7 +110,7 @@ ol.webgl.Map.prototype.getGL = function() {
|
||||
*/
|
||||
ol.webgl.Map.prototype.handleCenterChanged = function() {
|
||||
goog.base(this, 'handleCenterChanged');
|
||||
this.redraw_();
|
||||
this.redraw();
|
||||
};
|
||||
|
||||
|
||||
@@ -120,7 +120,7 @@ ol.webgl.Map.prototype.handleCenterChanged = function() {
|
||||
ol.webgl.Map.prototype.handleLayerAdd = function(layer) {
|
||||
goog.base(this, 'handleLayerAdd', layer);
|
||||
if (layer.getVisible()) {
|
||||
this.redraw_();
|
||||
this.redraw();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -131,7 +131,7 @@ ol.webgl.Map.prototype.handleLayerAdd = function(layer) {
|
||||
ol.webgl.Map.prototype.handleLayerRemove = function(layer) {
|
||||
goog.base(this, 'handleLayerRemove', layer);
|
||||
if (layer.getVisible()) {
|
||||
this.redraw_();
|
||||
this.redraw();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -141,7 +141,7 @@ ol.webgl.Map.prototype.handleLayerRemove = function(layer) {
|
||||
*/
|
||||
ol.webgl.Map.prototype.handleResolutionChanged = function() {
|
||||
goog.base(this, 'handleResolutionChanged');
|
||||
this.redraw_();
|
||||
this.redraw();
|
||||
};
|
||||
|
||||
|
||||
@@ -159,7 +159,7 @@ ol.webgl.Map.prototype.handleSizeChanged = function() {
|
||||
var gl = this.gl_;
|
||||
if (!goog.isNull(gl)) {
|
||||
gl.viewport(0, 0, size.width, size.height);
|
||||
this.redraw_();
|
||||
this.redraw();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -194,9 +194,11 @@ ol.webgl.Map.prototype.handleWebGLContextRestored = function() {
|
||||
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @protected
|
||||
*/
|
||||
ol.webgl.Map.prototype.redraw_ = function() {
|
||||
ol.webgl.Map.prototype.redraw = function() {
|
||||
|
||||
goog.base(this, 'redraw');
|
||||
|
||||
var gl = this.getGL();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user