最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to animate a custom Leaflet marker along a route? - Stack Overflow

programmeradmin0浏览0评论

I am very much new to leaflet and i hope that someone can help me. What im trying to do is adding two markers on the map and make another marker follow the route.

I have found a few plugins that would help but these plugins makes your marker over the map and not follow a specific route. .MovingMarker/

I know how it is done in google maps but not in leaflet.

I am very much new to leaflet and i hope that someone can help me. What im trying to do is adding two markers on the map and make another marker follow the route.

I have found a few plugins that would help but these plugins makes your marker over the map and not follow a specific route. http://ewoken.github.io/Leaflet.MovingMarker/

I know how it is done in google maps but not in leaflet. https://www.youtube./watch?v=zbr-F9wVqgU

Share Improve this question asked Mar 23, 2017 at 12:29 Wim PruiksmaWim Pruiksma 5981 gold badge5 silver badges19 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

You are close. You choosed the Leaflet plugin and have quite a precise goal. You just have to follow what is explained here.

Let's implement that :

// here is the path (get it from where you want)
var coordinateArray = [ [0,1], [1,1], [1,0] ];
// or for example
var coordinateArray = existingPolyline.getLatLngs();
// here is the line you draw (if you want to see the animated marker path on the map)
var myPolyline = L.polyline(coordinateArray);
myPolyline.addTo(map);
// i don't know if i understood your question correctly
// if you want to put a marker at the beginning and at the end of the path :
var mstart = L.marker(coordinateArray[0]).addTo(map);
var mend = L.marker(coordinateArray[coordinateArray.length - 1]).addTo(map);
// here is the moving marker (6 seconds animation)
var myMovingMarker = L.Marker.movingMarker(coordinateArray, 6000, {
    autostart: false
});
map.addLayer(myMovingMarker);
myMovingMarker.start();
发布评论

评论列表(0)

  1. 暂无评论