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

Animated `setBearing`

Open mattiasbe opened this issue 1 year ago • 9 comments

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 something similar for the map itself would be useful but that is more of a leaflet issue.

Any ideas or input appreciated.

mattiasbe avatar Nov 25 '24 17:11 mattiasbe

Why doesn't map.setBearing(0) restore to true north?

lwg5201314 avatar Dec 16 '24 06:12 lwg5201314

You might be interested in some work done on https://github.com/kalisio/leaflet-rotate and the way we create a smooth animation using it in https://github.com/kalisio/kdk/issues/1173. We have a pretty similar use case than you have to create a GPS-like application with an off-centered marker so that rotation should also occur off-centered as well at the marker position. As a consequence we also added support for a screen-space a offset. We found easier to rely on our own method to set map center/zoom/bearing without animation used by our own animation system instead of relying on smaller animated parts in Leaflet and plugins that we should synchronize.

Let me know if it helps.

claustres avatar Apr 11 '25 17:04 claustres

Hi @claustres,

You might be interested in some work done on https://github.com/kalisio/leaflet-rotate

thanks for the info.

Forked from Raruto/leaflet-rotate as it does not seem to be maitaind anymore.

Forgive me the rant, but this is not "abandoned", there aren't so many frequent commits in here because:

  1. (overall) it's a fairly stable plugin (with some minor glitches, whoever can do better is always welcome)
  2. no one else is really interested in actively contributing (ref: https://github.com/Raruto/leaflet-rotate/issues/64)
  3. new features/bugfixes would also require writing some tests (this plugins adds heavy changes to the leaflet core, it's not enough to say here's a new PR, eg: https://github.com/Raruto/leaflet-rotate/pull/48#issuecomment-1976533749)
  4. many users like to report problems related to external plugins (or their own code that they don't know how to integrate, eg: https://github.com/Raruto/leaflet-rotate/issues/66..)
  5. Last but not least, this feature is often used by tech companies, which rarely contribute to open source projects (and even fewer follows the GPL license, and no the problem it's not the overly restrictive licensing, it's just the modern AI people..).

Anyway, I don't consider myself a benevolent dictator for this project.

Anyone is welcome if it can spend more than 5 minutes of their life to this stuff, but lately nobody seems willing to discuss, everyone just wants to develop: «Harder, Better, Faster, Stronger»...

👋 Raruto

Raruto avatar Apr 14 '25 09:04 Raruto

Hi @Raruto and thanks for your plugin and feedback. What lead us to "not maintained anymore" was actually https://github.com/Raruto/leaflet-rotate/issues/64 and the fact le latest PRs were not merged but I agree the plugin is fairly stable so it might not need a lot more, we will remove this from our README.

However, as you probably know, becoming new maitainers on a project is not as simple as spending 5 minutes on the stuff, we don't like to start to do things that we would be not able to sustain in the long term as it would be counterproductive for the community. We have tried to understand some parts of the code to fix some issues we faced or improve our usage but we are not familiar enough to become maintainers yet, so the fork. We have already a lot of open source modules to maintain and I don't know if in the future we might take part of yours but we can create new PRs with some of our updates if you'd like, not yet sure if always relevent with the current open PRs.

About licensing, I am not a lawyer but the main point is probably how tied to Leaflet the plugin is. As it does not provide a kind of general "monkey-patching" mechanism that could be applied to any library it's deeply tied to Leaflet so chances are it should be considered as a modification of it, and in this case its licence should probably apply. But maybe you can also separate the "monkey-patching" parts and the more "plugin" parts (in the common sense of adding features to a software without modifying it internally) to use another licence.

Let me know what you think.

claustres avatar Apr 14 '25 10:04 claustres

Just a few clarifications (I don't want to go too much "off-topic" or get boring):

  • #64 says https://github.com/Raruto/leaflet-rotate/issues/64 not maintainers

  • this is a plugin like others (ie. nothing special here, no need to compile it differently), the "monkey-patch" term is only used to explain the coding pattern applied overall (based on: Extending Leaflet: Class Theory), as in the following three lines:

    • https://github.com/Raruto/leaflet-rotate/blob/4e75db11385149de688c77fb3d57a24a67aec2ee/src/map/Map.js#L7
    • https://github.com/Raruto/leaflet-rotate/blob/4e75db11385149de688c77fb3d57a24a67aec2ee/src/map/Map.js#L11
    • https://github.com/Raruto/leaflet-rotate/blob/4e75db11385149de688c77fb3d57a24a67aec2ee/src/map/Map.js#L22
  • It's been more than 10 years since https://github.com/Leaflet/Leaflet/issues/268 and in the end (just with passion, without any financial support) the only one who managed to create a truly reusable plugin is me.

  • we could spend hours arguing about licenses..

Essentially, anyone interested in seeing this feature properly "supported" (seriously, not just as a hobby), should really start thinking about:

  1. sponsoring it within core or switch to an alternative library which already ships "rotational" transformations.
  2. try to figure out how to write some tests before changing anything else in here (eg: examples/leaflet-rotate.spec.js)

Again, I know I'm being pedantic (and maybe some would like to see more "frequent" updates) but in here we're dealing with really complicated math stuff (even for core developers, there is a reason why mapbox came later leaflet, and then maplibre, gleo, ..).

Now I've gotten to a certain point (in an well-engineered way), now others.


As usual, PR are always welcome ❤

Raruto avatar Apr 14 '25 11:04 Raruto

For sure we did not yet studied how to create tests for the library so that creating a PR just to say we've created a PR does not make sense IMHO. Also a lot of people are progressively shifting to maplibre, as you said things here are complex, notably because not really architectured with that feature in mind upfront in Leaflet, so not sure if the effort is worth it.

claustres avatar Apr 14 '25 12:04 claustres

I'm not blaming you. (just to be clear, once again, about who's coming next)

not sure if the effort is worth it.

This is the reasoning of many (ref: the issues): not my business (not much true), no funds to dedicate

When Leaflet was born Open Layers were enough for the "businessman folks" (but then Volodymyr / Ivan proved them wrong..., simplicity and ease of use 🥬).

So get involved, if you care about future compatibility..

Raruto avatar Apr 17 '25 08:04 Raruto

Thank you. All is perfect for open source plugin. I want just note about it.

VlasovAlexey avatar Apr 17 '25 09:04 VlasovAlexey

No problem @Raruto I agree with most of your words, I know the problems of having contributors when trying to maintain open source projects. Simply for now we are not involved enough in the project code to create good PRs and we are as well too much focused on our own use case. Will try to have a look at the test part in the future.

claustres avatar Apr 17 '25 09:04 claustres