Keeping a reference to the event pane when a layer is removed from the map. The pane is set in initialize and set to null in destroy. r=ahocevar (closes #2456)

git-svn-id: http://svn.openlayers.org/trunk/openlayers@10013 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
Tim Schaub
2010-02-03 16:28:29 +00:00
parent ec455e81e1
commit af1e754546
2 changed files with 41 additions and 3 deletions

View File

@@ -80,6 +80,7 @@ OpenLayers.Layer.EventPane = OpenLayers.Class(OpenLayers.Layer, {
*/
destroy: function() {
this.mapObject = null;
this.pane = null;
OpenLayers.Layer.prototype.destroy.apply(this, arguments);
},
@@ -131,7 +132,6 @@ OpenLayers.Layer.EventPane = OpenLayers.Class(OpenLayers.Layer, {
removeMap: function(map) {
if (this.pane && this.pane.parentNode) {
this.pane.parentNode.removeChild(this.pane);
this.pane = null;
}
OpenLayers.Layer.prototype.removeMap.apply(this, arguments);
},

View File

@@ -118,8 +118,46 @@
layer.getWarningHTML = function() { this.warning = true; return ""; };
map.addLayer(layer);
map.removeLayer(layer);
t.eq(layer.pane, null, "Layer.pane is null after being removed.");
}
var parent = layer.pane.parentNode;
// IE creates a DOCUMENT_FRAGMENT_NODE for the parent
t.ok(!parent || parent.nodeType == 11, "Layer.pane removed from dom.");
}
function test_repeat_add(t) {
t.plan(1);
var map = new OpenLayers.Map("map");
layer = new OpenLayers.Layer.EventPane();
layer.loadMapObject = function() {};
layer.getWarningHTML = function() {this.warning = true; return "";};
map.addLayer(layer);
map.removeLayer(layer);
// try adding the layer a second time
var msg = "layer successfully added after being removed";
var pass = true;
try {
map.addLayer(layer);
} catch (err) {
msg = "couldn't add layer after removing: " + err;
pass = false;
}
t.ok(pass, msg);
}
function test_destroy(t) {
t.plan(2);
layer = new OpenLayers.Layer.EventPane();
t.ok(layer.pane, "pane created on initialize");
layer.destroy();
t.ok(!layer.pane, "pane deleted on destroy");
}
</script>