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.
This commit is contained in:
ahocevar
2011-12-26 11:09:07 +01:00
parent ff04517232
commit d42eec9775
4 changed files with 21 additions and 15 deletions

View File

@@ -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
* <moveTo>.
*/
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;
}
},

View File

@@ -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);
},
/**

View File

@@ -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");

View File

@@ -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;