谷歌地图v3向圆圈添加信息窗口
有没有办法将 infoWindow 添加到由 google.maps.Circle 创建的圆圈中
,
var circ = new google.maps.Circle({
center:latlng,
clickable:false,
fillColor:colors[count],
fillOpacity:0.3,
map:map,
radius:radius,
strokeColor:colors[count],
strokeOpacity:0.3});
或者
//create info window
var infoWindow= new google.maps.InfoWindow({
content: "Your info here"
});
//add a click event to the circle
google.maps.event.addListener(circ, 'click', function(){
//call the infoWindow
infoWindow.open(map, circ);
});
有没有办法在圆圈中心创建一个不可见的标记,可以单击该标记来访问 infoWindow
Is there a way to add a infoWindow to a circle created by google.maps.Circle
something like this
var circ = new google.maps.Circle({
center:latlng,
clickable:false,
fillColor:colors[count],
fillOpacity:0.3,
map:map,
radius:radius,
strokeColor:colors[count],
strokeOpacity:0.3});
and
//create info window
var infoWindow= new google.maps.InfoWindow({
content: "Your info here"
});
//add a click event to the circle
google.maps.event.addListener(circ, 'click', function(){
//call the infoWindow
infoWindow.open(map, circ);
});
or alternatively is there a way to create an invisible marker at the center of the circle that can be clicked on to access an infoWindow
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以为您的圆圈叠加层提供信息窗口。但你必须稍微调整你的代码。
首先,需要为您的 Circle 叠加层设置
clickable=true
(否则不会处理圆圈上的点击事件)。然后你必须更改点击监听器的代码。将 Circle 作为函数 open() 的参数没有任何效果(Circle 不是正确的 MVCObject 类型,有关解释,请阅读 InfoWindow.open() 函数)。要显示信息窗口,您必须提供其位置 - 例如点击事件的位置、圆的中心......。
然后代码是
或
回答您的评论:
您可以使用不可见的标记创建一个技巧(只需将完全透明的图像作为标记图标),但我更喜欢使用圆形覆盖的解决方案。
you can have info window for your circle overlay. But you have to slightly adjust your code.
First, it is necessary to set
clickable=true
for your Circle overlay (otherwise click events on the circle are not processed).Then you have to change the code of the click listener. Putting circle as a parameter to function open() has no effect (Circle is not the proper kind of MVCObject, for explanation read documentation of InfoWindow.open() function). To display the info window you have to provide its position - e.g. position of the click event, center of the circle, ....
The code is then
or
Answer to your comment:
You can create a trick with an invisible marker (just put fully transparent image as the marker icon), but I would prefer solution with Circle overlay.
在鼠标单击的位置设置信息窗口
to set info window at where mouse clicked
我也有同样的困惑。我简单地使用解决了它
I got same confusion. I simply solved it using