簡體   English   中英

Leaflet MarkerCluster和自定義標記

[英]Leaflet MarkerCluster and customized markers

我正在嘗試使用插件MarkerCluster和自定義標記圖標來實現Leaflet地圖。 該代碼在渲染群集時效果很好,但是標記存在一些問題。 實際上,渲染的標記是經典的傳單藍色別針,而不是我自定義的圖標(即logo_circle.png),這是代碼:

var tiles = L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
            attribution: '&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors',
            maxZoom: 18
            }),
            latlng = L.latLng(37.366667, 128.4);

        var map = L.map('map', {center: latlng, zoom: 9, layers: [tiles]});


        var OlympicIcon = L.icon({
            iconUrl: 'logo_circle.png',
            iconSize:     [36, 36], // size of the icon
            iconAnchor:   [0, 0], // point of the icon which will correspond to marker's location
            popupAnchor:  [0, 0] // point from which the popup should open relative to the iconAnchor
        });


        var markers = L.markerClusterGroup();

        for (var i = 0; i < addressPoints.length; i++) {
            var a = addressPoints[i];
            var title = a[2];
            var marker = L.marker(new L.LatLng(a[0], a[1]), { title: title }, {icon: myIcon});
            marker.bindPopup(title);
            markers.addLayer(marker);
        }

        markers.addLayer(OlympicIcon);

        map.addLayer(markers);

怎么了?

你的icon選項應該僅僅是第二個參數的成員 (選項) L.marker廠,旁邊title選項,而不是作為一個單獨的第三個參數:

var marker = L.marker(new L.LatLng(a[0], a[1]), {
  title: title,
  icon: myIcon
});

另請參閱https://gis.stackexchange.com/questions/183725/leaflet-pop-up-does-not-work-with-geojson-data/183832#183832

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM