0

我想在 Google 地图中的图块鼠标悬停时触发 jquery 事件。我能想到的最好的是。

$('div.tileclass').live('hover', function(){
   $("#debugger").prepend("test");  //Dummy just to test if this works
});

这仅在地图加载时触发悬停动作,而不是在页面加载后触发

可以在这里看到:http ://rider.cyclistsroadmap.com (虽然调试器 div 不会显示,并且警报对于测试来说往往很烦人,并希望加载地图)

加载页面后能够触发操作的任何方式

4

1 回答 1

0

You need to add an event listener to the map's mousemove event, such as:

google.maps.event.addListener(map,'mousemove', function(mev){
    var TILE_SIZE = 256;
    var proj = map.getProjection();
    var numTiles = 1 << map.getZoom();
    var worldCoordinate = proj.fromLatLngToPoint(mev.latLng);

    var pixelCoordinate = new google.maps.Point(
            worldCoordinate.x * numTiles,
            worldCoordinate.y * numTiles);
        var tileCoordinate = new google.maps.Point(
            Math.floor(pixelCoordinate.x / TILE_SIZE),
            Math.floor(pixelCoordinate.y / TILE_SIZE));

    debug('TileX:' +tileCoordinate.x+' - TileY:'+tileCoordinate.y);

});

Note that the debug() function is contained in this separate file

The code posted here is largely based on this example from the documentation.

于 2012-07-20T10:57:16.570 回答