我正在从谷歌地图api v2迁移到v3。在v2中,我们有一个工具提示的自定义叠加层,类似于v3中的标题。我想摆脱自定义叠加层,因为它在v3中无法正常工作,并且作为标题维护起来会更简单。问题是我在地图之外有片段,当它们与之交互时显示工具提示。我以为我可以用这样的东西来显示标题:
showTooltip: function(i) {
var marker = i && this.MARKERS ? this.MARKERS[i] : this.marker;
if (!marker.infoWindowOpen) {
google.maps.event.trigger(marker, 'mouseover', {ltLng: marker.getPosition()});
}
}
但是标题没有显示。我们的想法是模拟标记上的鼠标,以便显示标题。
答案 0 :(得分:1)
这就是我打开和关闭字幕的方式,我认为你可以使用相同的方法:
body .gmnoprint[title] {
overflow: visible !important;
width: auto !important;
background: transparent;
opacity: 1 !important;
}
body[data-captions='true'] .gmnoprint[title*="^"]:after {
background: none repeat scroll 0 0 rgba(255, 255, 255, 0.85);
content: attr(title);
display: block;
font-size: 90%;
left: 0em;
padding: 0em 0.6em;
position: relative;
top: 1em;
white-space: pre;
width: auto;
border-radius: 1em;
vertical-align: top;
color: #000;
font-weight: bold;
font-family: sans-serif;
text-shadow: 0 0 1px #fff, 0 0 3px #fff;
opacity: 0.75;
}
然后你可以切换身体标签数据字幕attrib来打开和关闭字幕。
它使用CSS来显示标题,通常无法显示脚本,但使用CSS生成内容的魔力,我们可以以有吸引力和可自定义的方式显示标题信息。
我相信代码会碰到一个标记,不确定这是否是你所拥有的,但它应该可以处理任何带有标题的东西。
在我的情况下,标题就是这个(如果需要可以是透明的):
var marker = new google.maps.Marker({
position: pos,
map: map,
icon: {
path: 0,
scale: 3,
fillColor: spot.color,
strokeWeight: 8,
strokeColor: spot.color,
fillOpacity: 1,
strokeOpacity: 0.333
},
title: "^ "+spot.name
});