简体   繁体   English

适用于 Google Maps API v3 的可扩展地图标记叠加

[英]Expandable map marker overlay for Google Maps API v3

I have been using Google Maps API v3 for a long time now.我已经使用 Google Maps API v3 很长时间了。 I want to create an expandable google maps marker for using with my map.我想创建一个可扩展的谷歌地图标记,用于我的地图。 I have been using map markers similar to the one in the image below:-我一直在使用类似于下图中的地图标记:- 标记

What I want to do is that when I hover on this marker on my map, it should expand and show the marker description, similar to the image below -我想要做的是,当我将鼠标悬停在地图上的此标记上时,它应该展开并显示标记描述,类似于下图 - 带描述的标记

And the marker should go back to the first image, ie, normal image when hovered out.并且标记应该回到第一张图像,即悬停时的正常图像。 It should be fairly simply to do this, however, I have no idea where and how to start.这样做应该相当简单,但是,我不知道从哪里开始以及如何开始。 Any help will be really appreciated.任何帮助将不胜感激。

You can use marker.setIcon on mouseover and mouseout :您可以在mouseovermouseout上使用marker.setIcon

google.maps.event.addListener(marker, 'mouseover', function() {
    marker.setIcon('http://i.stack.imgur.com/t7vAK.png');
});
google.maps.event.addListener(marker, 'mouseout', function() {
    marker.setIcon('http://i.stack.imgur.com/TrIat.png');
});

Demo: http://jsfiddle.net/mzu2qte5/2/演示: http : //jsfiddle.net/mzu2qte5/2/

The small issue with this solution is that arrow of the 'Hello World' icon should be placed in the middle of the icon, instead moved to left, as it is now.这个解决方案的一个小问题是“Hello World”图标的箭头应该放在图标的中间,而不是像现在一样移到左边。

That way you loose 'expand' effect.这样你就失去了“扩展”效果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM