fix for #480 -- addition of 'viewRequestID' variable to map to keep track of the changing view requests so that images dont load when they are no longer needed. muchas gracias to senior woodall for his help getting this patch together

git-svn-id: http://svn.openlayers.org/trunk/openlayers@2231 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
euzuro
2007-02-16 20:24:56 +00:00
parent 8095e22600
commit 3309b0b12e
4 changed files with 47 additions and 3 deletions

View File

@@ -77,6 +77,18 @@ OpenLayers.Map.prototype = {
/** @type int */
zoom: 0,
/** Used to store a unique identifier that changes when the map view
* changes. viewRequestID should be used when adding data asynchronously
* to the map: viewRequestID is incremented when you initiate your
* request (right now during changing of baselayers and changing of zooms).
* It is stored here in the map and also in the data that will be coming
* back asynchronously. Before displaying this data on request completion,
* we check that the viewRequestID of the data is still the same as that
* of the map. Fix for #480
*
* @type String */
viewRequestID: 0,
// Options
/** @type OpenLayers.Size */
@@ -448,6 +460,11 @@ OpenLayers.Map.prototype = {
// set new baselayer and make it visible
this.baseLayer = newBaseLayer;
// Increment viewRequestID since the baseLayer is
// changing. This is used by tiles to check if they should
// draw themselves.
this.viewRequestID++;
this.baseLayer.setVisibility(true, noEvent);
//redraw all layers
@@ -743,6 +760,9 @@ OpenLayers.Map.prototype = {
for (var i = 0; i < this.popups.length; i++) {
this.popups[i].updatePosition();
}
// zoom level has changed, increment viewRequestID.
this.viewRequestID++;
}
var bounds = this.getExtent();

View File

@@ -34,6 +34,7 @@ OpenLayers.Tile.Image.prototype =
destroy: function() {
if ((this.imgDiv != null) && (this.imgDiv.parentNode == this.layer.div)) {
this.layer.div.removeChild(this.imgDiv);
this.imgDiv.map = null;
}
this.imgDiv = null;
OpenLayers.Tile.prototype.destroy.apply(this, arguments);
@@ -52,6 +53,8 @@ OpenLayers.Tile.Image.prototype =
if (this.imgDiv == null) {
this.initImgDiv();
}
this.imgDiv.viewRequestID = this.layer.map.viewRequestID;
this.url = this.layer.getURL(this.bounds);
@@ -132,6 +135,10 @@ OpenLayers.Tile.Image.prototype =
null, null, null,
this.layer.opacity);
}
// we need this reference to check back the viewRequestID
this.imgDiv.map = this.layer.map;
},
/**

View File

@@ -217,8 +217,25 @@ OpenLayers.Util.setOpacity = function(element, opacity) {
}
OpenLayers.Util.onImageLoad = function() {
this.style.backgroundColor = null;
this.style.display = "";
// The complex check here is to solve issues described in #480.
// Every time a map view changes, it increments the 'viewRequestID'
// property. As the requests for the images for the new map view are sent
// out, they are tagged with this unique viewRequestID.
//
// If an image has no viewRequestID property set, we display it regardless,
// but if it does have a viewRequestID property, we check that it matches
// the viewRequestID set on the map.
//
// If the viewRequestID on the map has changed, that means that the user
// has changed the map view since this specific request was sent out, and
// therefore this tile does not need to be displayed (so we do not execute
// this code that turns its display on).
//
if (!this.viewRequestID ||
(this.viewRequestID == this.map.viewRequestID)) {
this.style.backgroundColor = null;
this.style.display = "";
}
};
OpenLayers.Util.onImageLoadErrorColor = "pink";

View File

@@ -11,7 +11,7 @@
<script type="text/javascript">
<!--
function init(){
map = new OpenLayers.Map('map', {'maxResolution': 1.40625/2, tileSize: new OpenLayers.Size(256,256)});
var map = new OpenLayers.Map('map', {'maxResolution': 1.40625/2, tileSize: new OpenLayers.Size(256,256)});
ww = new OpenLayers.Layer.WMS( "Basic",
"http://labs.metacarta.com/wms-c/Basic.py?",
{layers:"basic"});