Let's say we have the following map:
https://jsfiddle.net/fcumj09w/5/
In the above example, we have 2 marker cluster groups (clustRed and clustYellow) and a single marker outside of these groups.
I want the red marker cluster group to be on top (higher z-index) of the yellow marker cluster group, when zooming out.
I have created 3 custom panes to attach each cluster group to a different pane but it seems like panes don't work with cluster groups (or I haven't find the way to make them work).
What I tried:
var clustRed = L.markerClusterGroup({pane:'hilevel'});
var clustYellow = L.markerClusterGroup({pane:'lowlevel'});
I can only make panes work with the single marker:
L.circleMarker([45,5],{pane:"midlevel"}).addTo(map);
How can I make Leaflet.markercluster use the pane that I specify?
Note: this functionality is now available as
clusterPaneoption. Added since version 1.1.0.Although Layer Groups in Leaflet (including the MarkerClusterGroup from Leaflet.markercluster plugin) inherit from the
Layerbase class, which indeed provide thepaneoption, any child layer added to them still use their own specifiedpane, if any, or use the default one (i.e.overlayPane).It is still undecided whether that behaviour should be changed or not (see Leaflet issue #4279).
In the case of a MarkerClusterGroup, the latter even actually generates markers on its own, using the
L.MarkerClusterclass, which represent a cluster of individual markers.From your description, you would like those generated markers to be inserted in specific panes.
In that case, you could very simply override the
initializemethod ofL.MarkerClusterclass so that it uses whicheverpaneyou want. In your case, you would read the MarkerClusterGroup' optionpanemember:Once this is patched, the generated marker clusters will use the
panethat you specify when instantiating the MarkerClusterGroup, as shown in your question:Updated JSFiddle: https://jsfiddle.net/fcumj09w/9/