leaflet-locatecontrol icon indicating copy to clipboard operation
leaflet-locatecontrol copied to clipboard

Add zoom range restriction to keepCurrentZoomLevel

Open barryhunter opened this issue 5 years ago • 6 comments

Fixes https://github.com/domoritz/leaflet-locatecontrol/issues/246

barryhunter avatar Jul 16 '19 10:07 barryhunter

Hmm, thinking about this a bit more, I am not sure we want to merge this yet. When I see an array for keepCurrentZoomLevel, I'd think that this is providing the range that the zoom should be in (i.e. the target zoom level). I feel that filtering when to zoom is something that is very specific and should be done outside.

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.

domoritz avatar Jul 16 '19 11:07 domoritz

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 [13,18] then, if outside that range, it WILL zoom to that range. Its only if its already within 13->18 that it doesnt zoom. ie keep current zoom, if already within 13->18.

barryhunter avatar Jul 16 '19 12:07 barryhunter

Not quite. What I thought a range would be a is a range to clamp to. For example, if the user defines [13,18], then the zoom level would be between 13 and 18 but we might still zoom. But you are right that this isn't quite compatible with keepCurrentZoomLevel as a name, which implies that the range has something to do with keeping the zoom level. I think now I understand it better and updated the wording a bit. Now I also see that this is quite useful and so let's merge it.

Sorry, I needed a moment to understand this proposal fully.

domoritz avatar Jul 17 '19 08:07 domoritz

Could you do these two things to finish the PR?

  • [ ] Have a look at https://github.com/domoritz/leaflet-locatecontrol/pull/247#discussion_r303865857 and see whether you want to apply the suggestion.
  • [ ] Apply your refactoring to extract zoomOutsideRange as you discussed in zoomOutsideRange.

Thanks!

domoritz avatar Jul 17 '19 08:07 domoritz

So are thinking to have as a new separate 'option', as opposed to overloading keepCurrentZoomLevel. ie add 'options.zoomOutsideRange'.

Or is it just reflectoring the complicated if(..) clause that concerned about?

barryhunter avatar Jul 17 '19 09:07 barryhunter

I think keeping it part of keepCurrentZoomLevel is fine (no separate option). I am concerned about the docs (they need to be crystal clear so that others don't run into my confusions ;-)) and the complicated if clause.

domoritz avatar Jul 17 '19 21:07 domoritz