From d42eec97756d88f92147a46319484c55e8623a1a Mon Sep 17 00:00:00 2001 From: ahocevar Date: Mon, 26 Dec 2011 11:09:07 +0100 Subject: [PATCH] No new argument for Layer::redraw. Instead, make _resolution a private property (resolution) which is set to null to make redraw call moveTo with zoomChanged set to true. --- lib/OpenLayers/Layer.js | 21 +++++++++++++-------- lib/OpenLayers/Layer/HTTPRequest.js | 8 ++++---- tests/Layer.html | 3 ++- tests/Layer/HTTPRequest.html | 4 ++-- 4 files changed, 21 insertions(+), 15 deletions(-) diff --git a/lib/OpenLayers/Layer.js b/lib/OpenLayers/Layer.js index 2fd470a14e..dd6ebd790a 100644 --- a/lib/OpenLayers/Layer.js +++ b/lib/OpenLayers/Layer.js @@ -265,6 +265,14 @@ OpenLayers.Layer = OpenLayers.Class({ * {Float} */ minResolution: null, + + /** + * Property: resolution + * {Float} Current resolution that the layer is drawn in. Used by + * subclasses to determine whether the zoom has changed when calling + * . + */ + resolution: null, /** * APIProperty: numZoomLevels @@ -541,9 +549,7 @@ OpenLayers.Layer = OpenLayers.Class({ * Returns: * {Boolean} The layer was redrawn. */ - redraw: function(zoomChanged) { - // zoomChanged forces a zoom change in the layer's moveTo - // call. This isn't documented because not part of the API. + redraw: function() { var redrawn = false; if (this.map) { @@ -554,9 +560,8 @@ OpenLayers.Layer = OpenLayers.Class({ var extent = this.getExtent(); if (extent && this.inRange && this.visibility) { - zoomChanged = zoomChanged || - this._resolution === undefined || - this._resolution !== this.map.getResolution(); + zoomChanged = this.resolution == null || + this.resolution !== this.map.getResolution(); this.moveTo(extent, zoomChanged, false); this.events.triggerEvent("moveend", {"zoomChanged": zoomChanged}); @@ -581,7 +586,7 @@ OpenLayers.Layer = OpenLayers.Class({ display = display && this.inRange; } this.display(display); - this._resolution = this.map.getResolution(); + this.resolution = this.map.getResolution(); }, /** @@ -638,7 +643,7 @@ OpenLayers.Layer = OpenLayers.Class({ // deal with gutters this.setTileSize(); - delete this._resolution; + this.resolution = null; } }, diff --git a/lib/OpenLayers/Layer/HTTPRequest.js b/lib/OpenLayers/Layer/HTTPRequest.js index 3841c9f73d..8f939f7b40 100644 --- a/lib/OpenLayers/Layer/HTTPRequest.js +++ b/lib/OpenLayers/Layer/HTTPRequest.js @@ -120,7 +120,8 @@ OpenLayers.Layer.HTTPRequest = OpenLayers.Class(OpenLayers.Layer, { */ mergeNewParams:function(newParams) { this.params = OpenLayers.Util.extend(this.params, newParams); - var ret = OpenLayers.Layer.prototype.redraw.call(this, true); + this.resolution = null; + var ret = this.redraw(); if(this.map != null) { this.map.events.triggerEvent("changelayer", { layer: this, @@ -142,10 +143,9 @@ OpenLayers.Layer.HTTPRequest = OpenLayers.Class(OpenLayers.Layer, { */ redraw: function(force) { if (force) { - return this.mergeNewParams({"_olSalt": Math.random()}); - } else { - return OpenLayers.Layer.prototype.redraw.call(this); + this.params["_olSalt"] = Math.random(); } + return OpenLayers.Layer.prototype.redraw.call(this); }, /** diff --git a/tests/Layer.html b/tests/Layer.html index 01f5218cab..d3b5072f4c 100644 --- a/tests/Layer.html +++ b/tests/Layer.html @@ -710,7 +710,8 @@ "[a] redraw calls moveTo with zoomChanged false"); log = {}; - l1.redraw(true); + l1.resolution = null; + l1.redraw(); t.eq(log.moveTo.zoomChanged, true, "[b] redraw calls moveTo with zoomChanged true"); diff --git a/tests/Layer/HTTPRequest.html b/tests/Layer/HTTPRequest.html index e753586dd0..2025677fe4 100644 --- a/tests/Layer/HTTPRequest.html +++ b/tests/Layer/HTTPRequest.html @@ -95,8 +95,8 @@ t.eq( layer.params.chickpeas, "image/png", "mergeNewParams() makes clean copy of hash"); var redraw = OpenLayers.Layer.prototype.redraw; - OpenLayers.Layer.prototype.redraw = function(forceZoomChanged) { - t.eq(forceZoomChanged, true, 'mergeNewParams() sends true to Layer.redraw'); + OpenLayers.Layer.prototype.redraw = function() { + t.eq(this.resolution, null, 'mergeNewParams sets layer resolution to null, causing redraw to call moveTo with zoomChanged set to true'); }; layer.mergeNewParams(); OpenLayers.Layer.prototype.redraw = redraw;