Igor-Vladyka / leaflet.motion

A simple tool to animate polylines and polygons in different way
https://igor-vladyka.github.io/leaflet.motion/
MIT License
207 stars 44 forks source link

I want to change the speed to take effect in real time. #2

Closed chentangchun closed 5 years ago

chentangchun commented 5 years ago

I want to change the speed to take effect in real time. I should how do it?

Igor-Vladyka commented 5 years ago

Speed is just Distance/Time.

We use Distance to animate line. You can write your own animation function that will calculate. Example:

L.motion.polyline([[50,0], [60,10]], {
    color: "transparent"
}, {
    auto: true,
    duration: 3000,
    easing: function(durationRatio, elapsedTime, x, y, durationTime) { return /*here we return passed duration ration (from 0 to 1) from start point based on our needed time animation function*/ durationRation*durationRation; }
})

Here our custom easing function will be called ou each line animation paint and you can handle speed anyway you want.

chentangchun commented 5 years ago

Speed is just Distance/Time.

We use Distance to animate line. You can write your own animation function that will calculate. Example:

L.motion.polyline([[50,0], [60,10]], {
  color: "transparent"
}, {
  auto: true,
  duration: 3000,
  easing: function(durationRatio, elapsedTime, x, y, durationTime) { return /*here we return passed duration ration (from 0 to 1) from start point based on our needed time animation function*/ durationRation*durationRation; }
})

Here our custom easing function will be called ou each line animation paint and you can handle speed anyway you want.

thanks

Igor-Vladyka commented 4 years ago

@chentangchun if it's still applicable, I have extended motionSpeed to work nicely on speed change during animation.