-
Notifications
You must be signed in to change notification settings - Fork 265
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add zoom range restriction to keepCurrentZoomLevel #247
base: gh-pages
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the PR. I have two small comments but would be happy to merge once you addressed them.
README.md
Outdated
@@ -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` | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please correct the grammar of this sentence. Also, end with a .
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure what the grammer issue is, but have just spotted the rage=>range typo. I'll try fixing this - I think as a new PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something like this (it wasn't clear what the which clause refers to):
| `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. Setting a zoom range such as `[13,18]` will only zoom the map if the current zoom level is outside the specified range. | `false` | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just saw reply. I've updated the wording, try to keep clearer. It only zooms when outside the range. It keeps the zoom when within the range! ie keep zoom (if True, or within set range) barryhunter@1eaee57
not clear if that commit, is feeding back to pull request. if not will make a new one, after resolving other comment)
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]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you extract this into a variable zoomOutsideRange
and then write if (this.options.keepCurrentZoomLevel || zoomOutsideRange)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure what mean, make something like
var zoomOutsideRange = typeof this.options.keepCurrentZoomLevel == "object" && this._map.getZoom() <= this.options.keepCurrentZoomLevel[1] && this._map.getZoom() >= this.options.keepCurrentZoomLevel[0];
if (this.options.keepCurrentZoomLevel) would still be true in case of Array, so the if(..) still complicated.
although maybe could do if (this.options.keepCurrentZoomLevel === true || zoomOutsideRange)
? (not used === in javascript!)
Or to have new this.options.zoomOutsideRange
to store the range?
var zoomOutsideRange = typeof this.options.zoomOutsideRange == "object" && this._map.getZoom() <= this.options.zoomOutsideRange[1] && this._map.getZoom() >= this.options.zoomOutsideRange[0];
Then could just do... keepCurrentZoomLevel is back to just true/false
if (this.options.keepCurrentZoomLevel || zoomOutsideRange )
Hmm, thinking about this a bit more, I am not sure we want to merge this yet. When I see an array for I'd say let's add an event that gets triggered so that you can implement your own logic for zooming in, okay? I'm going to close this PR for now. I hope you understand that I want to keep only core functionality as otherwise this library will get too complex to maintain. |
ok. sure but I'd think that this is providing the range that the zoom should be in (i.e. the target zoom level). that is what is doing. If define as |
Not quite. What I thought a range would be a is a range to clamp to. For example, if the user defines Sorry, I needed a moment to understand this proposal fully. |
Could you do these two things to finish the PR?
Thanks! |
So are thinking to have as a new separate 'option', as opposed to overloading keepCurrentZoomLevel. Or is it just reflectoring the complicated if(..) clause that concerned about? |
I think keeping it part of |
Fixes #246