[OpenLayers-Users] Controls and map events

Eric Lemoine eric.c2c at gmail.com
Sat Jan 12 08:40:25 EST 2008


On Jan 11, 2008 10:21 PM, Attila Csipa <plists at prometheus.org.yu> wrote:
> Yes, I outdid myself with the parentheses, sorry about that. The code:
>
> var drag = new OpenLayers.Control.DragFeature(pointlayer,{
>                 onStart: function(feature, pixel)
>                 {
>                         storeGeometry(feature.geometry);
>                 },
>                 onComplete: function(feature, pixel)
>                 {
>                         processNewGeometry(feature.geometry);
>                 }
>         });
>
>         drag.dragHandler.stopDown = false;
>         map.addControl(drag);
>         drag.activate();
>         map.events.register("click", map, function(e) {
>               var lonlat = map.getLonLatFromViewPortPx(e.xy);
>               alert("You clicked near " + lonlat.lat + " N, " +
>                                           + lonlat.lon + " E");
>         });
>
> What I want to do is to preserve 'click' functionality even if the click
> happened over a draggable feature. pointlayer is a GML layer containing
> features with point geometries. What happens in the svn version is that in
> pointlayer.events, Events.js on line 627, after Handler.Drag returns
> continueChain = true due to the stopDown property, but on the call to the
> next listener (a Handler.Feature), continueChain = false and thus it doesn't
> fall through to other elements. I'm still familiarizing myself with OL
> structures, so my assessment might be wrong of course...

Setting the drag handler's stopDown property to false won't help you
because the event you want to get "click" not "mousedown". Anyhow the
feature handler (also used in the drag feature control) stops the
propagation of clicks that occur on features. That's what kills you
here.

Currently, there's no way to prevent the feature handler from stopping
the propagation of clicks occuring on features. I think this deserves
a ticket and a patch. In the meantime, you can try the patch attached
to this email. The patch adds the property stopHandledClick to the
feature handler. By default, stopHandledClick is set to true. By
making it false, clicks occuring on features will propagate.

So apply the patch and replace

drag.dragHandler.stopDown = false;

with

drag.featureHandler.stopHandledClick = false;

Hope this helps,

PS: if you'd like to quickly see this patch included in the trunk,
feel free to open a ticket in the trac, complement my patch with
tests, and attach the patch to the ticket. That'd be a good first code
contribution to OpenLayers ;-)

Thanks,
--
Eric
-------------- next part --------------
A non-text attachment was scrubbed...
Name: patch-r5728-feature-handler.diff
Type: text/x-patch
Size: 3017 bytes
Desc: not available
Url : http://lists.osgeo.org/pipermail/openlayers-users/attachments/20080112/eed6bb29/patch-r5728-feature-handler.bin


More information about the Users mailing list