如何沿路线对自定义传单标记进行动画处理



我对传单很陌生,希望有人能帮助我。我试图做的是在地图上添加两个标记,并使另一个标记沿着路线。

我找到了一些会有所帮助的插件,但这些插件会在地图上做标记,而不是遵循特定的路线。http://ewoken.github.io/Leaflet.MovingMarker/

我知道它是如何在谷歌地图中完成的,但在传单中却不知道。https://www.youtube.com/watch?v=zbr-F9wVqgU

你很接近。您选择了传单插件,并且有一个非常精确的目标。您只需要遵循此处解释的内容即可。

让我们实现它:

// 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();

最新更新