【问题标题】:Google map api v3, how to add polygons to custom overlayGoogle map api v3,如何将多边形添加到自定义叠加层
【发布时间】:2014-04-23 13:29:10
【问题描述】:

以下站点:https://developers.google.com/maps/documentation/javascript/customoverlays 展示了如何使用 customoverlays 创建图像叠加层,但我如何使用相同的技术使用 customoverlays 创建多边形。我使用的地图来自以下示例 http://gmaps-samples-v3.googlecode.com/svn/trunk/latlng-to-coord-control/latlng-to-coord-control.html 。但是,当我将多边形添加到地图时,当我将鼠标移到多边形上时,它无法显示纬度/经度/像素值。我认为如果我使用自定义叠加创建多边形,问题就会得到解决。我使用自定义叠加创建了图像叠加,当我将鼠标移到图像上时,它能够显示正确的纬度/经度/像素值。因此,我认为如果我使用自定义叠加创建多边形,它也应该可以工作,但我找不到有关如何做到这一点的示例。请指教。

更新代码:

aoiPoly = new google.maps.Polygon({ 
  paths: polyCoords, 
  strokeColor: '#FF0000', 
  strokeOpacity: 0.8, 
  strokeWeight: 2, 
  fillColor: '#FF0000', 
  fillOpacity: 0.35, 
  clickable:false 
}); 
aoiPoly.setMap(map);

【问题讨论】:

  • 你为什么不把polygons设置成clickable:false
  • 我重新检查了我的代码并尝试为多边形设置 clickable:false。现在它起作用了!非常感谢您的回答,geocodezip。这是代码: aoiPoly = new google.maps.Polygon({ paths: polyCoords, strokeColor: '#FF0000', strokeOpacity: 0.8, strokeWeight: 2, fillColor: '#FF0000', fillOpacity: 0.35, clickable:false }) ; aoiPoly.setMap(map);

标签: google-maps-api-3


【解决方案1】:

如果您在google.maps.Polygons 上设置clickable:false,将阻止它们拦截鼠标事件。

clickable | boolean | Indicates whether this Polygon handles mouse events. Defaults to true

【讨论】:

  • 是的,我也意识到了这一点,但我不知道允许鼠标事件在多边形上同时允许在鼠标悬停在多边形上时使用 LatLngControl 方法显示坐标Google 的示例代码 (gmaps-samples-v3.googlecode.com/svn/trunk/…)。
猜你喜欢
  • 2012-07-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-01-21
  • 1970-01-01
  • 2012-03-21
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多