-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplanning.html
More file actions
139 lines (129 loc) · 3.58 KB
/
planning.html
File metadata and controls
139 lines (129 loc) · 3.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="icon" href="./images/favicon.ico" />
<title>规划路径 - 腾讯地图</title>
</head>
<script type="text/javascript">
window._TMapSecurityConfig = {
serviceHost: "https://static.zhangsifan.com/_TMapService",
};
</script>
<script src="https://map.qq.com/api/gljs?v=1.exp"></script>
<script src="./js/planningData.js"></script>
<style>
html,
body {
height: 100%;
margin: 0px;
padding: 0px;
overflow: hidden;
}
#mapContainer {
position: relative;
width: 100%;
height: 100%;
}
</style>
<body onload="initMap()">
<div id="mapContainer"></div>
</body>
</html>
<script>
var map;
function initMap() {
map = new TMap.Map("mapContainer", {
center: new TMap.LatLng(39.9069659960541, 116.39749745438792),
zoom: 15,
});
const control = map.getControl(TMap.constants.DEFAULT_CONTROL_ID.ZOOM);
control.setNumVisible(true);
drawPath(planningData.result.routes[0]);
}
function drawPath(routes) {
var coords = routes.polyline;
let pl = [];
//坐标解压(返回的点串坐标,通过前向差分进行压缩)
var kr = 1000000;
for (var i = 2; i < coords.length; i++) {
coords[i] = Number(coords[i - 2]) + Number(coords[i]) / kr;
}
//将解压后的坐标放入点串数组pl中
for (var i = 0; i < coords.length; i += 2) {
pl.push(new TMap.LatLng(coords[i], coords[i + 1]));
}
let geometries = [
{
id: "start",
styleId: "start",
position: pl[0],
},
{
id: "end",
styleId: "end",
position: pl[pl.length - 1],
},
];
routes.waypoints.forEach((item, index) => {
geometries.splice(index + 1, 0, {
id: "mid" + index,
styleId: "mid",
position: new TMap.LatLng(item.location.lat, item.location.lng),
});
});
var latlngBounds = new TMap.LatLngBounds();
for (var i = 0; i < pl.length; i++) {
latlngBounds.extend(pl[i]);
}
map.fitBounds(latlngBounds, {
padding: 100,
});
var polylineLayer = new TMap.MultiPolyline({
id: "polyline-layer",
map: map,
styles: {
style_blue: new TMap.PolylineStyle({
color: "#3777FF", //线填充色
width: 8, //折线宽度
borderWidth: 5, //边线宽度
borderColor: "#FFF", //边线颜色
lineCap: "round", //线端头方式
}),
},
geometries: [
{
id: "pl_1", //折线唯一标识,删除时使用
styleId: "style_blue", //绑定样式名
paths: pl,
},
],
});
var marker = new TMap.MultiMarker({
id: "marker-layer",
map: map,
styles: {
start: new TMap.MarkerStyle({
width: 29,
height: 34,
anchor: { x: 16, y: 32 },
src: "https://mapapi.qq.com/web/lbs/javascriptGL/demo/demoCenterImage/start.png",
}),
mid: new TMap.MarkerStyle({
width: 29,
height: 34,
anchor: { x: 16, y: 32 },
src: "https://mapapi.qq.com/web/lbs/javascriptGL/demo/demoCenterImage/waypoint.png",
}),
end: new TMap.MarkerStyle({
width: 29,
height: 34,
anchor: { x: 16, y: 32 },
src: "https://mapapi.qq.com/web/lbs/javascriptGL/demo/demoCenterImage/end.png",
}),
},
geometries: geometries,
});
}
</script>