admin 管理员组文章数量: 1086019
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 badges1 Answer
Reset to default 6You 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();
本文标签: javascriptHow to animate a custom Leaflet marker along a routeStack Overflow
版权声明:本文标题:javascript - How to animate a custom Leaflet marker along a route? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://roclinux.cn/p/1743998309a2515981.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论