Using a real-time tile layer in the markercluster group

I am using Leaflet in combination with realtime and markercluster to show markers that are updated in real time on the map. The plugins work fine independently of each other, but the problem occurs when I want to group a layer in real time using the markercluster functions.

Sample code for a live layer in which I convert json to markers, assign a custom icon and apply some onEachFeature:

realtimeLayer = L.realtime({
    url: 'someURL',
    crossOrigin: true,
    type: 'json'
}, {
    interval: 3 * 1000,
    onEachFeature: onEachFeature,
    pointToLayer: function(feature, latlng) {
        return L.marker(latlng, {
            icon: customIcon
        });
    }
});

      

What I can do with non-realtime markers levels is create a markercluster group and add a layer to it, so the markers are clustered like this:

var clusterGroup = L.markerClusterGroup();
clusterGroup.addLayer(someLayer);

      

However, when I add the realtimeLayer to the cluster group, no clustering is applied, or the marker is not loaded at all. What am I missing? Thank!

+3


source to share





All Articles