Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draw polyline #15

Open
tech4bot opened this issue Apr 15, 2016 · 2 comments
Open

Draw polyline #15

tech4bot opened this issue Apr 15, 2016 · 2 comments

Comments

@tech4bot
Copy link

Hello,

Is there a easy way to draw a polyline while the marker is moving? To let behind the polyline, not to move over an existing polyline.

Thank you!

@wahisoufiane
Copy link

Use SnakeAnim plugin for leaflet

@julien-nc
Copy link

But the SnakeAnim plugin is hard to combine with MovingMarker because the way they define the speed is quite different. SnakeAnim speed is in pixel per second, which means if you zoom, the animation duration changes (not so great). I prefer MovingMarker's way. Animation duration is set and zoom events are not problematic.

After exploring a lot of complicated possibilities to draw a polyline progressively following the marker, i realized i just needed a "move" event from the marker. Here is a modified version of MovingMarker.js which fires this event. Then it looks like this :

var snakeLine, marker;
function updateSnakeLine(e) {
    var ll = e.target.getLatLng();
    snakeLine.addLatLng(ll);
}
// suppose we already have the pathLine polyline
snakeLine = L.polyline([]).addTo(map);
marker = L.Marker.movingMarker(pathLine.getLatLngs(), 10000).addTo(map);
marker.on('move', updateSnakeLine);
marker.start();

The snakeLine is drawn at the exact same time the marker moves.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants