guiji.html
4.9 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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>marker轨迹回放-全局模式</title>
</head>
<script charset="utf-8" src="https://map.qq.com/api/gljs?v=1.exp&key=OB4BZ-D4W3U-B7VVO-4PJWW-6TKDJ-WPB77"></script>
<style type="text/css">
html,
body {
height: 100%;
margin: 0px;
padding: 0px;
}
#container {
width: 100%;
height: 100%;
}
</style>
<body>
<div id="container"></div>
<!--引入jq--->
<script src="https://www.jq22.com/jquery/jquery-3.3.1.js"></script>
<script type="text/javascript">
let imgsrc ='{:get_root_url()}'+'/imgs/icon/shiliuzi.png';
let list = '{$list}';
let obj = $.parseJSON(list);
console.log(JSON.stringify(obj));
let path =[];
let list_length =obj.length;
if(list_length>0){
var center = new TMap.LatLng(obj[0].latitude, obj[0].longitude);
// 初始化地图
var map = new TMap.Map('container', {
zoom: 18,
center: center,
});
obj.forEach(function(item) {
path.push(new TMap.LatLng(item.latitude, item.longitude))
});
// var path = [
// new TMap.LatLng(39.98481500648338, 116.30571126937866),
// new TMap.LatLng(39.982266575222155, 116.30596876144409),
// new TMap.LatLng(39.982348784165886, 116.3111400604248),
// new TMap.LatLng(39.978813710266024, 116.3111400604248),
// new TMap.LatLng(39.978813710266024, 116.31699800491333),
// ];
console.log(path);
var polylineLayer = new TMap.MultiPolyline({
map, // 绘制到目标地图
// 折线样式定义
styles: {
style_blue: new TMap.PolylineStyle({
color: '#3777FF', // 线填充色
width: 4, // 折线宽度
borderWidth: 2, // 边线宽度
borderColor: '#FFF', // 边线颜色
lineCap: 'round', // 线端头方式
eraseColor: 'rgba(190,188,188,1)',
}),
},
geometries: [
{
id: 'erasePath',
styleId: 'style_blue',
paths: path,
},
],
});
var marker = new TMap.MultiMarker({
map,
styles: {
'car-down': new TMap.MarkerStyle({
width: 20,
height: 20,
anchor: {
x: 20,
y: 20,
},
// faceTo: 'map',
// rotate: 180,
src: imgsrc,
}),
start: new TMap.MarkerStyle({
width: 20,
height: 25,
anchor: { x: 16, y: 32 },
src: 'https://mapapi.qq.com/web/lbs/javascriptGL/demo/img/start.png',
}),
end: new TMap.MarkerStyle({
width: 20,
height: 25,
anchor: { x: 16, y: 32 },
src: 'https://mapapi.qq.com/web/lbs/javascriptGL/demo/img/end.png',
}),
},
geometries: [
{
id: 'car',
styleId: 'car-down',
position: new TMap.LatLng(obj[0].latitude, obj[0].longitude),
},
{
id: 'start',
styleId: 'start',
position: new TMap.LatLng(obj[0].latitude, obj[0].longitude),
},
{
id: 'end',
styleId: 'end',
position: new TMap.LatLng(obj[list_length-1].latitude, obj[list_length-1].longitude),
},
],
});
// 使用marker 移动接口, https://lbs.qq.com/webApi/javascriptGL/glDoc/glDocMarker
marker.moveAlong(
{
car: {
path,
speed: 250,
},
},
{
autoRotation: true,
}
);
marker.on('moving', (e) => {
var passedLatLngs = e.car && e.car.passedLatLngs;
if (passedLatLngs) {
// 使用路线擦除接口 eraseTo, https://lbs.qq.com/webApi/javascriptGL/glDoc/glDocVector
polylineLayer.eraseTo(
'erasePath',
passedLatLngs.length - 1,
passedLatLngs[passedLatLngs.length - 1]
);
}
});
}else{
$("#container").html("暂无轨迹");
}
</script>
</body>
</html>