2017-03-09 87 views
0

我正在使用Leaflet在離子應用程序中顯示地圖,我正在使用https://github.com/Leaflet/Leaflet.markercluster#customising-the-clustered-markers來啓用羣集。標記圖標總是默認

我似乎無法讓我的自定義圖標顯示,但我總是得到藍色默認值。

首先我創建markerClusterGroup

var markers = L.markerClusterGroup({ 
    spiderfyOnMaxZoom: true, 
    showCoverageOnHover: true, 
    zoomToBoundsOnClick: true 
    }); 

然後,我創建的圖標:

var myIcon = L.icon({ 
     iconUrl: '<myiconurl.png>' 
    }); 

我然後通過我需要顯示在地圖上的對象的陣列循環填充的標記陣列,並綁定一個彈出窗口[也可以放到每個標記上。

for (var i = 0; i < $scope.arrayOfVenues.length; i++) { 
    var name = $scope.arrayOfVenues[i].name; 
    var id = $scope.arrayOfVenues[i].venueID; 
    var image = $scope.arrayOfVenues[i].venueImageURL; 
    var distanceTo = "4 Miles Away"; 
    var popupContent = "<div style='height:200px;width:100%;position:relative;cursor:pointer;z-index:999999' nav-transition='ios' onclick='window.navDetails(" + id + ")'><img style='object-fit: cover;position:absolute;left:0;top:0;' height='200' width='100%' src='" + image + "'/><h3 style='color:#FFFFFF !important;position:absolute;z-index:100;bottom:3vh;left:14px;font-size:3vh;'>" + name + "</h3><h3 style='color:#FFFFFF !important;position:absolute;z-index:100;bottom:0;left:14px;font-size:2.5vh;'>" + distanceTo + "</h3></div>" 
    markers.addLayer(L.marker([ 
     $scope.arrayOfVenues[i].latitude, 
     $scope.arrayOfVenues[i].longitude, { 
     title: $scope.arrayOfVenues[i].name, 
     riseOnHover: true, 
     icon:myIcon 
     } 
    ]).bindPopup(popupContent, { 
     maxWidth: 300, 
     minWidth: 300, 
     minHeight: 300, 
     maxHeight: 300 
    })); 
    debugger 
    } 
    mymap.addLayer(markers); 

一旦顯示在地圖上,一切工作好,除了我還有默認標記圖標。

任何提示?

+1

'「」'看起來像一個佔位符,或者是它的文字? – stholzm

+0

對不起,我只是拿出網址發佈在這裏! – anthonyhumphreys

+1

啊,好的。另一件事:'myIcon'實際上是'barIcon'? – stholzm

回答

2

剛剛從看代碼,我相信一個右括號是放錯了地方:

markers.addLayer(L.marker([ 
    $scope.arrayOfVenues[i].latitude, 
    $scope.arrayOfVenues[i].longitude 
], { 
    title: $scope.arrayOfVenues[i].name, 
    riseOnHover: true, 
    icon:myIcon 
    } 
) 
+0

你絕對是聖人。即使我向你提供困惑,無用的代碼,你仍然可以找到解決方案。謝謝!! – anthonyhumphreys