For controls with multiple handlers, we now tack them on to a handlers object. The base destroy takes care of the handlers. r=crschmidt,uz/2 (closes #1338)

git-svn-id: http://svn.openlayers.org/trunk/openlayers@6106 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
Tim Schaub
2008-02-08 15:52:03 +00:00
parent 03a827de4d
commit 49e0bff93d
9 changed files with 132 additions and 147 deletions

View File

@@ -139,6 +139,15 @@ OpenLayers.Control = OpenLayers.Class({
this.handler.destroy(); this.handler.destroy();
this.handler = null; this.handler = null;
} }
if(this.handlers) {
for(var key in this.handlers) {
if(this.handlers.hasOwnProperty(key) &&
typeof this.handlers[key].destroy == "function") {
this.handlers[key].destroy();
}
}
this.handlers = null;
}
if (this.map) { if (this.map) {
this.map.removeControl(this); this.map.removeControl(this);
this.map = null; this.map = null;

View File

@@ -76,24 +76,12 @@ OpenLayers.Control.DragFeature = OpenLayers.Class(OpenLayers.Control, {
*/ */
feature: null, feature: null,
/**
* Property: dragHandler
* {<OpenLayers.Handler.Drag>}
*/
dragHandler: null,
/** /**
* Property: dragCallbacks * Property: dragCallbacks
* {Object} The functions that are sent to the drag handler for callback. * {Object} The functions that are sent to the drag handler for callback.
*/ */
dragCallbacks: {}, dragCallbacks: {},
/**
* Property: featureHandler
* {<OpenLayers.Handler.Feature>}
*/
featureHandler: null,
/** /**
* Property: featureCallbacks * Property: featureCallbacks
* {Object} The functions that are sent to the feature handler for callback. * {Object} The functions that are sent to the feature handler for callback.
@@ -119,20 +107,24 @@ OpenLayers.Control.DragFeature = OpenLayers.Class(OpenLayers.Control, {
initialize: function(layer, options) { initialize: function(layer, options) {
OpenLayers.Control.prototype.initialize.apply(this, [options]); OpenLayers.Control.prototype.initialize.apply(this, [options]);
this.layer = layer; this.layer = layer;
this.dragCallbacks = OpenLayers.Util.extend({down: this.downFeature, this.handlers = {
move: this.moveFeature, drag: new OpenLayers.Handler.Drag(
up: this.upFeature, this, OpenLayers.Util.extend({
out: this.cancel, down: this.downFeature,
done: this.doneDragging move: this.moveFeature,
}, this.dragCallbacks); up: this.upFeature,
this.dragHandler = new OpenLayers.Handler.Drag(this, this.dragCallbacks); out: this.cancel,
this.featureCallbacks = OpenLayers.Util.extend({over: this.overFeature, done: this.doneDragging
out: this.outFeature }, this.dragCallbacks)
}, this.featureCallbacks); ),
var handlerOptions = {geometryTypes: this.geometryTypes}; feature: new OpenLayers.Handler.Feature(
this.featureHandler = new OpenLayers.Handler.Feature(this, this.layer, this, this.layer, OpenLayers.Util.extend({
this.featureCallbacks, over: this.overFeature,
handlerOptions); out: this.outFeature
}, this.featureCallbacks),
{geometryTypes: this.geometryTypes}
)
};
}, },
/** /**
@@ -141,8 +133,6 @@ OpenLayers.Control.DragFeature = OpenLayers.Class(OpenLayers.Control, {
*/ */
destroy: function() { destroy: function() {
this.layer = null; this.layer = null;
this.dragHandler.destroy();
this.featureHandler.destroy();
OpenLayers.Control.prototype.destroy.apply(this, []); OpenLayers.Control.prototype.destroy.apply(this, []);
}, },
@@ -154,7 +144,7 @@ OpenLayers.Control.DragFeature = OpenLayers.Class(OpenLayers.Control, {
* {Boolean} Successfully activated the control and feature handler. * {Boolean} Successfully activated the control and feature handler.
*/ */
activate: function() { activate: function() {
return (this.featureHandler.activate() && return (this.handlers.feature.activate() &&
OpenLayers.Control.prototype.activate.apply(this, arguments)); OpenLayers.Control.prototype.activate.apply(this, arguments));
}, },
@@ -167,8 +157,8 @@ OpenLayers.Control.DragFeature = OpenLayers.Class(OpenLayers.Control, {
*/ */
deactivate: function() { deactivate: function() {
// the return from the handlers is unimportant in this case // the return from the handlers is unimportant in this case
this.dragHandler.deactivate(); this.handlers.drag.deactivate();
this.featureHandler.deactivate(); this.handlers.feature.deactivate();
this.feature = null; this.feature = null;
this.dragging = false; this.dragging = false;
this.lastPixel = null; this.lastPixel = null;
@@ -184,9 +174,9 @@ OpenLayers.Control.DragFeature = OpenLayers.Class(OpenLayers.Control, {
* feature - {<OpenLayers.Feature.Vector>} The selected feature. * feature - {<OpenLayers.Feature.Vector>} The selected feature.
*/ */
overFeature: function(feature) { overFeature: function(feature) {
if(!this.dragHandler.dragging) { if(!this.handlers.drag.dragging) {
this.feature = feature; this.feature = feature;
this.dragHandler.activate(); this.handlers.drag.activate();
this.over = true; this.over = true;
// TBD replace with CSS classes // TBD replace with CSS classes
this.map.div.style.cursor = "move"; this.map.div.style.cursor = "move";
@@ -238,7 +228,7 @@ OpenLayers.Control.DragFeature = OpenLayers.Class(OpenLayers.Control, {
*/ */
upFeature: function(pixel) { upFeature: function(pixel) {
if(!this.over) { if(!this.over) {
this.dragHandler.deactivate(); this.handlers.drag.deactivate();
this.feature = null; this.feature = null;
// TBD replace with CSS classes // TBD replace with CSS classes
this.map.div.style.cursor = "default"; this.map.div.style.cursor = "default";
@@ -265,9 +255,9 @@ OpenLayers.Control.DragFeature = OpenLayers.Class(OpenLayers.Control, {
* feature - {<OpenLayers.Feature.Vector>} The feature that the mouse left. * feature - {<OpenLayers.Feature.Vector>} The feature that the mouse left.
*/ */
outFeature: function(feature) { outFeature: function(feature) {
if(!this.dragHandler.dragging) { if(!this.handlers.drag.dragging) {
this.over = false; this.over = false;
this.dragHandler.deactivate(); this.handlers.drag.deactivate();
// TBD replace with CSS classes // TBD replace with CSS classes
this.map.div.style.cursor = "default"; this.map.div.style.cursor = "default";
this.feature = null; this.feature = null;
@@ -283,7 +273,7 @@ OpenLayers.Control.DragFeature = OpenLayers.Class(OpenLayers.Control, {
* Called when the drag handler detects a mouse-out (from the map viewport). * Called when the drag handler detects a mouse-out (from the map viewport).
*/ */
cancel: function() { cancel: function() {
this.dragHandler.deactivate(); this.handlers.drag.deactivate();
this.over = false; this.over = false;
}, },
@@ -295,8 +285,8 @@ OpenLayers.Control.DragFeature = OpenLayers.Class(OpenLayers.Control, {
* map - {<OpenLayers.Map>} The control's map. * map - {<OpenLayers.Map>} The control's map.
*/ */
setMap: function(map) { setMap: function(map) {
this.dragHandler.setMap(map); this.handlers.drag.setMap(map);
this.featureHandler.setMap(map); this.handlers.feature.setMap(map);
OpenLayers.Control.prototype.setMap.apply(this, arguments); OpenLayers.Control.prototype.setMap.apply(this, arguments);
}, },

View File

@@ -83,10 +83,10 @@ OpenLayers.Control.ModifyFeature = OpenLayers.Class(OpenLayers.Control, {
dragControl: null, dragControl: null,
/** /**
* Property: keyboardHandler * Property: handlers
* {<OpenLayers.Handler.Keyboard>} * {Object}
*/ */
keyboardHandler: null, handlers: null,
/** /**
* APIProperty: deleteCodes * APIProperty: deleteCodes
@@ -216,9 +216,9 @@ OpenLayers.Control.ModifyFeature = OpenLayers.Class(OpenLayers.Control, {
var keyboardOptions = { var keyboardOptions = {
keypress: this.handleKeypress keypress: this.handleKeypress
}; };
this.keyboardHandler = new OpenLayers.Handler.Keyboard( this.handlers = {
this, keyboardOptions keyboard: new OpenLayers.Handler.Keyboard(this, keyboardOptions)
); };
}, },
/** /**
@@ -229,7 +229,6 @@ OpenLayers.Control.ModifyFeature = OpenLayers.Class(OpenLayers.Control, {
this.layer = null; this.layer = null;
this.selectControl.destroy(); this.selectControl.destroy();
this.dragControl.destroy(); this.dragControl.destroy();
this.keyboardHandler.destroy();
OpenLayers.Control.prototype.destroy.apply(this, []); OpenLayers.Control.prototype.destroy.apply(this, []);
}, },
@@ -242,7 +241,7 @@ OpenLayers.Control.ModifyFeature = OpenLayers.Class(OpenLayers.Control, {
*/ */
activate: function() { activate: function() {
return (this.selectControl.activate() && return (this.selectControl.activate() &&
this.keyboardHandler.activate() && this.handlers.keyboard.activate() &&
OpenLayers.Control.prototype.activate.apply(this, arguments)); OpenLayers.Control.prototype.activate.apply(this, arguments));
}, },
@@ -266,7 +265,7 @@ OpenLayers.Control.ModifyFeature = OpenLayers.Class(OpenLayers.Control, {
[this.feature]); [this.feature]);
} }
this.selectControl.deactivate(); this.selectControl.deactivate();
this.keyboardHandler.deactivate(); this.handlers.keyboard.deactivate();
deactivated = true; deactivated = true;
} }
return deactivated; return deactivated;
@@ -352,9 +351,9 @@ OpenLayers.Control.ModifyFeature = OpenLayers.Class(OpenLayers.Control, {
this.dragControl.overFeature.apply(this.dragControl, this.dragControl.overFeature.apply(this.dragControl,
[feature]); [feature]);
this.dragControl.lastPixel = pixel; this.dragControl.lastPixel = pixel;
this.dragControl.dragHandler.started = true; this.dragControl.handlers.drag.started = true;
this.dragControl.dragHandler.start = pixel; this.dragControl.handlers.drag.start = pixel;
this.dragControl.dragHandler.last = pixel; this.dragControl.handlers.drag.last = pixel;
} }
} }
}, },
@@ -486,7 +485,7 @@ OpenLayers.Control.ModifyFeature = OpenLayers.Class(OpenLayers.Control, {
var vertex = this.dragControl.feature; var vertex = this.dragControl.feature;
if(vertex && if(vertex &&
OpenLayers.Util.indexOf(this.vertices, vertex) != -1 && OpenLayers.Util.indexOf(this.vertices, vertex) != -1 &&
!this.dragControl.dragHandler.dragging && !this.dragControl.handlers.drag.dragging &&
vertex.geometry.parent) { vertex.geometry.parent) {
// remove the vertex // remove the vertex
vertex.geometry.parent.removeComponent(vertex.geometry); vertex.geometry.parent.removeComponent(vertex.geometry);

View File

@@ -36,12 +36,6 @@ OpenLayers.Control.Navigation = OpenLayers.Class(OpenLayers.Control, {
*/ */
zoomBox: null, zoomBox: null,
/**
* Property: wheelHandler
* {<OpenLayers.Handler.MouseWheel>}
*/
wheelHandler: null,
/** /**
* Constructor: OpenLayers.Control.Navigation * Constructor: OpenLayers.Control.Navigation
* Create a new navigation control * Create a new navigation control
@@ -51,6 +45,7 @@ OpenLayers.Control.Navigation = OpenLayers.Class(OpenLayers.Control, {
* the control * the control
*/ */
initialize: function(options) { initialize: function(options) {
this.handlers = {};
OpenLayers.Control.prototype.initialize.apply(this, arguments); OpenLayers.Control.prototype.initialize.apply(this, arguments);
}, },
@@ -61,8 +56,6 @@ OpenLayers.Control.Navigation = OpenLayers.Class(OpenLayers.Control, {
* to prevent memory leaks. * to prevent memory leaks.
*/ */
destroy: function() { destroy: function() {
OpenLayers.Control.prototype.destroy.apply(this,arguments);
this.deactivate(); this.deactivate();
if (this.dragPan) { if (this.dragPan) {
@@ -70,20 +63,11 @@ OpenLayers.Control.Navigation = OpenLayers.Class(OpenLayers.Control, {
} }
this.dragPan = null; this.dragPan = null;
if (this.wheelHandler) {
this.wheelHandler.destroy();
}
this.wheelHandler = null;
if (this.clickHandler) {
this.clickHandler.destroy();
}
this.clickHandler = null;
if (this.zoomBox) { if (this.zoomBox) {
this.zoomBox.destroy(); this.zoomBox.destroy();
} }
this.zoomBox = null; this.zoomBox = null;
OpenLayers.Control.prototype.destroy.apply(this,arguments);
}, },
/** /**
@@ -91,8 +75,8 @@ OpenLayers.Control.Navigation = OpenLayers.Class(OpenLayers.Control, {
*/ */
activate: function() { activate: function() {
this.dragPan.activate(); this.dragPan.activate();
this.wheelHandler.activate(); this.handlers.wheel.activate();
this.clickHandler.activate(); this.handlers.click.activate();
this.zoomBox.activate(); this.zoomBox.activate();
return OpenLayers.Control.prototype.activate.apply(this,arguments); return OpenLayers.Control.prototype.activate.apply(this,arguments);
}, },
@@ -103,8 +87,8 @@ OpenLayers.Control.Navigation = OpenLayers.Class(OpenLayers.Control, {
deactivate: function() { deactivate: function() {
this.zoomBox.deactivate(); this.zoomBox.deactivate();
this.dragPan.deactivate(); this.dragPan.deactivate();
this.clickHandler.deactivate(); this.handlers.click.deactivate();
this.wheelHandler.deactivate(); this.handlers.wheel.deactivate();
return OpenLayers.Control.prototype.deactivate.apply(this,arguments); return OpenLayers.Control.prototype.deactivate.apply(this,arguments);
}, },
@@ -112,7 +96,7 @@ OpenLayers.Control.Navigation = OpenLayers.Class(OpenLayers.Control, {
* Method: draw * Method: draw
*/ */
draw: function() { draw: function() {
this.clickHandler = new OpenLayers.Handler.Click(this, this.handlers.click = new OpenLayers.Handler.Click(this,
{ 'dblclick': this.defaultDblClick }, { 'dblclick': this.defaultDblClick },
{ {
'double': true, 'double': true,
@@ -123,7 +107,7 @@ OpenLayers.Control.Navigation = OpenLayers.Class(OpenLayers.Control, {
{map: this.map, keyMask: OpenLayers.Handler.MOD_SHIFT}); {map: this.map, keyMask: OpenLayers.Handler.MOD_SHIFT});
this.dragPan.draw(); this.dragPan.draw();
this.zoomBox.draw(); this.zoomBox.draw();
this.wheelHandler = new OpenLayers.Handler.MouseWheel( this.handlers.wheel = new OpenLayers.Handler.MouseWheel(
this, {"up" : this.wheelUp, this, {"up" : this.wheelUp,
"down": this.wheelDown} ); "down": this.wheelDown} );
this.activate(); this.activate();

View File

@@ -98,10 +98,10 @@ OpenLayers.Control.OverviewMap = OpenLayers.Class(OpenLayers.Control, {
mapOptions: null, mapOptions: null,
/** /**
* Property: dragHandler * Property: handlers
* {<OpenLayers.Handler.Drag>} A handler for dragging the extent rectangle. * {Object}
*/ */
dragHandler: null, handlers: null,
/** /**
* Constructor: OpenLayers.Control.OverviewMap * Constructor: OpenLayers.Control.OverviewMap
@@ -114,6 +114,7 @@ OpenLayers.Control.OverviewMap = OpenLayers.Class(OpenLayers.Control, {
*/ */
initialize: function(options) { initialize: function(options) {
this.layers = []; this.layers = [];
this.handlers = {};
OpenLayers.Control.prototype.initialize.apply(this, [options]); OpenLayers.Control.prototype.initialize.apply(this, [options]);
}, },
@@ -125,8 +126,7 @@ OpenLayers.Control.OverviewMap = OpenLayers.Class(OpenLayers.Control, {
if (!this.mapDiv) { // we've already been destroyed if (!this.mapDiv) { // we've already been destroyed
return; return;
} }
this.dragHandler.destroy(); this.handlers.click.destroy();
this.clickHandler.destroy();
this.mapDiv.removeChild(this.extentRectangle); this.mapDiv.removeChild(this.extentRectangle);
this.extentRectangle = null; this.extentRectangle = null;
@@ -280,8 +280,8 @@ OpenLayers.Control.OverviewMap = OpenLayers.Class(OpenLayers.Control, {
* px - {<OpenLayers.Pixel>} The pixel location of the drag. * px - {<OpenLayers.Pixel>} The pixel location of the drag.
*/ */
rectDrag: function(px) { rectDrag: function(px) {
var deltaX = this.dragHandler.last.x - px.x; var deltaX = this.handlers.drag.last.x - px.x;
var deltaY = this.dragHandler.last.y - px.y; var deltaY = this.handlers.drag.last.y - px.y;
if(deltaX != 0 || deltaY != 0) { if(deltaX != 0 || deltaY != 0) {
var rectTop = this.rectPxBounds.top; var rectTop = this.rectPxBounds.top;
var rectLeft = this.rectPxBounds.left; var rectLeft = this.rectPxBounds.left;
@@ -456,11 +456,11 @@ OpenLayers.Control.OverviewMap = OpenLayers.Class(OpenLayers.Control, {
'border-bottom-width')); 'border-bottom-width'));
this.hComp = (this.hComp) ? this.hComp : 2; this.hComp = (this.hComp) ? this.hComp : 2;
this.dragHandler = new OpenLayers.Handler.Drag( this.handlers.drag = new OpenLayers.Handler.Drag(
this, {move: this.rectDrag, done: this.updateMapToRect}, this, {move: this.rectDrag, done: this.updateMapToRect},
{map: this.ovmap} {map: this.ovmap}
); );
this.clickHandler = new OpenLayers.Handler.Click( this.handlers.click = new OpenLayers.Handler.Click(
this, { this, {
"click": this.mapDivClick "click": this.mapDivClick
},{ },{
@@ -470,18 +470,18 @@ OpenLayers.Control.OverviewMap = OpenLayers.Class(OpenLayers.Control, {
map: this.ovmap map: this.ovmap
} }
); );
this.clickHandler.activate(); this.handlers.click.activate();
this.rectEvents = new OpenLayers.Events(this, this.extentRectangle, this.rectEvents = new OpenLayers.Events(this, this.extentRectangle,
null, true); null, true);
this.rectEvents.register("mouseover", this, function(e) { this.rectEvents.register("mouseover", this, function(e) {
if(!this.dragHandler.active && !this.map.dragging) { if(!this.handlers.drag.active && !this.map.dragging) {
this.dragHandler.activate(); this.handlers.drag.activate();
} }
}); });
this.rectEvents.register("mouseout", this, function(e) { this.rectEvents.register("mouseout", this, function(e) {
if(!this.dragHandler.dragging) { if(!this.handlers.drag.dragging) {
this.dragHandler.deactivate(); this.handlers.drag.deactivate();
} }
}); });

View File

@@ -14,7 +14,7 @@
"new OpenLayers.Control.DragFeature returns an instance"); "new OpenLayers.Control.DragFeature returns an instance");
t.eq(control.layer, "bar", t.eq(control.layer, "bar",
"constructor sets layer correctly"); "constructor sets layer correctly");
t.eq(control.featureHandler.geometryTypes, "foo", t.eq(control.handlers.feature.geometryTypes, "foo",
"constructor sets options correctly on feature handler"); "constructor sets options correctly on feature handler");
} }
@@ -24,14 +24,15 @@
var layer = new OpenLayers.Layer.Vector(); var layer = new OpenLayers.Layer.Vector();
map.addLayer(layer); map.addLayer(layer);
var control = new OpenLayers.Control.DragFeature(layer); var control = new OpenLayers.Control.DragFeature(layer);
control.dragHandler.destroy = function() { control.handlers.drag.destroy = function() {
t.ok(true, t.ok(true,
"control.destroy calls destroy on drag handler"); "control.destroy calls destroy on drag handler");
} }
control.featureHandler.destroy = function() { control.handlers.feature.destroy = function() {
t.ok(true, t.ok(true,
"control.destroy calls destroy on feature handler"); "control.destroy calls destroy on feature handler");
} }
control.destroy(); control.destroy();
} }
@@ -43,10 +44,10 @@
map.addLayer(layer); map.addLayer(layer);
var control = new OpenLayers.Control.DragFeature(layer); var control = new OpenLayers.Control.DragFeature(layer);
map.addControl(control); map.addControl(control);
t.ok(!control.featureHandler.active, t.ok(!control.handlers.feature.active,
"feature handler is not active prior to activating control"); "feature handler is not active prior to activating control");
control.activate(); control.activate();
t.ok(control.featureHandler.active, t.ok(control.handlers.feature.active,
"feature handler is active after activating control"); "feature handler is active after activating control");
} }
@@ -58,11 +59,11 @@
var control = new OpenLayers.Control.DragFeature(layer); var control = new OpenLayers.Control.DragFeature(layer);
map.addControl(control); map.addControl(control);
control.dragHandler.deactivate = function() { control.handlers.drag.deactivate = function() {
t.ok(true, t.ok(true,
"control.deactivate calls deactivate on drag handler"); "control.deactivate calls deactivate on drag handler");
} }
control.featureHandler.deactivate = function() { control.handlers.feature.deactivate = function() {
t.ok(true, t.ok(true,
"control.deactivate calls deactivate on feature handler"); "control.deactivate calls deactivate on feature handler");
} }
@@ -78,7 +79,7 @@
map.addControl(control); map.addControl(control);
control.activate(); control.activate();
t.ok(!control.dragHandler.active, t.ok(!control.handlers.drag.active,
"drag handler is not active before over a feature"); "drag handler is not active before over a feature");
// simulate a mouseover on a feature // simulate a mouseover on a feature
@@ -89,7 +90,7 @@
t.eq(control.feature, "foo", t.eq(control.feature, "foo",
"control gets the proper feature from the feature handler"); "control gets the proper feature from the feature handler");
t.ok(control.dragHandler.active, t.ok(control.handlers.drag.active,
"drag handler activated when over a feature"); "drag handler activated when over a feature");
} }

View File

@@ -172,7 +172,7 @@
control.handleKeypress(dKey); control.handleKeypress(dKey);
// now make sure nothing happens if the vertex is mid-drag // now make sure nothing happens if the vertex is mid-drag
control.dragControl.dragHandler.dragging = true; control.dragControl.handlers.drag.dragging = true;
control.handleKeypress(delKey); control.handleKeypress(delKey);
// reset modified methods // reset modified methods
@@ -305,11 +305,11 @@
control.dragControl.map.div = {}; control.dragControl.map.div = {};
control.dragControl.map.div.style = {}; control.dragControl.map.div.style = {};
control.dragControl.map.div.cursor = "foo"; control.dragControl.map.div.cursor = "foo";
control.dragControl.dragHandler.deactivate = function() { control.dragControl.handlers.drag.deactivate = function() {
this.active = false; this.active = false;
} }
control.resetVertices(); control.resetVertices();
t.ok(!control.dragControl.dragHandler.active, "resetVertices deactivates drag handler"); t.ok(!control.dragControl.handlers.drag.active, "resetVertices deactivates drag handler");
control.dragControl.map = null; control.dragControl.map = null;
control.destroy(); control.destroy();

View File

@@ -5,61 +5,63 @@
function test_Control_Navigation_constructor (t) { function test_Control_Navigation_constructor (t) {
t.plan( 2 ); t.plan( 2 );
var temp = OpenLayers.Control.prototype.initialize; var temp = OpenLayers.Control.prototype.initialize;
OpenLayers.Control.prototype.initialize = function() { OpenLayers.Control.prototype.initialize = function() {
t.ok(true, "OpenLayers.Control's constructor called"); t.ok(true, "OpenLayers.Control's constructor called");
}; };
var control = new OpenLayers.Control.Navigation(); var control = new OpenLayers.Control.Navigation();
t.ok( control instanceof OpenLayers.Control.Navigation, "new OpenLayers.Control returns object" ); t.ok( control instanceof OpenLayers.Control.Navigation, "new OpenLayers.Control returns object" );
OpenLayers.Control.prototype.initialize = temp; OpenLayers.Control.prototype.initialize = temp;
} }
function test_Control_Navigation_destroy (t) { function test_Control_Navigation_destroy (t) {
t.plan(10); t.plan(9);
var temp = OpenLayers.Control.prototype.destroy; var temp = OpenLayers.Control.prototype.destroy;
OpenLayers.Control.prototype.destroy = function() { OpenLayers.Control.prototype.destroy = function() {
t.ok(true, "OpenLayers.Control's destroy called"); t.ok(true, "OpenLayers.Control's destroy called");
}; temp.call(this);
};
var control = { var control = {
'deactivate': function() { 'deactivate': function() {
t.ok(true, "navigation control deactivated before being destroyed"); t.ok(true, "navigation control deactivated before being destroyed");
}, },
'dragPan': { 'dragPan': {
'destroy': function() { 'destroy': function() {
t.ok(true, "dragPan destroyed"); t.ok(true, "dragPan destroyed");
} }
}, },
'zoomBox': { 'zoomBox': {
'destroy': function() { 'destroy': function() {
t.ok(true, "zoomBox destroyed"); t.ok(true, "zoomBox destroyed");
} }
}, },
'wheelHandler': { handlers: {
'destroy': function() { 'wheel': {
t.ok(true, "wheelHandler destroyed"); 'destroy': function() {
} t.ok(true, "wheelHandler destroyed");
}, }
'clickHandler': { },
'destroy': function() { 'click': {
t.ok(true, "clickHandler destroyed"); 'destroy': function() {
} t.ok(true, "clickHandler destroyed");
} }
}; }
}
};
//this will also trigger one test by calling OpenLayers.Control's destroy //this will also trigger one test by calling OpenLayers.Control's destroy
// and three more for the destruction of dragPan, zoomBox, and wheelHandler // and three more for the destruction of dragPan, zoomBox, and wheelHandler
OpenLayers.Control.Navigation.prototype.destroy.apply(control, []); OpenLayers.Control.Navigation.prototype.destroy.apply(control, []);
t.eq(control.dragPan, null, "'dragPan' set to null"); t.eq(control.dragPan, null, "'dragPan' set to null");
t.eq(control.zoomBox, null, "'zoomBox' set to null"); t.eq(control.zoomBox, null, "'zoomBox' set to null");
t.eq(control.wheelHandler, null, "'wheelHandler' set to null"); t.eq(control.handlers, null, "handlers set to null");
t.eq(control.clickHandler, null, "'clickHandler' set to null");
OpenLayers.Control.prototype.destroy = temp; OpenLayers.Control.prototype.destroy = temp;
} }
</script> </script>

View File

@@ -51,7 +51,7 @@
t.eq(cent.lon, -71.3515625, "Clicking on the Overview Map has the correct effect on map lon"); t.eq(cent.lon, -71.3515625, "Clicking on the Overview Map has the correct effect on map lon");
t.eq(cent.lat, 42.17578125, "Clicking on the Overview Map has the correct effect on map lat"); t.eq(cent.lat, 42.17578125, "Clicking on the Overview Map has the correct effect on map lat");
control.dragHandler = { control.handlers.drag = {
last: new OpenLayers.Pixel(5,5), last: new OpenLayers.Pixel(5,5),
destroy: function() {} destroy: function() {}
}; };