百度地圖多點路徑載入以及調整頁面js

來源:互聯網
上載者:User

標籤:style   blog   color   io   art   cti   ar   div   

 1 $(document).ready(function () { 2 /*用Regex擷取url傳遞的地址參數,split後獲得地址數組*/ 3 bmap = new BMap.Map(‘mapcontainer‘); 4 var point = new BMap.Point(116.404, 39.915);//地圖中心點 5 bmap.centerAndZoom(point, 15);//調整縮放以及設立中心點 6 bmap.enableScrollWheelZoom(); 7 var locations = ["天安門", "北京郵電大學", "地壇公園", "北京師範大學"]; 8 var i = 0; 9 var points=[];//儲存目標點用於調整viewport10 var driving = new BMap.DrivingRoute(bmap, {11 policy : BMAP_DRIVING_POLICY_LEAST_TIME,12 onSearchComplete : function (results) {13 console.log(i);14 var path = results.getPlan(0).getRoute(0).getPath();15 var pathpoly = new BMap.Polyline(path, {16 strokeColor : "blue",17 strokeWeight : 6,18 strokeOpacity : 0.519 });20 if (i === 0) {21 console.log(‘起點‘ + results.getStart());22 var start = new BMap.Marker(results.getStart().point);23 start.setTitle(‘起點:‘ + results.getStart().title);24 bmap.addOverlay(start);25 points.push(results.getStart().point);26 }27 var marker = new BMap.Marker(results.getEnd().point);28 points.push(results.getEnd().point);29 marker.setTitle(‘經過點‘ + (i + 1) + ‘:‘ + results.getEnd().title);30 bmap.addOverlay(pathpoly);31 bmap.addOverlay(marker);32 i++;33 if (i < locations.length - 1) {34 setTimeout(driving.search(locations[i], locations[i + 1]), 10000);//調用後面的路徑
35 }
36 bmap.setViewport(points); 37 } 38 }); 39 driving.search(locations[0], locations[1]);//調用第一條路徑
40 });

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.