diff --git a/README.md b/README.md index bd3537d..5a6eedb 100644 --- a/README.md +++ b/README.md @@ -80,7 +80,7 @@ Possible options are listed in the following table. More details are [in the cod | `layer` | [`ILayer`](http://leafletjs.com/reference.html#ilayer) | The layer that the user's location should be drawn on. | a new layer | | `setView` | `boolean` or `string` | Set the map view (zoom and pan) to the user's location as it updates. Options are `false`, `'once'`, `'always'`, `'untilPan'`, or `'untilPanOrZoom'` | `'untilPanOrZoom'` | | `flyTo` | `boolean` | Smooth pan and zoom to the location of the marker. Only works in Leaflet 1.0+. | `false` | -| `keepCurrentZoomLevel` | `boolean` | Only pan when setting the view. | `false` | +| `keepCurrentZoomLevel` | `boolean` or `Array` | Only pan when setting the view. Set to True (for any zoom), or a zoom range like [13,18] which will only zoom the map when outside the range. Keeps the current zoom, when current view within the defined range. | `false` | | `clickBehavior` | `object` | What to do when the user clicks on the control. Has three options `inView`, `inViewNotFollowing` and `outOfView`. Possible values are `stop` and `setView`, or the name of a behaviour to inherit from. | `{inView: 'stop', outOfView: 'setView', inViewNotFollowing: 'inView'}` | | `returnToPrevBounds` | `boolean` | If set, save the map bounds just before centering to the user's location. When control is disabled, set the view back to the bounds that were saved. | `false` | | `cacheLocation` | `boolean` | Keep a cache of the location after the user deactivates the control. If set to false, the user has to wait until the locate API returns a new location before they see where they are again. | `true` | diff --git a/src/L.Control.Locate.js b/src/L.Control.Locate.js index f8035c1..188377e 100644 --- a/src/L.Control.Locate.js +++ b/src/L.Control.Locate.js @@ -514,7 +514,10 @@ You can find the project at: https://github.com/domoritz/leaflet-locatecontrol this._event = undefined; // clear the current location so we can get back into the bounds this.options.onLocationOutsideMapBounds(this); } else { - if (this.options.keepCurrentZoomLevel) { + if (this.options.keepCurrentZoomLevel && ( + typeof this.options.keepCurrentZoomLevel == "boolean" || + (typeof this.options.keepCurrentZoomLevel == "object" && this._map.getZoom() <= this.options.keepCurrentZoomLevel[1] && this._map.getZoom() >= this.options.keepCurrentZoomLevel[0]) + )) { var f = this.options.flyTo ? this._map.flyTo : this._map.panTo; f.bind(this._map)([this._event.latitude, this._event.longitude]); } else {