[OpenLayers-Users] Capturing mouse events

Mike Leahy mgleahy at alumni.uwaterloo.ca
Thu Jul 22 23:13:24 EDT 2010


Ok...a bit more on this.

I am able to capture right clicks by disabling the contextmenu action, then 
checking for the right-click event on mouseup.

map.div.oncontextmenu = function(){return false;};
map.div.onmouseup = function(e){
	if (OpenLayers.Event.isRightClick(e)){
		alert("Right button click"); // Do stuff here...
	}
};

From here, though, I'd want to get the event variable 'e' to have the various 
properties that are normally prepared through OpenLayers events (e.g., to have 
the 'xy' property).  Can anyone recommend a better way to do this?  Is there a 
problem with taking over the mouseup event on the map div?  If so, what other 
approach might work here (e.g., would using jQuery to bind events work 
better)?

Regards,
Mike


On Thursday, July 22, 2010 21:48:54 Mike Leahy wrote:
> That does work for right-click, although it's not as tidy.  What confuses
> me is that it would seem that based on the documentation that there are
> specific functions meant for handling these events in the click handler
> class:
> http://dev.openlayers.org/docs/files/OpenLayers/Handler/Click-js.html
> 
> Am I misinterpreting that?
> 
> On Thursday, July 22, 2010 21:07:33 Phil Scadden wrote:
> > Not sure how OpenLayers handles it, but fir html, how  about
> > onContextMenu event? For mouse handling, I am pretty sure you can only
> > reliably pick right button in onMousedown event
> > --
> > Phil Scadden, Senior Scientist GNS Science Ltd 764 Cumberland St,
> > Private Bag 1930, Dunedin, New Zealand Ph +64 3 4799663, fax +64 3 477
> > 5232
> > 
> > Notice: This email and any attachments are confidential. If received in
> > error please destroy and immediately notify us. Do not copy or disclose
> > the contents.
> > 
> > On Thursday, July 22, 2010 18:58:39 Mike Leahy wrote:
> > > Hello list,
> > > 
> > > I'm taking a look at OpenLayers again, and I'm just trying to figure
> > > out how to effectively capture various mouse events.  Based on the
> > > examples provided, it's fairly straightforward to get click and
> > > double-click events.  But I don't seem to be able to figure out how to
> > > handle the right click event, or
> > > mouseup/mousedown events.
> > > 
> > > I've tried cobbling together a sample...and although I seem to be able
> > > to make something happen with mouseup and mousedown, these end up
> > > appearing as 'click' events.  As for a right-click event, I can't seem
> > > to capture that at all.  I'm sure this can be done, but I just don't
> > > understand the OpenLayers classes well enough to implement it.  Can
> > > someone look at the attached html file and identify where I'm going
> > > wrong?  If you drop it into the examples of the dev version of
> > > OpenLayers, it should work (at least in FireFox), and it'll write
> > > messages into a Firebug console.
> > > 
> > > Mike



More information about the Users mailing list