Leaflet MarkerCluster和自定义标记

时间:2018-02-01 22:36:54

标签: javascript maps leaflet

我试图用插件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);

怎么了?

1 个答案:

答案 0 :(得分:0)

您的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