4

如何動態更改用於Google Maps V3的Marker Clusterer Plus中特定羣集的圖標?Marker Clusterer Plus更改懸停圖標

標記似乎沒有公開任何方法來修改它們。我需要做這樣的事情(或同等的事情)。

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

到庫「Marker Clusterer Plus」的鏈接不起作用。你能提供鏈接嗎? – mistletoe

+0

這可能是這樣的:https://github.com/googlemaps/v3-utility-library/tree/master/markerclustererplus – Nicolas

+0

好的。非常感謝! – mistletoe

回答

13

存在對錶示集羣的div元素的引用。此div的第一個子元素是img元素,請更改此圖像的src:

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'}); 
+0

謝謝!這實際上工作得很好。然而,我的意思是改變完整'Style'的方式,即修改url,字體顏色,大小等。同樣,可惜的是唯一的方法是鏈接兩個私有方法。 – Nicolas