我是mapbox新手
我从csv文件导入了一些标记,我可以手动在它们之间画线,从每个端口到它的目的地。例如,从摩洛哥到中国,但如果我给你看我的地图,你不知道港口在哪里,目的地是什么:从摩洛哥到中国,或者相反。因此,出于这个原因,我想绘制一条从每个端口到其目的地的动画线。
目前我没有任何代码,我在下面的链接中找到了如何绘制动画线条,但我不能在标记之间绘制,因为它们谈论的是正弦函数。
https://www.mapbox.com/mapbox.js/example/v1.0.0/dynamically-drawing-a-line/,你能帮帮我吗?
谢谢!
发布于 2015-10-08 19:17:36
在您链接的示例中,可以将add()
函数更改为从第一个点开始绘制,在最后一个点停止绘制。理想情况下,您的标记应按您希望绘制线条的顺序排列:
// add your points
var points = [
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [0, 0]
},
"properties": {}
},
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [10, -10]
},
"properties": {}
},
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [50, 50]
},
"properties": {}
}
]
// add a variable for keeping track of points
var y = 0;
// Start drawing the polyline.
add();
function add() {
// add a point on the line for the new marker
polyline.addLatLng(
L.latLng(points[y].geometry.coordinates[1],
points[y].geometry.coordinates[0])
);
// Pan the map along with where the line is being added.
map.setView(points[y].geometry.coordinates, 3);
// Continue to draw and pan the map by calling `add()`
// until `y` reaches the number of points
if (++y < points.length) window.setTimeout(add, 1000);
}
https://stackoverflow.com/questions/32989730
复制