Rename freeze/thaw to freezeRendering/unfreezeRendering

This commit is contained in:
Tom Payne
2012-07-22 22:24:04 +02:00
parent a2f24b9d43
commit 269bd9387e
3 changed files with 30 additions and 31 deletions

View File

@@ -1,4 +1,3 @@
// FIXME rename freeze/thaw to freezeRendering/unfreezeRendering
// FIXME add change resolution by zoom step function
// FIXME recheck layer/map projection compatability when projection changes
// FIXME layer renderers should skip when they can't reproject
@@ -135,7 +134,7 @@ ol.Map = function(target, opt_values, opt_viewportSizeMonitor) {
* @private
* @type {number}
*/
this.freezeCount_ = 0;
this.freezeRenderingCount_ = 0;
/**
* @private
@@ -219,13 +218,6 @@ ol.Map.prototype.animate_ = function() {
ol.Map.prototype.createLayerRenderer = goog.abstractMethod;
/**
*/
ol.Map.prototype.freeze = function() {
++this.freezeCount_;
};
/**
* @inheritDoc
*/
@@ -241,7 +233,7 @@ ol.Map.prototype.disposeInternal = function() {
* @param {ol.Extent} extent Extent.
*/
ol.Map.prototype.fitExtent = function(extent) {
this.whileFrozen(function() {
this.withFrozenRendering(function() {
this.setCenter(extent.getCenter());
this.setResolution(this.getResolutionForExtent(extent));
}, this);
@@ -272,6 +264,13 @@ ol.Map.prototype.forEachVisibleLayer = function(f, opt_obj) {
};
/**
*/
ol.Map.prototype.freezeRendering = function() {
++this.freezeRenderingCount_;
};
/**
* @return {ol.Color|undefined} Background color.
*/
@@ -640,7 +639,7 @@ ol.Map.prototype.recalculateTransforms_ = function() {
*/
ol.Map.prototype.render = function() {
if (!this.animating_) {
if (this.freezeCount_ === 0) {
if (this.freezeRenderingCount_ === 0) {
if (this.renderInternal()) {
this.animate_();
}
@@ -776,25 +775,10 @@ ol.Map.prototype.setUserProjection = function(userProjection) {
/**
* @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) {
ol.Map.prototype.unfreezeRendering = function() {
goog.asserts.assert(this.freezeRenderingCount_ > 0);
if (--this.freezeRenderingCount_ === 0) {
if (!this.animating_ && this.dirty_) {
if (this.renderInternal()) {
this.animate_();
@@ -804,6 +788,21 @@ ol.Map.prototype.thaw = function() {
};
/**
* @param {function(this: T)} f Function.
* @param {T=} opt_obj Object.
* @template T
*/
ol.Map.prototype.withFrozenRendering = function(f, opt_obj) {
this.freezeRendering();
try {
f.call(opt_obj);
} finally {
this.unfreezeRendering();
}
};
/**
* @constructor

View File

@@ -23,7 +23,7 @@ ol.control.DblClickZoom.prototype.handleMapBrowserEvent =
function(mapBrowserEvent) {
if (mapBrowserEvent.type == goog.events.EventType.DBLCLICK) {
var map = mapBrowserEvent.map;
map.whileFrozen(function() {
map.withFrozenRendering(function() {
// FIXME compute correct center for zoom
map.setCenter(mapBrowserEvent.getCoordinate());
var browserEvent = mapBrowserEvent.browserEvent;

View File

@@ -28,7 +28,7 @@ ol.control.MouseWheelZoom.prototype.handleMapBrowserEvent =
mapBrowserEvent.browserEvent;
goog.asserts.assert(mouseWheelEvent instanceof goog.events.MouseWheelEvent);
if (mouseWheelEvent.deltaY !== 0) {
map.whileFrozen(function() {
map.withFrozenRendering(function() {
// FIXME compute correct center for zoom
map.setCenter(mapBrowserEvent.getCoordinate());
var scale = mouseWheelEvent.deltaY < 0 ? 0.5 : 2;