Skip to content
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

Animated setBearing #63

Open
mattiasbe opened this issue Nov 25, 2024 · 1 comment
Open

Animated setBearing #63

mattiasbe opened this issue Nov 25, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@mattiasbe
Copy link

Feature request.
Thanks for the excellent work with the lib and the work maintaining it!

Would love it if setBearing would accept something similar to the regular setView() for animating the update (zoom/pan options contain an animate: true). Example for setView:
map.setView(pos, zoomLevel, {animate: true, duration: 2.0, easeLinearity: 0.25});

Suggest a similar api for setBearing as well
map.setBearing(-heading, {animate: true, duration: 2.0, easeLinearity: 0.25});

or preferably a new setView variant with bearing (and animate options):
map.setBearingView(pos, zoomLevel, -heading, {animate: true, duration: 2.0, easeLinearity: 0.25});

But...

Would love it even more if it could be combined with setView and others (panBy comes to mind) for one smooth update. Or some other way of combining an animated update, but that is missing in leaflet itself I guess?

My use case is updating map on every gps position update (once every second). Moving map and a vehicle marker with animations makes it very smooth, but rotating the map in the heading direction is very sudden and almost disorienting at times.

So currently if I want to set rotation and updating map position it can't(?) be done in one animation anyway:

map.setBearing(-heading);
map.setView(pos, zoomLevel, {animate: true, duration: 2.0, easeLinearity: 0.25});

Will (too) quickly rotate the map and then after that the map will move smoothly animated. So hence the second api suggestion above.

Adding further to the use case is that it would be preferable if we saw more ahead of us than behind so off-setting it a bit with panBy() is already show casing the same problem, can't (?) start two animated movements with leaflet so have to do without the nice smooth animated updates, like this:

map.setBearing(-heading);
map.setView(pos, zoomLevel, {animate: false});
const offsetY = mapDiv.clientHeight/4
map.panBy([0, -offsetY], {animate: false});

Would there be any way to have multiple such map state changes animated as one? An update(), commit(). The vehicle marker itself is fine because can update separately by itself, not part of map state (zoom, center etc). Or new calls adding to existing animation if not overlapping params..
I've found the https://leafletjs.com/reference.html#posanimation L.PosAnimation and somethign similar for the map itself woudl be useful but that is more of a leaflet issue.

Any ideas or input appreciated.

@Raruto Raruto added the enhancement New feature or request label Nov 26, 2024
@lwg5201314
Copy link

map.setBearing(0) 为什么没有恢复到正北位置啊?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants