Search code examples
google-mapsmarkerclusterer

rendering order of multiple MarkerClusterers


I have two groups of data points, each clustered with its own MarkerClusterer instance. I thought that, if clusters/markers from the two sets happened to overlap, the one on top would belong to the clusterer I instantiated last; and it seems to work that way, mostly. But occasionally, the wrong pin comes out on top. Is that because the clusterers render asynchronously? Is there a way I can control this?


Solution

  • The answer is that marker pins are placed in a different MapPane than the cluster pins, and the MapPanes are controlled by z-index order of their own. About the MapPanes.

    Of further interest: to make the markers' z-index work,

    You have to both specify a zIndex and add optimized: false to every marker constructor

    And to make marker pins and cluster pins respect the same z-index:

    Because clustered markers sit in the overlayMouseTarget pane, you would need to create your own markers in the same pane.