鼠标悬停时更改标记图标(谷歌地图V3) [英] change marker icon on mouseover ( google maps V3 )

查看:77
本文介绍了鼠标悬停时更改标记图标(谷歌地图V3)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

var image = 'bullets/_st_zzzzzzl SSS.gif';

var bar1 = new google.maps.Marker({
    position: myLatLng, 
    map: map,
    icon: image,
    title: "bar number 1"       
}); 

    google.maps.event.addListener(bar1, 'mouseover', function() {
        infowindow.open(map,bar1);
    });

    google.maps.event.addListener(bar1, 'mouseout', function() {
        infowindow.close(map,bar1);
    });

现在,当我将鼠标悬停在上方时,我希望图标更改为我得到的另一张图像. 我尝试了一些技巧和一些代码,但没有用... 感谢您的帮助

Now when im on mouseover i want the icon to change to another image i got. i tried some tips and some code but nothing works... Appreciate ur help

推荐答案

使用marker.setIcon()函数.其余与代码中打开/关闭信息窗口几乎相同:

Use marker.setIcon() function. The rest is almost the same as opening/closing infowindow in your code:

var icon1 = "imageA.png";
var icon2 = "imageB.png";

var marker = new google.maps.Marker({
    position: myLatLng,
    map: map,
    icon: icon1,
    title: "some marker"
});

google.maps.event.addListener(marker, 'mouseover', function() {
    marker.setIcon(icon2);
});
google.maps.event.addListener(marker, 'mouseout', function() {
    marker.setIcon(icon1);
});

请注意,除了在setIcon()函数中使用图像路径之外,还可以使用google.maps.MarkerImage对象,这非常有用,尤其是在要使用图像精灵的情况下.

Note that besides using image paths in setIcon() function, you can also use google.maps.MarkerImage objects, which are very useful, especially if you want to use image sprites.

这篇关于鼠标悬停时更改标记图标(谷歌地图V3)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆