Marker Clusterer Plus change icon on hover

可紊 提交于 2019-12-10 17:14:34

问题


How can I dynamically change the Icon used for a specific Cluster in Marker Clusterer Plus for Google Maps V3?

The markers do not seem to expose any methods at all to modify them. I need to do something like this (or equivalent).

google.maps.event.addListener(markerCluster, "mouseover", function (cluster) {
  cluster.setIcon(hoverIcon);
});
google.maps.event.addListener(markerCluster, "mouseout", function (cluster) {
  cluster.setIcon(normalIcon);
});

回答1:


There is a reference to the div-element that represents the cluster. The first child of this div is the img-element, change the src of this image:

    google.maps.event.addListener(markerCluster,'mouseover',function(c){
      c.clusterIcon_.div_.firstChild.src='hoverIconPath'});

    google.maps.event.addListener(markerCluster,'mouseout',function(c){
      c.clusterIcon_.div_.firstChild.src='normalIconPath'});



回答2:


There is some changing in last google maps.

    google.maps.event.addListener(markerCluster, 'clusterclick', function(cluster) {
    cluster.clusterIcon_.div_.style.backgroundImage = 'url("linktoyourimage")'})

Image icon moved to background.



来源:https://stackoverflow.com/questions/20454582/marker-clusterer-plus-change-icon-on-hover

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!