根據(jù)官網(wǎng)的demo,小弟想到的方法是通過路書(BMapLib.LuShu)類來實(shí)現(xiàn),但是在var driving = new BMap.DrivingRoute的構(gòu)造函數(shù)中,調(diào)用driving.search,在添加途經(jīng)點(diǎn)的時(shí)候,由于該方法只支持10個(gè)途經(jīng)點(diǎn)(項(xiàng)目有成千上百個(gè)點(diǎn)),出現(xiàn)了bug。。具體問題如下:
如圖:
這樣就導(dǎo)致我的法拉利開不完全程。。。。。
附上代碼:
var map = new BMap.Map("container");
// 創(chuàng)建點(diǎn)坐標(biāo)
var point = new BMap.Point(113.184439,22.989369);
// 初始化地圖,設(shè)置中心點(diǎn)坐標(biāo)和地圖級別
map.centerAndZoom(point,13);
//啟用滾輪放大縮小,默認(rèn)禁用
map.enableScrollWheelZoom(true);
var lushu;
// alert
function showPoly(pointList){
//循環(huán)顯示點(diǎn)對象
for(let c=0;c<pointList.length;c++){
// Marker(point: Point, opts: MarkerOptions) 創(chuàng)建一個(gè)圖像標(biāo)注實(shí)例。
// point參數(shù)指定了圖像標(biāo)注所在的地理位置
console.log(c)
let marker = new BMap.Marker(pointList[c]);
// addOverlay,覆蓋物添加到地圖中,一個(gè)覆蓋物實(shí)例只能向地圖中添加一次
map.addOverlay(marker);
//將途經(jīng)點(diǎn)按順序添加到地圖上
var label = new BMap.Label(c+1,{offset:new BMap.Size(20,-10)});
marker.setLabel(label);
}
var group = Math.floor( pointList.length /11 ) ;
var mode = pointList.length %11 ;
var driving = new BMap.DrivingRoute( map, {onSearchComplete: function(res){
if (driving.getStatus() == BMAP_STATUS_SUCCESS){
var plan = res.getPlan(0);
var arrPois =[];
for(var j=0;j<plan.getNumRoutes();j++){
var route = plan.getRoute(j);
arrPois= arrPois.concat(route.getPath());
}
map.addOverlay(new BMap.Polyline(arrPois));
// map.setViewport(arrPois);
console.log(arrPois)
lushu = new BMapLib.LuShu(map,arrPois,{
defaultContent:"",//"從天安門到百度大廈"
autoView:true,//是否開啟自動視野調(diào)整,如果開啟那么路書在運(yùn)動過程中會根據(jù)視野自動調(diào)整
icon : new BMap.Icon('http://lbsyun.baidu.com/jsdemo/img/car.png', new BMap.Size(52,26),{anchor : new BMap.Size(27, 13)}),
speed: 4500,
enableRotation:true,//是否設(shè)置marker隨著道路的走向進(jìn)行旋轉(zhuǎn)
landmarkPois: [
{lng:116.314782,lat:39.913508,html:'加油站',pauseTime:2},
{lng:116.315391,lat:39.964429,html:'高速公路收費(fèi)<div><img src="http://map.baidu.com/img/logo-map.gif"/></div>',pauseTime:3},
{lng:116.381476,lat:39.974073,html:'肯德基早餐<div><img src="http://ishouji.baidu.com/resource/images/map/show_pic04.gif"/></div>',pauseTime:2}
]});
}
}});
for(let i =0;i<group;i++){
var waypoints = pointList.slice(i*11+1,(i+1)*11);
console.log(i)
//注意這里的終點(diǎn)如果是11的倍數(shù)的時(shí)候,數(shù)組可是取不到最后一位的,所以要注意終點(diǎn)-1
driving.search(pointList[i*11], pointList[(i+1)*11-1],{waypoints:waypoints});//waypoints表示途經(jīng)點(diǎn)
}
if( mode != 0){
console.log("mode!0")
var waypoints = pointList.slice(group*11,pointList.length-1);//多出的一段單獨(dú)進(jìn)行search
driving.search(pointList[group*11],pointList[pointList.length-1],{waypoints:waypoints});
}
}
var arrayList = [new BMap.Point(113.184439,22.989369),new BMap.Point(113.384222,22.947576),
new BMap.Point(113.625687,22.921482),new BMap.Point(113.625687,22.921482),
new BMap.Point(114.016055,22.83411),new BMap.Point(114.14771,22.689609),
new BMap.Point(114.338007,22.686408),new BMap.Point(114.465639,22.785605),
new BMap.Point(114.648462,22.941186),new BMap.Point(114.695605,22.99549),
new BMap.Point(114.684825,23.023166),new BMap.Point(114.665853,23.113872),
new BMap.Point(114.926002,23.04658),new BMap.Point(114.927224,23.073647),
new BMap.Point(114.964593,23.090669),new BMap.Point(114.994489,23.136671),
new BMap.Point(114.993051,23.197274),new BMap.Point(114.956832,23.295029),
new BMap.Point(114.925786,23.415),new BMap.Point(115.065491,23.496686),
new BMap.Point(115.128372,23.572294),new BMap.Point(115.006849,23.69009),
new BMap.Point(115.258662,24.106641),new BMap.Point(115.542671,24.373402)] ;
showPoly(arrayList);
$("#startLushu").on('click',function(){
console.log('啟動了')
lushu.start();
})
北大青鳥APTECH成立于1999年。依托北京大學(xué)優(yōu)質(zhì)雄厚的教育資源和背景,秉承“教育改變生活”的發(fā)展理念,致力于培養(yǎng)中國IT技能型緊缺人才,是大數(shù)據(jù)專業(yè)的國家
北大青鳥中博軟件學(xué)院創(chuàng)立于2003年,作為華東區(qū)著名互聯(lián)網(wǎng)學(xué)院和江蘇省首批服務(wù)外包人才培訓(xùn)基地,中博成功培育了近30000名軟件工程師走向高薪崗位,合作企業(yè)超4
中公教育集團(tuán)創(chuàng)建于1999年,經(jīng)過二十年潛心發(fā)展,已由一家北大畢業(yè)生自主創(chuàng)業(yè)的信息技術(shù)與教育服務(wù)機(jī)構(gòu),發(fā)展為教育服務(wù)業(yè)的綜合性企業(yè)集團(tuán),成為集合面授教學(xué)培訓(xùn)、網(wǎng)
達(dá)內(nèi)教育集團(tuán)成立于2002年,是一家由留學(xué)海歸創(chuàng)辦的高端職業(yè)教育培訓(xùn)機(jī)構(gòu),是中國一站式人才培養(yǎng)平臺、一站式人才輸送平臺。2014年4月3日在美國成功上市,融資1
浪潮集團(tuán)項(xiàng)目經(jīng)理。精通Java與.NET 技術(shù), 熟練的跨平臺面向?qū)ο箝_發(fā)經(jīng)驗(yàn),技術(shù)功底深厚。 授課風(fēng)格 授課風(fēng)格清新自然、條理清晰、主次分明、重點(diǎn)難點(diǎn)突出、引人入勝。
曾工作于聯(lián)想擔(dān)任系統(tǒng)開發(fā)工程師,曾在博彥科技股份有限公司擔(dān)任項(xiàng)目經(jīng)理從事移動互聯(lián)網(wǎng)管理及研發(fā)工作,曾創(chuàng)辦藍(lán)懿科技有限責(zé)任公司從事總經(jīng)理職務(wù)負(fù)責(zé)iOS教學(xué)及管理工作。
精通HTML5和CSS3;Javascript及主流js庫,具有快速界面開發(fā)的能力,對瀏覽器兼容性、前端性能優(yōu)化等有深入理解。精通網(wǎng)頁制作和網(wǎng)頁游戲開發(fā)。
具有10 年的Java 企業(yè)應(yīng)用開發(fā)經(jīng)驗(yàn)。曾經(jīng)歷任德國Software AG 技術(shù)顧問,美國Dachieve 系統(tǒng)架構(gòu)師,美國AngelEngineers Inc. 系統(tǒng)架構(gòu)師。