是否可以为各个谷歌地图图块添加一个监听器?

时间:2013-08-29 01:18:11

标签: javascript google-maps google-maps-api-3

我能想到的创建自定义地图图块的最简单示例是Google maps base tile example.

这里唯一有趣的部分是我们在getTile()中添加的内容:

CoordMapType.prototype.getTile = function(coord, zoom, ownerDocument) {
  var div = ownerDocument.createElement('div');
  div.innerHTML = coord;
  div.style.width = this.tileSize.width + 'px';
  div.style.height = this.tileSize.height + 'px';
  div.style.fontSize = '10';
  div.style.borderStyle = 'solid';
  div.style.borderWidth = '1px';
  div.style.borderColor = '#AAAAAA';
  div.style.backgroundColor = '#E5E3DF';
  return div;
};

是否有可能为单个地图图块添加鼠标悬停或点击事件,例如,在返回div之前做这样的事情?

google.maps.event.addDomListener(div, 'click', function() {
alert( ' test - called from addListener');
} );

我不能让事件发生。

1 个答案:

答案 0 :(得分:0)

也许你应该看看叠加而不是瓷砖。当用户放大/缩小时,平铺可以改变坐标。 试试https://developers.google.com/maps/documentation/javascript/examples/rectangle-simple