【发布时间】:2013-04-04 20:03:08
【问题描述】:
我有两个标记,用一条折线连接这两个标记。 我在标记和折线上有点击事件,但我试图让折线更容易点击,而无需放置新的标记或增加它的 strokeWeight。 所以我创建了一个圆形图标并放置在折线上,但我无法使其可点击。可能吗?
看到了这个帖子,但没有具体说明图标是如何可点击的。我搜索了它的代码源,但他添加了一个 KML 层。我不想那样做。 Google Maps: Attaching events on polyline icons
搜索了谷歌地图覆盖API,但没有找到任何监听点击事件的接口。 https://developers.google.com/maps/documentation/javascript/overlays#Polylines
我也尝试附加一个事件侦听器,但没有成功。我怀疑如果不添加实际标记或对象就无法完成,但如果其他人遇到类似问题,我将不胜感激任何提示:)
提前致谢!
我的代码:
var pathSymbol = {
path: google.maps.SymbolPath.CIRCLE,
scale: 8,
strokeColor: '#228B22'
};
var conPath = new google.maps.Polyline({
path: conCoord,
strokeColor: "#228B22",
strokeOpacity: 0.7,
icons: [{
icon: pathSymbol,
offset: '50%'
}],
strokeWeight: 2
});
conPath.setMap(map);
google.maps.event.addListener(conPath, 'click', (function(l,conCoord) {
return function() {
infowindowPath.setContent("<b>Ligação "+connections[l].id);
infowindowPath.setPosition(new google.maps.LatLngBounds(conCoord[1], conCoord[0]).getCenter());
infowindowPath.open(map);
}
})(l,conCoord));
【问题讨论】:
标签: javascript google-maps events polyline