console
var map = new AMap.Map('container', {
zoom: 4
});
AMapUI.load(['ui/misc/PathSimplifier', 'lib/$'], function(PathSimplifier, $) {
if (!PathSimplifier.supportCanvas) {
alert('当前环境不支持 Canvas!');
return;
}
var pathSimplifierIns = new PathSimplifier({
zIndex: 100,
//autoSetFitView:false,
map: map, //所属的地图实例
getPath: function(pathData, pathIndex) {
return pathData.path;
},
getHoverTitle: function(pathData, pathIndex, pointIndex) {
if (pointIndex >= 0) {
//point
return pathData.name + ',点:' + pointIndex + '/' + pathData.path.length;
}
return pathData.name + ',点数量' + pathData.path.length;
},
renderOptions: {
renderAllPointsIfNumberBelow: 100 //绘制路线节点,如不需要可设置为-1
}
});
window.pathSimplifierIns = pathSimplifierIns;
//设置数据
pathSimplifierIns.setData([{
name: '路线0',
path: [
[116.3548, 40.0418],
[116.3454, 40.1042],
[116.3536, 40.1506],
[116.3024, 40.2212],
[116.1, 40.2236],
[115.5612, 40.1654],
[115.4724, 40.1336],
[115.293, 40.0648],
[115.1018, 40.0648],
[114.3, 40.063],
[113.5536, 38.403],
[113.0454, 38.05],
[112.3524, 37.523],
[112.2106, 37.463],
[110.3818, 37.0242],
[109.3806, 36.4112],
[109.0824, 35.5048],
[108.423, 34.4524],
[108.3748, 34.3048],
[108.3006, 34.0636],
[108.0518, 33.2448],
[107.4612, 32.103],
[107.233, 31.2218],
[107.0406, 30.5136],
[106.5806, 30.4206],
[106.483, 30.2212],
[106.4518, 30.1712],
[106.5618, 30.1124],
[107.0348, 30.0724],
[107.0012, 29.5712],
[106.5754, 29.5042],
[106.5536, 29.4412],
[106.4724, 29.4624],
[106.4942, 29.5254],
[106.5154, 29.5924],
[106.383, 29.4306],
]
}]);
//对第一条线路(即索引 0)创建一个巡航器
var navg1 = pathSimplifierIns.createPathNavigator(0, {
loop: true, //循环播放
speed: 1000000 //巡航速度,单位千米/小时
});
navg1.start();
});
<div id="container"></div>
<script type="text/javascript" src='//webapi.amap.com/maps?v=1.3&key=71477380fc31e5291f93952b10091bf6&plugin=AMap.Driving'></script>
<script src="//webapi.amap.com/ui/1.0/main.js?v=1.0.10"></script>
html,
body,
#container {
width: 100%;
height: 100%;
margin: 0px;
}