according to the demo, boy on the official website, the method is implemented through the BMapLib.LuShu class, but in the constructor of var driving = new BMap.DrivingRoute, when calling driving.search, to add pass points, because this method only supports 10 pass points (there are hundreds of points in the project), bug appears. No, no, no. The specific problems are as follows:
as shown in the figure:
this leads to the failure of my Ferrari to complete the journey.
attach code:
var map = new BMap.Map("container");
//
var point = new BMap.Point(113.184439,22.989369);
//
map.centerAndZoom(point,13);
//
map.enableScrollWheelZoom(true);
var lushu;
// alert
function showPoly(pointList){
//
for(let c=0;c<pointList.length;cPP){
// Marker(point: Point, opts: MarkerOptions)
// point
console.log(c)
let marker = new BMap.Marker(pointList[c]);
// addOverlay,
map.addOverlay(marker);
//
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();jPP){
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,//
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,//marker
landmarkPois: [
{lng:116.314782,lat:39.913508,html:"",pauseTime:2},
{lng:116.315391,lat:39.964429,html:"<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;iPP){
var waypoints = pointList.slice(i*11+1,(i+1)*11);
console.log(i)
//11-1
driving.search(pointList[i*11], pointList[(i+1)*11-1],{waypoints:waypoints});//waypoints
}
if( mode != 0){
console.log("mode!0")
var waypoints = pointList.slice(group*11,pointList.length-1);//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);
$("-sharpstartLushu").on("click",function(){
console.log("")
lushu.start();
})