https://github.com/asleepwalker/leaflet.hardbounds
Leaflet plugin to prevent panning outside of map bounds
https://github.com/asleepwalker/leaflet.hardbounds
bounds leaflet map-bounds outside panning plugin prevent
Last synced: 3 months ago
JSON representation
Leaflet plugin to prevent panning outside of map bounds
- Host: GitHub
- URL: https://github.com/asleepwalker/leaflet.hardbounds
- Owner: asleepwalker
- License: mit
- Created: 2015-09-03T07:09:39.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2017-02-07T11:57:10.000Z (over 9 years ago)
- Last Synced: 2025-10-22T19:50:01.873Z (8 months ago)
- Topics: bounds, leaflet, map-bounds, outside, panning, plugin, prevent
- Language: JavaScript
- Homepage:
- Size: 51.8 KB
- Stars: 8
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
#Leaflet.HardBounds [](https://gemnasium.com/github.com/asleepwalker/leaflet.hardbounds)
[Leaflet](http://leafletjs.com/) plugin to prevent panning outside of map bounds.
Requires: Leaflet v0.6.3 or higher.
## Usage
Setup hard bounds:
map.addHardBounds();
Then you can set maxBounds as usual:
var bounds = L.latLngBounds([[51.55, -0.2], [51.45, 0]]);
map.setMaxBounds(bounds);
Or even unset them:
map.setMaxBounds(null);
However, it's better to remove listener if you need hard bounds no more:
map.removeHardBounds();
### Demo
## License
The MIT License.