From fredj: "layer.destroy() calls removeLayer() so control.destroy()

should do the same by calling removeControl()". (Closes #1009)


git-svn-id: http://svn.openlayers.org/trunk/openlayers@4676 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
crschmidt
2007-09-30 16:25:43 +00:00
parent 46c8730601
commit 33f85eeb35
3 changed files with 39 additions and 9 deletions
+5 -1
View File
@@ -130,8 +130,12 @@ OpenLayers.Control = OpenLayers.Class({
// eliminate circular references // eliminate circular references
if (this.handler) { if (this.handler) {
this.handler.destroy(); this.handler.destroy();
this.handler = null;
}
if (this.map) {
this.map.removeControl(this);
this.map = null;
} }
this.map = null;
}, },
/** /**
+2 -2
View File
@@ -797,8 +797,8 @@ OpenLayers.Map = OpenLayers.Class({
removeControl: function (control) { removeControl: function (control) {
//make sure control is non-null and actually part of our map //make sure control is non-null and actually part of our map
if ( (control) && (control == this.getControl(control.id)) ) { if ( (control) && (control == this.getControl(control.id)) ) {
if (!control.outsideViewport) { if (!control.outsideViewport && control.div) {
this.viewPortDiv.removeChild(control.div) this.viewPortDiv.removeChild(control.div);
} }
OpenLayers.Util.removeItem(this.controls, control); OpenLayers.Util.removeItem(this.controls, control);
} }
+31 -5
View File
@@ -2,12 +2,38 @@
<head> <head>
<script src="../lib/OpenLayers.js"></script> <script src="../lib/OpenLayers.js"></script>
<script type="text/javascript"> <script type="text/javascript">
var map; function test_Control_constructor(t) {
function test_01_Control_constructor (t) { t.plan(2);
t.plan( 1 );
control = new OpenLayers.Control(); var control = new OpenLayers.Control();
t.ok( control instanceof OpenLayers.Control, "new OpenLayers.Control returns object" );
t.ok(control instanceof OpenLayers.Control, "new OpenLayers.Control returns object");
t.eq(control.displayClass, "olControl", "displayClass set correctly");
}
function test_Control_addControl(t) {
t.plan(2);
var map = new OpenLayers.Map('map');
var control = new OpenLayers.Control();
map.addControl(control);
t.ok(control.map === map, "Control.map is set to the map object" );
t.ok(map.controls[map.controls.length - 1] === control, "map.controls contains control");
}
function test_Control_destroy(t) {
t.plan(3);
var map = new OpenLayers.Map('map');
var control = new OpenLayers.Control();
map.addControl(control);
control.destroy();
t.ok(map.controls[map.controls.length - 1] != control, "map.controls doesn't contains control");
t.ok(control.map == null, "Control.map is null");
t.ok(control.handler == null, "Control.handler is null");
} }
</script> </script>