SINTEF-9012 / PruneCluster

Fast and realtime marker clustering for Leaflet
MIT License
551 stars 131 forks source link

Initialize marker with dedicated pane (layer) #132

Open axelerate opened 7 years ago

axelerate commented 7 years ago

Without PruneCluster I would specify my marker creation as follows:

                renderable = L.marker([renderableMetadata.coordinate.latitude, renderableMetadata.coordinate.longitude], {
                    icon: new L.Icon.Default({
                        shadowSize: [0, 0],
                    }),
                    pane: extractedLayerId
                });

Note I was able to dictate what pane to add the marker to, but I no longer can provide options when initializing a marker (the markers are being automatically dumped into leaflet-marker-parse). Is there a workaround to this?

fungiboletus commented 7 years ago

Hello, looking at the changelog the pane attribute is a new feature of Leaflet 1.0.

The main problem I see is the lack of a setPane method in the new API. PruneCluster recycles the markers for performances reasons, so if you plan to have markers on different layers, that will probably not be possible easily.

If you just want to have all markers on the same pane, a quick workaround would be to override BuildLeafletMarker (and maybe BuildLeafletCluster) to something like this:

leafletView.BuildLeafletMarker = function(marker, position) {
    var m = new L.Marker(position, { pane: "paneId" } );
    PruneClusterForLeaflet.prototype.PrepareLeafletMarker.call(this,
        m, marker.data, marker.category);
    return m;
};

I hope it helps.