[OpenLayers-Users] Click handler not handling clicks after using editing toolbar

Eric Lemoine eric.lemoine at camptocamp.com
Wed Mar 17 04:38:56 EDT 2010


On Tue, Mar 16, 2010 at 8:23 AM, Dylan Parry <me at dylanparry.com> wrote:
> Hi,
>
> I’ve set up a click handler on my map to handle double-clicks. I did
> this by bastardising the demo for click handlers, so the code I have is
> as follows:
>
> --- start ---
> OpenLayers.Control.Click = OpenLayers.Class(OpenLayers.Control, {
>
>        defaultHandlerOptions: {
>                'single': true,
>                'double': true,
>                'pixelTolerance': 0,
>                'stopSingle': false,
>                'stopDouble': true
>        },
>
>        initialize: function(options) {
>                this.handlerOptions = OpenLayers.Util.extend(
>                        {}, this.defaultHandlerOptions
>                );
>                OpenLayers.Control.prototype.initialize.apply(
>                        this, arguments
>                );
>                this.handler = new OpenLayers.Handler.Click(
>                        this, {
>                                'dblclick': this.onDblclick
>                        }, this.handlerOptions
>                );
>        },
>
>        onDblclick: function(evt) {
>                // A jQuery function that isn’t relevant here
>        }
> });
>
> // Double click handler
> var doubleClick = new OpenLayers.Control.Click({
>        handlerOptions: {
>                "single": false,
>                "double": true,
>                "stopDouble": true
>        }
> });
> map.addControl(doubleClick);
> doubleClick.activate();
> --- end ---
>
> All this code lives in the function that initialises the map. I’ve also
> got an editing toolbar on the map, which is added to the map controls
> during initialisation.
>
> The double click handler works just fine, but if I click on any of the
> buttons in the editing toolbar, then click back to the “move” button, it
> no longer handles the double click events and the map then zooms in when
> I double click, instead of running my custom function.
>
> Any ideas what I can do to stop this from happening? Is there maybe an
> event that fires when you click the edit toolbar buttons that I can
> re-register my click handler in?

The navigation control also uses a click handler configured with a
dblclick handler, this is for zooming in on double clicks. At the
initial state, since your click control is activated after the
navigation control, your click control does catch doubleclick. When
you deactivate the navigation control (by activating an editing tool)
and reactivate it, it's now the one that catches doubleclick, and it
stops the event propagation.

Since you want to open a popup on doubleclick I guess you don't want
the navigation control to zoom on doubleclick. So what I'd do is patch
Control.Navigation to add a new boolean option: zoomDblclickEnable.
This should be pretty straightforward, by mimicing what's done with
the zoomWheelEnabled and zoomBoxEnabled options in the control code.
This patch could go OpenLayers trunk.

You'd also need to create your own application-specific EditingToolbar
control, as you will want to set zoomDblclickEnabled to false for the
navigation control defined in the toolbar. Again this should be pretty
straightforward, there's much code in the EditingToolbar control.

Also, I think you should remove the Navigation control from controls
array you set in the map options, since the EditingToolbar already has
this control.

Hope this helps,



-- 
Eric Lemoine

Camptocamp France SAS
Savoie Technolac, BP 352
73377 Le Bourget du Lac, Cedex

Tel : 00 33 4 79 44 44 96
Mail : eric.lemoine at camptocamp.com
http://www.camptocamp.com



More information about the Users mailing list