Skip to content

Animate a styled line #177

Answered by dimfeld
Ducktatorrr asked this question in Q&A
Jun 13, 2024 · 1 comments · 1 reply
Discussion options

You must be logged in to vote

I’ve done it in a non-open-source project as part of some contract work and it works great. Basically you do what’s in this Mapbox example, just with Svelte components instead of mapbox for the sources/layers/etc: https://docs.mapbox.com/mapbox-gl-js/example/animate-ant-path/

Then instead of calling setPaintProperty you update the paint property on the relevant LineLayer component instead.

Oh and make sure you have some way to detect when to stop calling requestAnimationFrame. That demo doesn't bother since it runs forever but you'll want to make sure that you stop calling it once the page is torn down. Something like this will work if you don't have some other interlock:

let active = true;

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@Ducktatorrr
Comment options

Answer selected by Ducktatorrr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants