From 5a698f4aeaa0f4251022dec1590d8436f02ae6fc Mon Sep 17 00:00:00 2001 From: barryhunter Date: Tue, 16 Jul 2019 10:58:21 +0100 Subject: [PATCH 1/3] And zoom range restriction to keepCurrentZoomLevel --- src/L.Control.Locate.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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 { From 892ed51997826d1477112b56ea77f6b0382b2be7 Mon Sep 17 00:00:00 2001 From: barryhunter Date: Tue, 16 Jul 2019 11:00:21 +0100 Subject: [PATCH 2/3] Add zoom restriction to keepCurrentZoomLevel --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index bd3537d..b1d4e17 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, or a zoom range like [13,18] which will only zoom the map when outside the rage. Allows keeping the current view at these scales | `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` | From 1eaee571533969af8c888b7b7d745490e4bfb255 Mon Sep 17 00:00:00 2001 From: barryhunter Date: Tue, 16 Jul 2019 12:49:34 +0100 Subject: [PATCH 3/3] wording update --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b1d4e17..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` or `Array` | Only pan when setting the view. Set to True, or a zoom range like [13,18] which will only zoom the map when outside the rage. Allows keeping the current view at these scales | `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` |