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
clusterPane
option. Added since version 1.1.0.Although Layer Groups in Leaflet (including the MarkerClusterGroup from Leaflet.markercluster plugin) inherit from the
Layer
base class, which indeed provide thepane
option, 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.MarkerCluster
class, 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
initialize
method ofL.MarkerCluster
class so that it uses whicheverpane
you want. In your case, you would read the MarkerClusterGroup' optionpane
member:Once this is patched, the generated marker clusters will use the
pane
that you specify when instantiating the MarkerClusterGroup, as shown in your question:Updated JSFiddle: https://jsfiddle.net/fcumj09w/9/