我知道我可以使用显示“某事”的工具提示来做一个标记,如下所示:
marker = new google.maps.Marker({
position: new google.maps.LatLng(lat,lon),
map: map,
draggable: true,
title:"SOMETHING",
icon: '/public/markers-map/male-2.png'
});
我想对一个圆圈做同样的事情,但是 标题 不起作用。
new google.maps.Circle({
center: new google.maps.LatLng(lat,lon),
radius: 20,
strokeColor: "blue",
strokeOpacity: 1,
title:"SOMETHING",
strokeWeight: 1,
fillColor: "blue",
fillOpacity: 1,
map: map
});
它打印圆圈但不显示消息“SOMETHING”。
我该怎么做?有没有其他属性可以得到它?
提前致谢。
最佳答案
工具提示是通过原生 title
创建的-DOM 元素的属性,但 API 不提供任何方法来访问包含圆的 DOMElement。
一种可能的解决方法可能是改用 map-div 的标题属性(设置它 onmouseover
并删除它 onmouseout
)
//circle is the google.maps.Circle-instance
google.maps.event.addListener(circle,'mouseover',function(){
this.getMap().getDiv().setAttribute('title',this.get('title'));});
google.maps.event.addListener(circle,'mouseout',function(){
this.getMap().getDiv().removeAttribute('title');});
关于google-maps - 谷歌地图,在圆圈上显示工具提示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21069097/