admin 发表于 2021-4-19 21:38:01

【行车路径规划】百度地图API,行车路径规划 起始点 途经点





<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<style type="text/css">
body, html,#allmap {width: 100%;height: 100%;overflow: hidden;margin:0;font-family:"微软雅黑";}
</style>
<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=eYf9sA6yVTFHlh9ytU4a0EYY"></script>
<title>设置驾车路线途经点</title>
</head>
<body>
<div id="allmap"></div>
</body>
</html>
<script type="text/javascript">

// 百度地图API功能
var map = new BMap.Map("allmap");
map.centerAndZoom(new BMap.Point(116.404, 39.915), 11);
map.enableScrollWheelZoom(true);

//起始点
var p1 = new BMap.Point(116.301934,39.977552);
var p2 = new BMap.Point(116.508328,39.919141);
//途经点
var p3 = new BMap.Point(116.405628,39.9139721);//天安门
var p4 = new BMap.Point(116.455646,39.937433);//体育馆

//行车路线规划实例
var driving = new BMap.DrivingRoute(map, { renderOptions:{ map: map, autoViewport: true}       ,onPolylinesSet:function(Route){
//当线条添加完成时调用
for(var i=0;i<Route.length;i++){
          var polyline = Route.getPolyline();//获取线条遮挡物
                  polyline.setStrokeColor("#38CA69");//设置颜色
                polyline.setStrokeWeight(5);//设置宽度
                polyline.setStrokeOpacity(1);//设置透明度
}
console.log(Route);
},onMarkersSet:function(routes) {
//当地图标记添加完成时调用
      for (var i = 0; i <routes.length; i++) {
                //判断是否是途经点
                if(typeof(routes.Km)=="undefined"){
                        map.removeOverlay(routes.marker); //删除起始默认图标
                }else{
                        map.removeOverlay(routes.Km); //删除途经默认图标
                }
      }
    }
});

driving.enableAutoViewport();//自动调整层级

//自定义起点图标
var m = new BMap.Marker(p1);
m.setIcon(new BMap.Icon('http://demo.dingwei.cn/xingfou/public/Home/img/icon_21-25.png',new BMap.Size(20, 26),{anchor: new BMap.Size(10, 26)}));
map.addOverlay(m);
   //自定义终点图标
    var m = new BMap.Marker(p2);
m.setIcon(new BMap.Icon('http://demo.dingwei.cn/xingfou/public/Home/img/icon_21-25.png',new BMap.Size(20, 26),{anchor: new BMap.Size(10, 26)}));
map.addOverlay(m);
   //自定义途经图标
    var m = new BMap.Marker(p3);
m.setIcon(new BMap.Icon('http://demo.dingwei.cn/xingfou/public/Home/img/icon_21-25.png',new BMap.Size(20, 26),{anchor: new BMap.Size(10, 26)}));
map.addOverlay(m);
   //自定义途经图标
    var m = new BMap.Marker(p4);
m.setIcon(new BMap.Icon('http://demo.dingwei.cn/xingfou/public/Home/img/icon_21-25.png',new BMap.Size(20, 26),{
anchor: new BMap.Size(10, 26)//这是图标的偏移量,一般x设置为 图片宽度一半,高度想等,就正确了
   
}));
map.addOverlay(m);

driving.search(p1, p2,{waypoints:});//waypoints表示途经点

            // driving.setPolylinesSetCallback(result => {
            // 清除路线规划 重新设置路线颜色
            // driving.clearResults();
            // const points = [];
            // result.Oq.forEach(item => {
            //   points.push(new window.BMap.Point(item.lng, item.lat));
            // });
            // const polyline = new window.BMap.Polyline(points, {
            //   strokeColor: '#6BC600',
            //   strokeWeight: 3,
            //   strokeOpacity: 0.8,
            // });
            // 创建折线
            // map.addOverlay(polyline);
            // });

            // 起点终点重新添加图标
            // const startIcon = new window.BMap.Icon(
            //   require('../../../public/start.png'),
            //   new window.BMap.Size(30, 120),
            //   { anchor: new BMap.Size(10, 25) }
            // );
            // const endIcon = new window.BMap.Icon(
            //   require('../../../public/start.png'),
            //   new window.BMap.Size(30, 120),
            //   { anchor: new window.BMap.Size(10, 25) }
            // );

            // driving.setMarkersSetCallback(result => {
            //   result.marker.setIcon(startIcon);
            //   result.marker.setIcon(endIcon);
            // });

            // 搜索成功后得回调
            // driving.setSearchCompleteCallback(() => {
            // 通过驾车实例,获得一系列点的数组
            // const pts = driving
            //   .getResults()
            //   .getPlan(0)
            //   .getRoute(0)
            //   .getPath();
            // const polyline = new window.BMap.Polyline(pts);
            // map.addOverlay(polyline);
            // });

</script>

Dennisfem 发表于 2025-3-3 23:05:25

How to start winning

Try reading this - https://ivfrankivsk.if.ua/
Maybe it will help you

Anya109Ei 发表于 2025-4-29 16:03:26

Great reading too 109 !

Hello folks!
I came across a 109 very cool site that I think you should check out.
This site is packed with a lot of useful information that you might find helpful.
It has everything you could possibly need, so be sure to give it a visit!
https://conversationswithbianca.com/wagering-on-reality-television-programs-tactics-and-results/

Arisha20Ei 发表于 2025-8-25 16:09:14

Great reading too 20 !

Hello colleagues
Hello. A 20 nice site 1 that I found on the Internet.
Check out this site. There's a great article there. <a href=https://gigapanbot.de/casino-spiele/casino-design-und-architektur-der-erste-eindruck-zahlt/>https://enkolpion.org/kasyna-online/naduzycia-po-stronie-nielicencjonowanych-kasyn-internetowych-i-jak-sie-przed-nimi-bronic/</a>|

There is sure to be a lot of useful and interesting information for you here.
You'll find everything you need and more. Feel free to follow the link below.

Cavirosaovato 发表于 2026-3-16 10:34:56

ВИРТА - надежное казино для игры онлайн

Anya109Ei ??? 2025-4-29 16:03
Hello folks!
I came across a 109 very cool site that I think you should check out.
This site is pa ...

Если посмотреть на опыт игроков, становится заметно, что большинство проблем возникает именно на неизвестных площадках. Проверенные казино дорожат своей репутацией и стараются избегать конфликтов с пользователями. Поэтому игроки всё чаще советуют выбирать платформы с историей и хорошими отзывами. В таких рекомендациях нередко предлагают играть в казино на деньги именно в проверенных казино.
页: [1]
查看完整版本: 【行车路径规划】百度地图API,行车路径规划 起始点 途经点