add removeLayer() function to Layers... implement it for EventPane so that it removes the extra 'pane' div when the layer is removed. (Closes #887)
git-svn-id: http://svn.openlayers.org/trunk/openlayers@4053 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -418,6 +418,22 @@ OpenLayers.Layer = OpenLayers.Class({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* APIMethod: removeMap
|
||||||
|
* Just as setMap() allows each layer the possibility to take a
|
||||||
|
* personalized action on being added to the map, removeMap() allows
|
||||||
|
* each layer to take a personalized action on being removed from it.
|
||||||
|
* For now, this will be mostly unused, except for the EventPane layer,
|
||||||
|
* which needs this hook so that it can remove the special invisible
|
||||||
|
* pane.
|
||||||
|
*
|
||||||
|
* Parameters:
|
||||||
|
* map - {<OpenLayers.Map>}
|
||||||
|
*/
|
||||||
|
removeMap: function(map) {
|
||||||
|
//to be overridden by subclasses
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* APIMethod: getImageSize
|
* APIMethod: getImageSize
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -105,6 +105,22 @@ OpenLayers.Layer.EventPane = OpenLayers.Class(OpenLayers.Layer, {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* APIMethod: removeMap
|
||||||
|
* On being removed from the map, we'll like to remove the invisible 'pane'
|
||||||
|
* div that we added to it on creation.
|
||||||
|
*
|
||||||
|
* Parameters:
|
||||||
|
* map - {<OpenLayers.Map>}
|
||||||
|
*/
|
||||||
|
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);
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method: loadWarningMessage
|
* Method: loadWarningMessage
|
||||||
* If we can't load the map lib, then display an error message to the
|
* If we can't load the map lib, then display an error message to the
|
||||||
|
|||||||
@@ -566,8 +566,9 @@ OpenLayers.Map = OpenLayers.Class({
|
|||||||
} else {
|
} else {
|
||||||
this.layerContainerDiv.removeChild(layer.div);
|
this.layerContainerDiv.removeChild(layer.div);
|
||||||
}
|
}
|
||||||
layer.map = null;
|
|
||||||
OpenLayers.Util.removeItem(this.layers, layer);
|
OpenLayers.Util.removeItem(this.layers, layer);
|
||||||
|
layer.removeMap(this);
|
||||||
|
layer.map = null;
|
||||||
|
|
||||||
// if we removed the base layer, need to set a new one
|
// if we removed the base layer, need to set a new one
|
||||||
if (setNewBaseLayer && (this.baseLayer == layer)) {
|
if (setNewBaseLayer && (this.baseLayer == layer)) {
|
||||||
|
|||||||
@@ -105,6 +105,20 @@
|
|||||||
layer.setVisibility(true);
|
layer.setVisibility(true);
|
||||||
t.eq(layer.visibility, true, "layer pane is now visible");
|
t.eq(layer.visibility, true, "layer pane is now visible");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function test_Layer_EventPane_removeLayer(t) {
|
||||||
|
t.plan(1);
|
||||||
|
var map = new OpenLayers.Map('map');
|
||||||
|
|
||||||
|
layer = new OpenLayers.Layer.EventPane('Test Layer');
|
||||||
|
layer.loadMapObject = function() { };
|
||||||
|
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.");
|
||||||
|
}
|
||||||
|
|
||||||
// -->
|
// -->
|
||||||
</script>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
|
|||||||
Reference in New Issue
Block a user