如何在鼠标悬停在 Google 地图标记上时使其变大?

6
在Google Map API v3中,正如标题所示,我只看到了2种类型的动画,但我在某些地方看到地图标记器在鼠标悬停时像变大一样的动画?如何实现这个效果?
2个回答

3
使用标记的mouseover事件处理程序和setIcon()方法。您可以使用Google图表API中的动态图标来实现此目的,并更改chld属性以使图标增大:

enter image description here http://chart.googleapis.com/chart?chst=d_map_spin&chld=0.5|0|FF8800|15|_|

enter image description here http://chart.googleapis.com/chart?chst=d_map_spin&chld=0.6|0|FF8800|15|_|

enter image description here http://chart.googleapis.com/chart?chst=d_map_spin&chld=0.7|0|FF8800|15|_|

不要忘记设置正确的锚点!例如:

marker.setIcon(new google.maps.MarkerImage(
    'http://chart.googleapis.com/chart?chst=d_map_spin&chld=0.65|0|FF8800|15|_|',
    null,
    null,
    new google.maps.Point(11, 43) // this is the proper anchor point for scale 0.65
));

截至2012年,此方法已被弃用。有人知道现代化的解决方案吗? - FRD
如果你只是点击自己的链接,你就会看到。;) - FRD

1

您可以使用自己的图像作为标记,然后利用标记图像的 scaledSize 属性,在 mouseover 事件触发时将其放大。

我不知道有没有其他简单的方法可以实现这个功能。


你解决了这个问题吗?如果它真的有效,请点赞。请告诉我。 - Yes Barry
@mmmshuddup 抱歉,我已经有一段时间没有在这上面工作了。由于已经超过一年的时间,你可能会发现 API 已经发生了变化/改进。 - Oliver

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接