React-leaflet: How to make a moving marker like Uber cars?

Created on 25 Jun 2019  路  6Comments  路  Source: PaulLeCam/react-leaflet

I create a marker now how do I move this marker like a car on location updates?
I use states to update the position of the marker but it doesn't animate. How do I do this?

My issue is when a latlng is updated the marker jumps from one place to another but I want it to move the car animation smoothly. Have you ever tracked an Uber ride on the web? something like that.

live image

This above gif might help you understand my requirement better.

Most helpful comment

Try with https://github.com/ewoken/Leaflet.MovingMarker

I want to make it in React Js. Do you have any example in React?
It will really help me. Thanks

hi there, i have a package that supports react-leaflet out of the box, please give it a try and feedback me hehe, pacakge name:leaflet-drift-marker
you just need to pass the car icon
Edit react-leaflet_DriftMarker
leaflet-drift-marker npm
leaflet-drift-marker github

All 6 comments

Try with https://github.com/ewoken/Leaflet.MovingMarker

I want to make it in React Js. Do you have any example in React?
It will really help me. Thanks

Try with https://github.com/ewoken/Leaflet.MovingMarker

I want to make it in React Js. Do you have any example in React?
It will really help me. Thanks

hi there, i have a package that supports react-leaflet out of the box, please give it a try and feedback me hehe, pacakge name:leaflet-drift-marker
you just need to pass the car icon
Edit react-leaflet_DriftMarker
leaflet-drift-marker npm
leaflet-drift-marker github

hi all, i need help to create moving marker in anguar, i cant find an example and good packege that works in angular, any help, leaflet moving marker

i am not into angular, but you can use leaflet-drift-marker pure class( that is just pure javasvript/typescript) and use it as this:
https://github.com/hugobarragon/leaflet-drift-marker#drift_marker-with-leaflet

Thanks @hugobarragon, works like a charm 馃槉

@hugobarragon thanks a lot !

My needs were a bit more specific and I modified your code and made it compatible with https://github.com/bbecquet/Leaflet.RotatedMarker

Basically I added :
// Enhanced marker with Rotate Marker
if (props.rotationAngle !== prevProps.rotationAngle) {
marker.setRotationAngle(props.rotationAngle);
}
if (props.rotationOrigin !== prevProps.rotationOrigin) {
marker.setRotationOrigin(props.rotationOrigin);
}

Of course there are a lot to consider when using these 2 libraries, but it works for me.
For example watch out for 'rotationAngle' from 'rotateMarke'r which is 0 if undefined as props and will cause a reset of angle on component update, followed by the correct angle. => weird marker dancing on the map :))

My case was that I update car position and also the car angle to align with the road.
Typical transportation dashboard :))

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ekatzenstein picture ekatzenstein  路  4Comments

kaitlynbrown picture kaitlynbrown  路  3Comments

rolfdalhaug picture rolfdalhaug  路  3Comments

gane5h picture gane5h  路  3Comments

fborghi picture fborghi  路  3Comments