[OpenLayers-Users] left click handler at OpenLayers.Handler.Drag

Andre Pereira de Matos andre.matos at co.sapo.pt
Thu Jul 9 09:03:40 EDT 2009


Thanks :)

Now it works! Yes, I need to be notified when a mouse down occurres, because I have implemented a context menu control, and I need to close it when a left mouse down occurres over the map.

Thanks again,

Best Regards,
André Matos


-----Original Message-----
From: Eric Lemoine [mailto:eric.lemoine at camptocamp.com] 
Sent: quinta-feira, 9 de Julho de 2009 13:35
To: Andre Pereira de Matos
Cc: users at openlayers.org
Subject: Re: [OpenLayers-Users] left click handler at OpenLayers.Handler.Drag

On Thursday, July 9, 2009, Andre Pereira de Matos
<andre.matos at co.sapo.pt> wrote:
> Hi,
>
>
> Yes, I put that property false in OpenLayers code, and I notice that when you open the box to zoom (shift + left mouse down + mouse move) the map moves too.

This is expected.

>
> Looking at the code, when that property is true it stops the chain event propagation (returns false, at event handler), and the map listener for mousedown ( to move the map) is not notified and it works well. In this case I am not notified either when I register an event like this:

which makes sense.

>
> mapInstance.events.register('mousedown', this, alert(1));
>
>
> Then, I tried to put that property false, has you suggested. I have changed at OpenLayers code, to make sure that I has done it right. With that property false I am notified when a mouse down event occurres, but when I draw a box (shift + left mouse down + mouse move) to zoom, the map moves too. This happens because Drag handler doesn't stop the event propagation and the map handler for mouse down, which is used to move the map is also notified.

Again, this is expected and makes perfect sense.

>
>
> You can see this happening. Just set that property to false and try to draw a box to zoom (shift + left mouse down + mouse move).
>
>
> This only happens for left mouse down events. Right mouse down works well.

So, what you want is register your own listener on mousedown. You can
probable use registerPriority instead of register to make sure your
listener is called first:

map.events.registerPriority("mousedown", scope, function() {
alert("callback"); });

(You'll also want to remove OpenLayers.Handler.Drag.prototype.stopDown = false)

That being said, do you really need a mousedown listener? If a click
listener can work for your case I'll recommend using Handler.Click,
click-handler.html provides an usage example.




>
>
> Best Regards,
> André Matos
>
>
> -----Original Message-----
> From: Eric Lemoine [mailto:eric.lemoine at camptocamp.com]
> Sent: quarta-feira, 8 de Julho de 2009 21:18
> To: Andre Pereira de Matos
> Cc: users at openlayers.org
> Subject: Re: [OpenLayers-Users] left click handler at OpenLayers.Handler.Drag
>
> On Wednesday, July 8, 2009, Andre Pereira de Matos
> <andre.matos at co.sapo.pt> wrote:
>> Hi,
>>
>> And thanks for your reply ;)
>>
>> Before send the mail, I have tried to set that property to false and the Box handler has stop working.
>
> Have you changed prototype.stopDown as I mentioned if my previous email?
>
>
>> I pressed shift + mouse drag, and when you are dragging the box the map moves too.
>>
>> Is this a bug? Is it supposed?
>
> The ZoomBox control uses a Box handler internally, which itself uses a
> Drag handler. If that Drag handler's stopDown property is false then
> the Drag handler used in the PanZoom control's Drag handler also
> receives the mousedown event, which explains why the map moves.
>
>>
>> Cheers!
>>
>> André Matos
>>
>> -----Original Message-----
>> From: Eric Lemoine [mailto:eric.lemoine at camptocamp.com]
>> Sent: quarta-feira, 8 de Julho de 2009 20:03
>> To: Andre Pereira de Matos
>> Cc: users at openlayers.org
>> Subject: Re: [OpenLayers-Users] left click handler at OpenLayers.Handler.Drag
>>
>> On Wednesday, July 1, 2009, Andre Pereira de Matos
>> <andre.matos at co.sapo.pt> wrote:
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>> Hi List,
>>>
>>>
>>>
>>> I am developping a site using OpenLayers
>>> 2.7 (I know, I have to upgrade it to 2.8 :p, but for now I am using 2.7).
>>>
>>>
>>>
>>> So, in the class OpenLayers.Handler.Drag you
>>> are using an handler for mousedown events (method: mousedown), and you are
>>> returning false if it is a left mousedown, is there any reason to do that? I tried
>>> to return true and the behavior apparenty doesn't chang, it still works.
>>>
>>>
>>>
>>>
>>>
>>> At some point of my application I would
>>> like to be notified when a left mousedown occurs, could I return true in that
>>> method? Is there a patch to fix that?
>>
>> Hi, and sorry if this answer comes late. Yes, by default the drag
>> handler's mousedown method returns false. You can change that by
>> setting stopDown to false in the drag handler instance. If you want to
>> have that in every drag handler, even those that you don't create
>> yourself, you can do:
>>
>> OpenLayers.Handler.Drag.prototype.stopDown = false;
>>
>> soon enough if you application code.
>>
>> Cheers,
>>
>> --
>> 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
>>
>
> --
> 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
>

-- 
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