[OpenLayers-Dev] removeControl not working as expected
Dejung Gewissler
dejung.gewissler at oit.state.nj.us
Tue Jul 15 14:59:22 EDT 2008
Hi Devs-
I'm trying to create my own control and extend its functionality like
shown in the control API documentation [1]. I only ever want one control
activated on the map at any given time (essentially functionality like
the panel except with a different layout). I've got three buttons
(images) that allow the user to designate which control to use (draw
points, lines or polygons). When no button is active the default map
navigation should then be active. In my HTML I've got three images that
have their respective
onmousedown="javascript:setupInteractiveSelection('Line');" properties
set. This is the js so far:
OGIS.InteractiveSelectionControl = null;
function setupInteractiveSelection(selType){
if (OGIS.Misc.typeOf(OGIS.InteractiveSelectionControl) == "object"){
if (OGIS.InteractiveSelectionControl.OGIS_selectionType == selType){
OGIS.map.removeControl(OGIS.InteractiveSelectionControl);
OGIS.InteractiveSelectionControl = null;
OGIS.map.controls[0].activate();
return;
}
OGIS.map.removeControl(OGIS.InteractiveSelectionControl);
OGIS.InteractiveSelectionControl = null;
}
switch (selType){
case "point":
$("selectByPoint").src =
"../../libraries/openlayers/theme/default/img/draw_point_on.png";
OGIS.InteractiveSelectionControl = new OpenLayers.Control();
OpenLayers.Util.extend(OGIS.InteractiveSelectionControl, {
draw: function () {
// this Handler.Box will intercept the shift-mousedown
// before Control.MouseDefault gets to see it
this.box = new OpenLayers.Handler.Point(
OGIS.InteractiveSelectionControl,
{"done": this.notice});
// {keyMask: OpenLayers.Handler.MOD_SHIFT});
this.box.activate();
},
notice: function (bounds) {
alert(bounds.x + " " + bounds.y);
},
OGIS_selectionType : selType
});
break;
case "line":
//line code here
break;
case "polygon":
//polygon code here
break;
}
OGIS.map.addControl(OGIS.InteractiveSelectionControl);
}
Switching the control from point to line to polygon and back again works
fine. I am able to override the drawing end of the control to do my bidding.
My problem lies in the in the first conditional. There I am trying to
remove the newly created control from the map if the user clicks on the
same image again and put the default map panning/zoom controls back.
What happens currently when the same button is clicked twice is that the
control is removed from the map.controls array, but the mousedown
actions are still of the path handler and vectors are drawn on the map!
[1] - http://dev.openlayers.org/apidocs/files/OpenLayers/Control-js.html
Am I doing this wrong or incompletely or should I file this as a bug?
Thanks,
Dejung
More information about the Dev
mailing list