2

I have a Leaflet map that uses the Leaflet.markercluster plugin.

The clusters plot properly on the map but I am noticing that the clusters that are outside the view are still rendering even though I have the removeOutsideVisibleBounds option set to true.

The way I can tell is if I pan the map by pressing and holding the mouse button, all of the clusters are still visible as I pan.

The configuration for the cluster group is below:

let myCluster = L.markerClusterGroup({ spiderfyOnMaxZoom: false, removeOutsideVisibleBounds: true });

What else am I missing to ensure that the clusters that are outside of the view are removed?

The project is in Angular 5 using ngx-leaflet.

ghybs
  • 47,565
  • 6
  • 74
  • 99
jurgen w
  • 243
  • 1
  • 2
  • 14

1 Answers1

3

You probably just missed this part of the removeOutsideVisibleBounds option description (emphasis mine):

removeOutsideVisibleBounds: Clusters and markers too far from the viewport are removed from the map for performance.

What this "too far" means is that it still keeps markers and clusters within a "buffer" area of 1 viewport size in each direction; except for mobile, where the buffer area is 0, in order to be lighter on device memory.

Therefore on desktop browsers, you have to pan the map by more than 1 map viewport size before you see missing markers and clusters, that re-appear only when you stop panning (release the mouse).

If you inspect the source code:

Gets the maps visible bounds expanded in each direction by the size of the screen (so the user cannot see an area we do not cover in one pan)

ghybs
  • 47,565
  • 6
  • 74
  • 99