2016-05-26 74 views
-1

我有以下的jQuery代碼添加地圖標記集羣:以標記羣集添加自定義圖像,而不會覆蓋標記

markerCluster = new MarkerClusterer(map); 

我使用markerCluster.addMarker(Marker);個人標記在底部添加到集羣(完整的代碼塊這一頁)。

我遇到的問題是我的羣集默認沒有附加圖像。

我可以做到以下幾點:

var options = 'an image path'; 
markerCluster = new MarkerClusterer(map,markers,options); 

然而,由於選擇的是第三個參數,能有效地覆蓋第二個參數。有沒有辦法將圖像設置爲MarkerCluster而不覆蓋標記?

(function() { 
      var address = response[key]["address"]; 
      $.getJSON('http://maps.googleapis.com/maps/api/geocode/json?address='+response[key]["post_code"]+'&sensor=false', null, function (data) { 
       var p = data.results[0].geometry.location 
       var latlng = new google.maps.LatLng(p.lat, p.lng); 
       var Marker = new google.maps.Marker({ 
        position: latlng, 
        map: map, 
        content: address 
       }); 
       markerCluster.addMarker(Marker); 
       google.maps.event.addListener(Marker, 'click', function() {  
        infowindow.setContent(this.content); 
        infowindow.open(map, this); 
       }); 
      }); 
     })(); 
+0

請提供一個[最小,完整,測試和可讀的示例](http://stackoverflow.com/help/mcve),說明問題。你如何創建'markerCluster'?在添加任何具有空數組的標記之前,您應該可以創建它。 – geocodezip

回答

1

默認情況下,MarkerClusterer查找在../images文件夾標記(相對於markerclusterer.js的位置)。

最簡單的事情,你會得到從github圖像文件夾,這樣你的文件的結構如下:

-images 
    -m1.png 
    -m2.png 
    -..etc other files from the directory 
-SOME_FOLDER //can be lib, libraries, what have you 
    -markerclusterer.js 

或者你可以用options對象的imagePath屬性玩,所以你會有這樣的事情:

var options = { imagePath: "PATH_TO_IMAGES_FOLDER/m" }; 
markerCluster = new MarkerClusterer(map, markers, options);