fix for #795 - all layers now have a redraw() method that simply redraws them no matter whether the extent or parameters or zoom has changed. Big big thanks to tim schaub for not only taking the time to listen to my relentless (and often cracked) brainstorming about this ticket and for taking the time out to review the final patch.... but above and beyond the call of duty, adding *tests* for this patch. real ace. top knotch.

git-svn-id: http://svn.openlayers.org/trunk/openlayers@3582 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
euzuro
2007-07-05 14:04:51 +00:00
parent 364e7d7546
commit 2cf67f76d0
6 changed files with 78 additions and 27 deletions

View File

@@ -334,6 +334,31 @@ OpenLayers.Layer.prototype = {
//this function can be implemented by subclasses
},
/**
* APIMethod: redraw
* Redraws the layer. Returns true if the layer was redrawn, false if not.
*
* Return:
* {Boolean} The layer was redrawn.
*/
redraw: function() {
var redrawn = false;
if (this.map) {
// min/max Range may have changed
this.inRange = this.calculateInRange();
// map's center might not yet be set
var extent = this.getExtent();
if (extent && this.inRange && this.visibility) {
this.moveTo(extent, true, false);
redrawn = true;
}
}
return redrawn;
},
/**
* Method: moveTo
*
@@ -451,12 +476,7 @@ OpenLayers.Layer.prototype = {
if (visibility != this.visibility) {
this.visibility = visibility;
this.display(visibility);
if (visibility && this.map != null) {
var extent = this.map.getExtent();
if (extent != null) {
this.moveTo(extent, true);
}
}
this.redraw();
if ((this.map != null) &&
((noEvent == null) || (noEvent == false))) {
this.map.events.triggerEvent("changelayer");

View File

@@ -241,7 +241,7 @@ OpenLayers.Layer.MapServer.Untiled.prototype =
*/
setUrl: function(newUrl) {
OpenLayers.Layer.HTTPRequest.prototype.setUrl.apply(this, arguments);
this.moveTo();
this.redraw();
},
/**
@@ -254,8 +254,7 @@ OpenLayers.Layer.MapServer.Untiled.prototype =
mergeNewParams:function(newParams) {
OpenLayers.Layer.HTTPRequest.prototype.mergeNewParams.apply(this,
[newParams]);
//redraw
this.moveTo(null, true);
this.redraw();
},
/**

View File

@@ -72,7 +72,9 @@ OpenLayers.Layer.Markers.prototype =
OpenLayers.Layer.prototype.moveTo.apply(this, arguments);
if (zoomChanged || !this.drawn) {
this.redraw();
for(i=0; i < this.markers.length; i++) {
this.drawMarker(this.markers[i]);
}
this.drawn = true;
}
},
@@ -116,17 +118,6 @@ OpenLayers.Layer.Markers.prototype =
}
},
/**
* APIMethod: redraw
* Clear all the marker div's from the layer and then redraw all of them.
* Use the map to recalculate new placement of markers.
*/
redraw: function() {
for(i=0; i < this.markers.length; i++) {
this.drawMarker(this.markers[i]);
}
},
/**
* Method: drawMarker
* Calculate the pixel location for the marker, create it, and

View File

@@ -257,7 +257,7 @@ OpenLayers.Layer.WMS.Untiled.prototype =
*/
setUrl: function(newUrl) {
OpenLayers.Layer.HTTPRequest.prototype.setUrl.apply(this, arguments);
this.moveTo();
this.redraw();
},
/**
@@ -272,8 +272,7 @@ OpenLayers.Layer.WMS.Untiled.prototype =
var newArguments = [upperParams];
OpenLayers.Layer.HTTPRequest.prototype.mergeNewParams.apply(this,
newArguments);
//redraw
this.moveTo(null, true);
this.redraw();
},
/**

View File

@@ -518,9 +518,7 @@ OpenLayers.Map.prototype = {
layer.setVisibility(false);
}
} else {
if (this.getCenter() != null) {
layer.moveTo(this.getExtent(), true);
}
layer.redraw();
}
this.events.triggerEvent("addlayer");

View File

@@ -165,6 +165,50 @@
}
function test_Layer_redraw(t) {
t.plan(8)
var name = 'Test Layer';
var url = "http://octo.metacarta.com/cgi-bin/mapserv";
var params = { map: '/mapdata/vmap_wms.map',
layers: 'basic',
format: 'image/jpeg'};
var layer = new OpenLayers.Layer.WMS(name, url, params);
t.ok(!layer.redraw(),
"redraw on an orphan layer returns false");
var map = new OpenLayers.Map('map');
map.addLayer(layer);
t.ok(!layer.redraw(),
"redraw returns false if map does not yet have a center");
map.zoomToMaxExtent();
t.ok(layer.redraw(),
"redraw returns true after map has a center");
layer.setVisibility(false);
t.ok(!layer.redraw(),
"redraw returns false if a layer is not visible");
layer.setVisibility(true);
t.ok(layer.redraw(),
"redraw returns true even if extent has not changed");
layer.moveTo = function(bounds, zoomChanged, dragging) {
var extent = layer.map.getExtent();
t.ok(bounds.equals(extent),
"redraw calls moveTo with the map extent");
t.ok(zoomChanged,
"redraw calls moveTo with zoomChanged true");
t.ok(!dragging,
"redraw calls moveTo with dragging false");
}
layer.redraw();
}
/******
*