hosuaby / Leaflet.SmoothMarkerBouncing

Smooth animation of marker bouncing for Leaflet.
BSD 2-Clause "Simplified" License
146 stars 28 forks source link

Instant stop #52

Closed timothyarmes closed 1 month ago

timothyarmes commented 1 year ago

It would be really useful to have a way to instantly stop bouncing, rather than wait till the end of the current animation

timothyarmes commented 1 year ago

I have a work around, but a proper option would be nice.

(if (markerRef.current.isBouncing()) {
  // @ts-ignore
  markerRef.current.stopBouncing();

  // The plugin keeps bouncing until the end of the animation.  We want to stop it immediately
  // An issue has been raised on the project (https://github.com/hosuaby/Leaflet.SmoothMarkerBouncing/issues/52), until then we have this hack.
  // We remove the class and reset some internal state
  // @ts-ignore
  DomUtil.removeClass(markerRef.current._icon, "bouncing");

  if (
    // @ts-ignore
    markerRef.current?._bouncingMotion?.bouncingAnimationPlaying === true
  )
    // @ts-ignore
    markerRef.current._bouncingMotion.bouncingAnimationPlaying = false;
})
hosuaby commented 1 year ago

Hello @timothyarmes

Thanks for enhancement proposal. I think, the proper solution would be to add flag immediate in the arguments of method marker.stopBouncing() and introduce option stopImmediately into options of bouncing.

I find your proposal interesting. I will take care of it when I will have some free time. If you need it fast, feel free to make a PR and I will review.

hosuaby commented 1 month ago

Will be availbale in version 3.1.0