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
Snap to integer zoom level #3532
base: main
Are you sure you want to change the base?
Conversation
Thanks for taking the time to contribute! |
Thanks for the note! I'll check those :) |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3532 +/- ##
==========================================
- Coverage 86.83% 86.46% -0.37%
==========================================
Files 241 242 +1
Lines 32341 32530 +189
Branches 1962 2161 +199
==========================================
+ Hits 28082 28128 +46
- Misses 3340 3454 +114
- Partials 919 948 +29 ☔ View full report in Codecov by Sentry. |
I've done some changes to |
I don't think we can ignore the touch events without a flag that is specifying to which gestures the interger zoom applies I guess. |
OK will add hash control. For the touch event it'll take some time since it's quite complicated. |
What I meant to say is that if you decide not to implement touch handling the flag specifying the integer zoom should be something like: |
Any updates on this? |
Hey @HarelM sorry I got busy. Will try to followup on it this weekend. I'll break it into smaller pieces as you suggested. |
Hi @HarelM I've updated the example map and added a jsfiddle. Could you please check it and provide feedback? Once it looks good I'll fix the tests and docs. |
I think this direction is OK. |
Noticed that in your jsfiddle you can't zoom in. When I drag the mousewheel forward, it jumps to zoom 3.0 and you are stuck there. |
if (options === null || options === undefined) { | ||
this._snapToIntegerZoomOptions = {boxZoom: false, clickZoom: false, scrollZoom: false, tapZoom: false}; | ||
} else { | ||
this._snapToIntegerZoomOptions = options; |
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.
I think this will reset other snap options, wouldn't it? i.e. if I set scroll to true in the first call and set box to true in the second call, I'll reset scroll configuration.
Consider doing a for loop here maybe? Not sure if it's a great idea though...
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.
Or maybe consider the API to be similar to the get/should
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.
I see your point. I think replacing the entire options is more logical here because we are setting SnapToIntegerZoomOptions
instead of type: SnapToIntegerZoomType
. It's also same like other setters like style: StyleSpecification
.
Or maybe consider the API to be similar to the get/should
Something like setSnapToIntegerZoom(type: SnapToIntegerZoomType, value: boolean)
? Normally this options is set once at the map init instead of fine tune later. Using this kind of setter is not very convenient in this common case. As you would find codes like:
setSnapToIntegerZoom("boxScroll", true);
setSnapToIntegerZoom("clickScroll", true);
instead of simple setOptions({boxScrolll: true, clickScroll: true})
|
||
zoomTarget = Math.round(zoomTarget); | ||
|
||
this._map.easeTo({ |
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.
It seems like there is a explicit animation code for regular zoom, how come this can be avoided using easeTo instead of writing the animation code (using frames etc)?
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.
The explicit animation is about smoothOutEasing which doesn't have a targetZoom. The end zoom is based on an easing function which is hard to ease to an integer level. So I just skip that and use a simple easeTo
instead.
@quinncnl did you check/fix the issue reported by @sbachinin? |
I can't seem to reproduce the scenario. @sbachinin could you try again? Maybe it was before my refator to scrollZoom. |
This particular jsfiddle shows the same bad behaviour. Here's what I get when I try to zoom in: 1234.mp4 |
@sbachinin Thanks. I can reproduce it using touchpad scroll. Will check |
Hi @sbachinin I updated the demo. Could you try again? It seems we have to round the zoom at the end of inertia animation. If this is not acceptable can we have a separate toggle for it, like |
I would expect the last commit to be added with a test to make sure this is the expected behavior. |
@quinncnl, all the demos given here still demonstrate zooming problems for me. (Chrome 122.0.6261.129) |
I tried a different computer on Windows and there it jumps zoom by 2 with single scroll. Looks like I need to test with different browser/OS/scroll device(trackpad/mouse) as they have different scroll values. |
Add an option to snap to integer zoom level: #1591
Example: https://tracestrack.s3-website.nl-ams.scw.cloud/dist/
Example: https://tracestrack.s3-website.nl-ams.scw.cloud/dist/#12.40/11.7933/53.4402
jsfiddle: https://jsfiddle.net/142rftnx/1/
Launch Checklist
CHANGELOG.md
under the## main
section.