Skip to content

brandoncopeland/Leaflet.boundsAwareLayerGroup

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

40 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Leaflet.boundsAwareLayerGroup

Leaflet.LayerGroup plugin to render only layers in the current map bounds

Adding lots of layers to a map can kill browser performance, even if the layers are outside the map bounds and not visible to the user. Leaflet.boundsAwareLayerGroup patches Leaflet.LayerGroup to manage only rendering in the map layers in the map bounds. On each map bounds change (zoom, pan, whatever...), layers in the new bounds are added, layers outside are removed.

See the plugin in action when comparing performance with and without Leaflet.boundsAwareLayerGroup for 5,000 markers.

Using the plugin

Create a new Leaflet.LayerGroup with the makeBoundsAware option.

new L.LayerGroup([marker1, marker2], {
	makeBoundsAware: true
}.addTo(map);

or

L.layerGroup([marker1, marker2], {
	makeBoundsAware: true
}).addTo(map);

Leaflet.boundsAwareLayerGroup works with Leaflet.FeatureGroup as well...

L.featureGroup([marker1, marker2], {
	makeBoundsAware: true
}).addTo(map);

Additional options

  • minZoom - Do not show LayerGroup if map zoom is less than minZoom
  • maxZoom - Do not show LayerGroup if map zoom is greater than maxZoom

About

Leaflet.LayerGroup plugin to render only layers in the current map bounds

Resources

Stars

Watchers

Forks

Packages

No packages published