give the navigation control a proper destroy and also give it a test file while we're at it. (Closes #1289)

git-svn-id: http://svn.openlayers.org/trunk/openlayers@5990 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
euzuro
2008-02-05 06:34:20 +00:00
parent 8311449985
commit 672d3c4eed
3 changed files with 91 additions and 4 deletions

View File

@@ -62,11 +62,28 @@ OpenLayers.Control.Navigation = OpenLayers.Class(OpenLayers.Control, {
*/
destroy: function() {
OpenLayers.Control.prototype.destroy.apply(this,arguments);
this.deactivate();
if (this.dragPan) {
this.dragPan.destroy();
}
this.dragPan = null;
if (this.wheelHandler) {
this.wheelHandler.destroy();
}
this.wheelHandler = null;
if (this.clickHandler) {
this.clickHandler.destroy();
}
this.clickHandler = null;
if (this.zoomBox) {
this.zoomBox.destroy();
}
this.zoomBox = null;
},
/**

View File

@@ -0,0 +1,69 @@
<html>
<head>
<script src="../../lib/OpenLayers.js"></script>
<script type="text/javascript">
function test_Control_Navigation_constructor (t) {
t.plan( 2 );
var temp = OpenLayers.Control.prototype.initialize;
OpenLayers.Control.prototype.initialize = function() {
t.ok(true, "OpenLayers.Control's constructor called");
};
var control = new OpenLayers.Control.Navigation();
t.ok( control instanceof OpenLayers.Control.Navigation, "new OpenLayers.Control returns object" );
OpenLayers.Control.prototype.initialize = temp;
}
function test_Control_Navigation_destroy (t) {
t.plan(10);
var temp = OpenLayers.Control.prototype.destroy;
OpenLayers.Control.prototype.destroy = function() {
t.ok(true, "OpenLayers.Control's destroy called");
};
var control = {
'deactivate': function() {
t.ok(true, "navigation control deactivated before being destroyed");
},
'dragPan': {
'destroy': function() {
t.ok(true, "dragPan destroyed");
}
},
'zoomBox': {
'destroy': function() {
t.ok(true, "zoomBox destroyed");
}
},
'wheelHandler': {
'destroy': function() {
t.ok(true, "wheelHandler destroyed");
}
},
'clickHandler': {
'destroy': function() {
t.ok(true, "clickHandler destroyed");
}
}
};
//this will also trigger one test by calling OpenLayers.Control's destroy
// and three more for the destruction of dragPan, zoomBox, and wheelHandler
OpenLayers.Control.Navigation.prototype.destroy.apply(control, []);
t.eq(control.dragPan, null, "'dragPan' set to null");
t.eq(control.zoomBox, null, "'zoomBox' set to null");
t.eq(control.wheelHandler, null, "'wheelHandler' set to null");
t.eq(control.clickHandler, null, "'clickHandler' set to null");
OpenLayers.Control.prototype.destroy = temp;
}
</script>
</head>
<body>
</body>
</html>

View File

@@ -83,6 +83,7 @@
<li>Control/test_ModifyFeature.html</li>
<li>Control/test_MousePosition.html</li>
<li>Control/test_MouseToolbar.html</li>
<li>Control/test_Navigation.html</li>
<li>Control/test_NavToolbar.html</li>
<li>Control/test_OverviewMap.html</li>
<li>Control/test_Panel.html</li>