Merge pull request #3410 from IvanSanchez/multiple-maxbounds

Prevent recursion on map.setMaxBounds
This commit is contained in:
Vladimir Agafonkin 2015-04-29 13:52:25 +03:00
commit 24ce6b3e8e
2 changed files with 6 additions and 2 deletions

View File

@ -33,6 +33,8 @@
var latlngs = L.rectangle(bounds).getLatLngs();
L.polyline(latlngs.concat([latlngs[0]])).addTo(map);
map.setMaxBounds(bounds); // Should not enter infinite recursion
</script>
</body>
</html>

View File

@ -138,12 +138,14 @@ L.Map = L.Evented.extend({
setMaxBounds: function (bounds) {
bounds = L.latLngBounds(bounds);
this.options.maxBounds = bounds;
if (!bounds) {
return this.off('moveend', this._panInsideMaxBounds);
} else if (this.options.maxBounds) {
this.off('moveend', this._panInsideMaxBounds);
}
this.options.maxBounds = bounds;
if (this._loaded) {
this._panInsideMaxBounds();
}