Skip to content
This repository has been archived by the owner on Nov 21, 2024. It is now read-only.

Restricts Leaflet's map bounds to area not covered by any map controls

License

Notifications You must be signed in to change notification settings

MazeMap/Leaflet.ControlledBounds

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Deprecated

This repository is no longer maintained and is deprecated. Please be aware that it may not work with the latest versions of its dependencies.


Leaflet.ControlledBounds

This Leaflet plugin overloads some of the map's methods (setView, fitBounds, setZoom) so that the bounds are relative to the area of the map not covered by any map controls (hence "controlled" bounds). The center of the map becomes the center of that area.

Demo

Try the example page !

Usage

Include the javascript file after including the main Leaflet library:

<script src="Leaflet.ControlledBounds.js"></script>

The useful bounds of the map will be cut down to the largest area not covered by any map controls (instances of L.Control added to the map).

Then, the map will center itself in the center of that DIV when calling setView, setZoom, fitBounds, getBounds, or zooming in/out.

Limitations

The plugin will not detect changes in the size (or position) of the map controls. If the controls change under controlled circumstances (e.g. panels expanding), run invalidateSize():

map.invalidateSize();

The plugin has only been tested with Leaflet 0.7.x. It will most probably not work well with Leaflet 1.0's flyTo and flyToBounds methods.

License

Licensed under the Apache 2.0 license. See the LICENSE file for details.

Contains code from Leaflet-active-area.