rightclick event inside a circle

712 views
Skip to first unread message

Eduardo

unread,
Jan 18, 2012, 7:58:23 AM1/18/12
to google-map...@googlegroups.com
hello,

i am working in a system and I need to create a custom context menu when the user right click inside a circle. i have noticed that a right click on the map triggers an event with the XY position defined, and then I can create a menu for the map. But when the rightclick is inside a circle, the event doesn't have the XY position, and I can't show the menu at the right position!!

anyone knows how to get the screen XY position when the click event is triggered?!

Martin™

unread,
Jan 19, 2012, 12:53:34 AM1/19/12
to Google Maps JavaScript API v3
Hi.

Could you add an API event listener for the Map 'mousemove' event:

http://code.google.com/apis/maps/documentation/javascript/reference.html#Map

google.maps.event.addListener(myMap, 'mousemove', function(mouseEvent)
{
lastMousePosition=mouseEvent.latLng;
});

lastMousePosition would have to be defined as a global variable in
your code.

Then add a DOM event listener for the mouse right click event.

Whenever the DOM event is triggered you will have the last mouse
position available.

Or does the API 'consume' the right click event so it will not
propogate to your DOM listener?

Martin.


On Jan 18, 12:58 pm, Eduardo <duduweil...@gmail.com> wrote:
> hello,
>
> i am working in a system and I need to create a custom context menu when
> the user right click *inside* a circle. i have noticed that a right click

Rossko

unread,
Jan 19, 2012, 5:12:42 AM1/19/12
to Google Maps JavaScript API v3
Maybe circumvent the problem - only listen for map right-clicks; when
you get one, check to see if it is within your circle(s). The maths
for that should be easy, testing if the click is less than 'radius'
distance from 'centre(s)'.

Eduardo

unread,
Jan 19, 2012, 6:51:34 AM1/19/12
to google-map...@googlegroups.com
Martin: it doesn't work
Rossko: it doesn't work too

I tried the mousemove event, but it did not get the position of the movements within the circle, it always shows the menu in the last position of the mouse over the map (ie, at the edge of the circle)

the same thing to rightclick events: the map does not receive the events that were triggered by a click or rightclick inside the circle.

Andrew Leach

unread,
Jan 19, 2012, 10:19:14 AM1/19/12
to google-map...@googlegroups.com
On 19 January 2012 11:51, Eduardo <duduw...@gmail.com> wrote:
> Martin: it doesn't work
> Rossko: it doesn't work too
>
> I tried the mousemove event, but it did not get the position of the
> movements within the circle, it always shows the menu in the last position
> of the mouse over the map (ie, at the edge of the circle)

Did you add the mousemove listener to the circle as well as the map?

> the same thing to rightclick events: the map does not receive the events
> that were triggered by a click or rightclick inside the circle.

This is why a link to the map really is needed. We need to see what
you have and try it (and debug it) for ourselves.

Nianwei Liu

unread,
Jan 20, 2012, 11:46:44 AM1/20/12
to Google Maps JavaScript API v3
The Circle class has a rightclick event and returns mouseevent with
latLng. If that's not working then it's a good candidate for firing a
bug report.

Eduardo

unread,
Jan 20, 2012, 11:53:05 AM1/20/12
to google-map...@googlegroups.com
no, you misunderstood. this is the only thing that is working. but with that i can't get the mouse position, but with the rightclick event on the map this property is already defined in the mouse event

event.pixel.x and event.pixel.y

these properties could be defined in all the click events

Rossko

unread,
Jan 20, 2012, 2:14:44 PM1/20/12
to Google Maps JavaScript API v3
> no, you misunderstood. this is the only thing that is working. but with
> that i can't get the mouse position, but with the rightclick event on the
> map this property is already defined in the mouse event
> *
> **event.pixel.x* and *event.pixel.y*

That's not documented. It might stop working in future releases.

Both map and circle are documented to return MouseEvent objects on a
rightclick, which contain a LatLng like the man said
http://code.google.com/apis/maps/documentation/javascript/reference.html#MouseEvent

If you must have pixels, you can convert a LatLng using
http://code.google.com/apis/maps/documentation/javascript/reference.html#MapCanvasProjection

If you want to raise an enhancement request to change the behaviour,
you could use the issues list
http://code.google.com/p/gmaps-api-issues/
Reply all
Reply to author
Forward
0 new messages