Ticket #1009: Control.destroy.removeControl.00.patch
| File Control.destroy.removeControl.00.patch, 2.9 kB (added by fredj, 1 year ago) |
|---|
-
tests/test_Control.html
old new 2 2 <head> 3 3 <script src="../lib/OpenLayers.js"></script> 4 4 <script type="text/javascript"> 5 var map; 6 function test_01_Control_constructor (t) { 7 t.plan( 1 ); 5 function test_Control_constructor(t) { 6 t.plan(2); 8 7 9 control = new OpenLayers.Control(); 10 t.ok( control instanceof OpenLayers.Control, "new OpenLayers.Control returns object" ); 8 var control = new OpenLayers.Control(); 9 10 t.ok(control instanceof OpenLayers.Control, "new OpenLayers.Control returns object"); 11 t.eq(control.displayClass, "olControl", "displayClass set correctly"); 11 12 } 12 13 14 function test_Control_addControl(t) { 15 t.plan(2); 16 17 var map = new OpenLayers.Map('map'); 18 var control = new OpenLayers.Control(); 19 map.addControl(control); 20 21 t.ok(control.map === map, "Control.map is set to the map object" ); 22 t.ok(map.controls[map.controls.length - 1] === control, "map.controls contains control"); 23 } 24 25 function test_Control_destroy(t) { 26 t.plan(3); 27 28 var map = new OpenLayers.Map('map'); 29 var control = new OpenLayers.Control(); 30 map.addControl(control); 31 32 control.destroy(); 33 t.ok(map.controls[map.controls.length - 1] != control, "map.controls doesn't contains control"); 34 35 t.ok(control.map == null, "Control.map is null"); 36 t.ok(control.handler == null, "Control.handler is null"); 37 } 38 13 39 </script> 14 40 </head> 15 41 <body> -
lib/OpenLayers/Map.js
old new 797 797 removeControl: function (control) { 798 798 //make sure control is non-null and actually part of our map 799 799 if ( (control) && (control == this.getControl(control.id)) ) { 800 if (!control.outsideViewport ) {801 this.viewPortDiv.removeChild(control.div) 800 if (!control.outsideViewport && control.div) { 801 this.viewPortDiv.removeChild(control.div); 802 802 } 803 803 OpenLayers.Util.removeItem(this.controls, control); 804 804 } -
lib/OpenLayers/Control.js
old new 130 130 // eliminate circular references 131 131 if (this.handler) { 132 132 this.handler.destroy(); 133 } 134 this.map = null; 133 this.handler = null; 134 } 135 if (this.map) { 136 this.map.removeControl(this); 137 this.map = null; 138 } 135 139 }, 136 140 137 141 /**
