Skip to content

Commit

Permalink
the grid layer needs to clear its tile loading timeout when it's remo…
Browse files Browse the repository at this point in the history
…ved from the map, or moveGriddedTiles can be called with this.map set to null, r=crschmidt (closes #3110)

git-svn-id: http://svn.openlayers.org/trunk/openlayers@11482 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
  • Loading branch information
Éric Lemoine committed Feb 25, 2011
1 parent 339d1eb commit 4a4d9b2
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
14 changes: 14 additions & 0 deletions lib/OpenLayers/Layer/Grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,20 @@ OpenLayers.Layer.Grid = OpenLayers.Class(OpenLayers.Layer.HTTPRequest, {
);
},

/**
* Method: removeMap
* Called when the layer is removed from the map.
*
* Parameters:
* map - {<OpenLayers.Map>} The map.
*/
removeMap: function(map) {
if(this.timerId != null) {
window.clearTimeout(this.timerId);
this.timerId = null;
}
},

/**
* APIMethod: destroy
* Deconstruct the layer and clear the grid.
Expand Down
4 changes: 3 additions & 1 deletion tests/Layer/Grid.html
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@

function test_Layer_Grid_destroy (t) {

t.plan( 7 );
t.plan( 8 );

var map = new OpenLayers.Map('map');
layer = new OpenLayers.Layer.Grid(name, url, params);
Expand All @@ -608,6 +608,7 @@
map.addLayer(layer);

map.setCenter(new OpenLayers.LonLat(0,0), 10);
map.setCenter(new OpenLayers.LonLat(1,1));


//grab a reference to one of the tiles
Expand All @@ -616,6 +617,7 @@

layer.destroy();
t.eq( tile.imgDiv, null, "Tile destroyed" );
t.eq( layer.timerId, null, "Tile loading timeout cleared");

t.ok( layer.grid == null, "tiles appropriately destroyed")

Expand Down
6 changes: 6 additions & 0 deletions tests/Map.html
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,8 @@

valid = OpenLayers.Map.prototype.isValidZoomLevel.apply(map, [19]);
t.eq(valid, false, "19 is not a valid zoomLevel when baseLayer has restrictedMinZoom of 1");

map.destroy();
}

function test_Map_isValidLonLat(t) {
Expand Down Expand Up @@ -977,6 +979,8 @@
map.addControls(controls2, pixels2);
t.eq(map.controls.length, 5, "three additional controls were added by map.addControls with a px-array");
t.eq(map.controls[3].position.toString(), pixels2[1].toString(), "control 'fourthctrl' has position set to given px");

map.destroy();
}

function test_Map_getControl(t) {
Expand Down Expand Up @@ -1598,6 +1602,8 @@

t.eq(map.layers.length, 2, "multiple layers added from options");
t.ok(map.baseLayer, "map has a base layer");

map.destroy();

}

Expand Down

0 comments on commit 4a4d9b2

Please sign in to comment.