我能想到的用于创建自定义地图图块的最简单示例是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');
} );


我无法触发事件。

最佳答案

也许您应该查看叠加层而不是图块。当用户放大/缩小时,图块可能会更改坐标。
尝试https://developers.google.com/maps/documentation/javascript/examples/rectangle-simple

08-04 03:33
查看更多