最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Rectangle drawn by google maps DrawingManager does not trigger the mousemove event - Stack Overflow

programmeradmin1浏览0评论

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 badges
Add a ment  | 

1 Answer 1

Reset to default 7

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

发布评论

评论列表(0)

  1. 暂无评论