I want to:
- Draw rectangles on a google map
- Have at most on rectangle
- Display the current location of the mouse when it moves
So, I came up with this code - /
I subscribe to the rectangleplete
event of the DrawingManager
instance in order to dispose of the previous rectangle, save the reference to the new one and subscribe to the mousemove event on the rectangle.
The problem, is that the mousemove
event is never triggered.
What am I doing wrong and how to fix it?
Thanks.
I want to:
- Draw rectangles on a google map
- Have at most on rectangle
- Display the current location of the mouse when it moves
So, I came up with this code - http://jsfiddle/mark69_fnd/vBwf6/4/
I subscribe to the rectangleplete
event of the DrawingManager
instance in order to dispose of the previous rectangle, save the reference to the new one and subscribe to the mousemove event on the rectangle.
The problem, is that the mousemove
event is never triggered.
What am I doing wrong and how to fix it?
Thanks.
Share Improve this question edited Apr 23, 2012 at 13:21 mark asked Apr 23, 2012 at 12:59 markmark 63k96 gold badges347 silver badges671 bronze badges1 Answer
Reset to default 7Here is a function, which gives GPS coordinates by pixel offset related to top-left corner of map's container.
function getLatLngByOffset( map, offsetX, offsetY ){
var currentBounds = map.getBounds();
var topLeftLatLng = new google.maps.LatLng( currentBounds.getNorthEast().lat(),
currentBounds.getSouthWest().lng());
var point = map.getProjection().fromLatLngToPoint( topLeftLatLng );
point.x += offsetX / ( 1<<map.getZoom() );
point.y += offsetY / ( 1<<map.getZoom() );
return map.getProjection().fromPointToLatLng( point );
}
Add 'onmousemove'
event listener on map's div element, then pass mouse position related to div's top-left corner.
UPDATE: DEMO (Tested on Chrome)