设置标记之间多段线的动画-Mapbox
Animating polylines between markers - Mapbox
我有以下代码来绘制点之间的标记和多段线。当用户更改页面上的选择时,它会运行此脚本。
$.post('_posts/get-pins.php', {traveller: $(this).val()}, function(data){
// Create empty featureLayer
var featureLayer = L.mapbox.featureLayer().addTo(map);
// Create empty featureCollection
var featureCollection = {
"type": "FeatureCollection",
"features": []
};
var lineArray = [];
$.each(data, function (k, item) {
// Create new feature object and push to featureCollection
featureCollection.features.push({
"type": "Feature",
"properties": {
"id": item.id,
"title": item.title,
"description": item.description,
"image": item.image,
"marker-symbol": "star",
"marker-color": "#ff8888",
"marker-size": "large"
},
"geometry": {
"type": "Point",
"coordinates": [
item.long,
item.lat
]
}
});
lineArray[item.id] = [item.lat, item.long];
});
featureLayer.setGeoJSON(featureCollection);
lineArray = lineArray.filter(function(){return true});
var polyline = L.polyline(lineArray).addTo(map);
},'json');
我在地图框示例中找到了以下示例。https://www.mapbox.com/mapbox.js/example/v1.0.0/dynamically-drawing-a-line/我想知道这种动画在画简单的线时是否可行,如果可以的话,如何做到。
而不是将整个lineArray
添加到安装L.polyline
:
var polyline = L.polyline(lineArray).addTo(map);
添加一个空数组,然后创建一个函数,逐个添加数组中的点。代码中,注释中有解释:
// New polyline with empty array
var polyline = L.polyline([]).addTo(map);
// Set iterator to 0
var iteration = 0;
// Function for adding lines
function addLine () {
// Add first point from the line array
polyline.addLatLng(lineArray[iteration]);
// Set the view to the same point
map.setView(lineArray[iteration], 3);
// As long as there are points in the array,
// Update the iterator and execute this function every 500 ms
if (++iteration < lineArray.length) window.setTimeout(addLine, 500);
}
// Execute the function
addLine();
Plunker的工作示例:http://plnkr.co/edit/8tO7P2bFd6ycWllfllZM?p=preview
相关文章:
- 如何设置html元素填充的动画
- 如何使用动画实现纸张推车
- 如何在生成下载文件时显示加载动画
- 剑道网格jQuery动画()问题
- EaseJS拖放;放下(动画CC)电影剪辑的鼠标坐标
- jQuery Lazy加载动画滚动
- jquery动画可以通过编程链接吗
- Javascript将数学动画化
- 动画.CSS重播
- 制作一个不带HTML a标记但在动画播放完毕后指向其他页面的超链接
- 如何使用jQuery在动画中期加速动画
- 使用数据上的角度更改设置集合的第一个元素的动画
- 如何使用css动画/javascript使具有背景图像的元素出现
- 如何使用css动画从中心增加边界线
- JQuery动画延长容器不起作用
- 动画CSS进度条
- JavaScript动画从不执行
- 更多延迟动画
- 使用jQuery制作伪元素的动画
- 设置标记之间多段线的动画-Mapbox