//o是我所有點的一個集合
var map = new BMap.Map('allmap');
map.enableScrollWheelZoom();
var point = new BMap.Point(o[0].LNG, o[0].LAT);
map.centerAndZoom(point, 13);
var array = [];//所有點位置
for (var i = 0; i < o.length; i++) {
array.push(new BMap.Point(o[i].LNG, o[i].LAT));
}
var lushu;
// 實例化一個駕車導航用來生成路線
var drv = new BMap.DrivingRoute(point, {
onSearchComplete: function (res) {
if (drv.getStatus() == BMAP_STATUS_SUCCESS) {
var plan = res.getPlan(0);
map.addOverlay(new BMap.Polyline(array, { strokeColor: '#111' }));
map.setViewport(array);
lushu = new BMapLib.LuShu(map, array, {
defaultContent: "",
autoView: true,//是否開啓自動視野調整,如果開啓那麼路書在運動過程中會根據視野自動調整
icon: new BMap.Icon('/Content/Map/imgs/ship.png', new BMap.Size(48, 48), { anchor: new BMap.Size(27, 13) }),
speed: 5000,//覆蓋物移動速度
enableRotation: false,//是否設置marker隨着道路的走向進行旋轉
landmarkPois: [
{ lng: 0, lat: 0, html: '', pauseTime: 2 },//必須寫入該參數,否則js會報錯,第二次不能執行
]
});
}
}
});
var endPoint = new BMap.Point(o[o.length - 1].LNG, o[o.length - 1].LAT);
drv.search(point, endPoint);//開始點,結束點
//開始運動事件
$("#run").click(function () {
lushu.start();
});
詳情查看:http://lbsyun.baidu.com/jsdemo.htm#c2_8
http://api.map.baidu.com/library/LuShu/1.2/docs/symbols/BMapLib.LuShu.html