最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Problem with js function for Leaflet Marker Cluster - Stack Overflow

programmeradmin3浏览0评论
var clusterM = L.markerClusterGroup();

var geojsonPoints = new L.GeoJSON.AJAX("Files/Coordinates/coordonate_rk.geojson", {
    pointToLayer: function (feature, latlng) {
        if (type== 'All') {
            switch (feature.properties.Servicii) {
                case 'A': return L.circleMarker(latlng, geojsonMarkerOptions1);
                case 'B': return L.circleMarker(latlng, geojsonMarkerOptions2);
                default : return L.circleMarker(latlng, geojsonMarkerOptions3);
            }
        }
        if (type == 'A') {
            switch (feature.properties.Servicii) {
                case 'A': return L.circleMarker(latlng, geojsonMarkerOptions1);
                default :
            }
        }
        if (type == 'B') {
            switch (feature.properties.Servicii) {
                case 'B': return L.circleMarker(latlng, geojsonMarkerOptions2);
                default :
            }
        }
        if (type == 'Undefined') {
            switch (feature.properties.Servicii) {
                case '': return L.circleMarker(latlng, geojsonMarkerOptions3);
                default :
            }
        }
    
    
    },
    onEachFeature: function (feature, layer) {
        let popupContent = "<p style=\"font-size: 12px\">Drum : " + feature.properties.Indicativ + "<br/>" + feature.properties.Obiectiv + "<br/>" + "Tip proiect : " + feature.properties.Servicii + "</p>";
        layer.on(
            {
                click: whenClicked 
            }
        ),
        layer.bindPopup(popupContent, {closeButton: false, offset: L.point(0, -20)});
        layer.on('mouseover', function() { layer.openPopup(); });
        layer.on('mouseout', function() { layer.closePopup(); });
    }
});

geojsonPoints.on('data:loaded', function () {
    console.log('Hello1');
    clusterM.addLayer(geojsonPoints);
    map.addLayer(clusterM);

});


//geojsonPoints.addTo(map);

I ran into the problem with Leaflet having a maximum number of markers it can display, and was trying out the cluster solution I found. Problem is, I can't figure out why the on('data:loaded') part is not working. It isn't called at all. Initially I thought there was a problem with the markerClusterGroup, but the consol.log() isnt fired either. The geojsonPoints work, given how the commented geojsonPoints.addTo(map); function works. What am I missing?

I have looked into the following :

How to use leaflet markerclusterGroup?

Leaflet MarkerCluster with GeoJson

On a separate note, is there a way in Leaflet to edit the number of Markers that can be displayed? Or at least know what that number is?

发布评论

评论列表(0)

  1. 暂无评论