-
Notifications
You must be signed in to change notification settings - Fork 7
/
index.html
196 lines (179 loc) · 4.5 KB
/
index.html
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style>
html,
body,
#map {
height: 90%;
width: 100%;
margin: 0;
}
</style>
<script type="text/javascript" src="./js/jquery.js"></script>
<script type="text/javascript" src="./js/init_Data.js"></script>
<script type="text/javascript" src="./js/custom_Lushu.js"></script>
<script type="text/javascript" src="http://api.map.baidu.com/getscript?v=2.0&ak=bB8H5rgknsMqiKIDV0ALeuocIbXd6Uro&services=&t=20171004185957"></script>
</head>
<body>
<div id="map"></div>
<button onclick="stop()">暂停</button>
<button onclick="starts()">开始</button>
<button onclick="fast()">加快</button>
<script>
/**
* 示例:伴随与目标的轨迹,根据同一时间比例计算,可以重点突出伴随的效果,只要时间一致,那么伴随效果就能显现
*/
// 自定义目标数据
var tarData = [
{
latitude: 34.27563,
longitude: 108.99059,
time: "2018-10-30 13:23:32"
},
{
latitude: 34.276365,
longitude: 108.980291,
time: "2018-10-30 13:43:32"
},
{
latitude: 34.276361,
longitude: 108.969296,
time: "2018-10-30 15:55:32"
},
{
latitude: 34.276164,
longitude: 108.953575,
time: "2018-10-30 16:15:32"
},
{
latitude: 34.276164,
longitude: 108.953575,
time: "2018-10-30 19:55:32"
},
{
latitude: 34.287457,
longitude: 108.953593,
time: "2018-10-30 23:55:32"
},
{
latitude: 34.27563,
longitude: 108.99059,
time: "2018-10-31 02:03:32"
}
];
// 自定义伴随数据
var accData = [
{
latitude: 34.28563,
longitude: 108.98059,
time: "2018-10-30 12:43:32"
},
{
latitude: 34.277365,
longitude: 108.981291,
time: "2018-10-30 13:23:32"
},
{
latitude: 34.277361,
longitude: 108.970296,
time: "2018-10-30 15:45:32"
},
{
latitude: 34.277361,
longitude: 108.970296,
time: "2018-10-30 16:05:32"
},
{
latitude: 34.276164,
longitude: 108.953575,
time: "2018-10-30 16:15:32"
},
{
latitude: 34.276164,
longitude: 108.953575,
time: "2018-10-30 19:55:32"
},
{
latitude: 34.287457,
longitude: 108.953593,
time: "2018-10-30 23:55:32"
},
{
latitude: 34.27563,
longitude: 108.99059,
time: "2018-10-31 02:03:32"
}
];
// 初始化地图
var map = new BMap.Map("map");
map.enableScrollWheelZoom(true);
map.centerAndZoom(new BMap.Point(108.967584, 34.28106), 16);
// 获取data数据中的经纬度点并格式化点为BMap点
var tarPoints = getBMapPoints(tarData);
var accPoints = getBMapPoints(accData);
// 经过计算后得到的总坐标点
var tarAllPoints = [];
var accAllPoints = [];
// 此处是先去根据时间判断先后启动,后启动的在起点等待,也就是添加起点的坐标
var tarStartTime = new Date(tarData[0]["time"])
var accStartTime = new Date(accData[0]["time"])
// 判断时间前后,根据同一个比例进行添加对应的坐标
if(tarStartTime - accStartTime > 0) {
var num = (tarStartTime - accStartTime) / 30000
tarAllPoints.push(...addCoord(tarPoints[0], num));
}
if(accStartTime - tarStartTime > 0) {
var num = (accStartTime - tarStartTime) / 30000
accAllPoints.push(...addCoord(accPoints[0], num));
}
// 添加计算的坐标,根据同一个比例进行添加对应的坐标
tarAllPoints.push(...sumPoints(tarPoints, tarData));
accAllPoints.push(...sumPoints(accPoints, accData));
// 目标icon
var tarIcon = new BMap.Icon("./img/tar.png", new BMap.Size(37, 46), {
anchor: new BMap.Size(20, 20)
});
// 伴随icon
var accIcon = new BMap.Icon("./img/acc.png", new BMap.Size(37, 46), {
anchor: new BMap.Size(20, 20)
});
// 初始化对象
var tarLuShu = new customLushu(map, tarAllPoints, {
icon: tarIcon
})
var accLuShu = new customLushu(map, accAllPoints, {
icon: accIcon,
strokeColor: '#0096ff',
strokeWeight: 2,
strokeOpacity: 0.7
})
// 开始运行
tarLuShu.start();
accLuShu.start();
/**
* 暂停
*/
function stop() {
tarLuShu.stop();
accLuShu.stop();
}
/**
* 开始
*/
function starts() {
tarLuShu.start();
accLuShu.start();
}
/**
* 加快
*/
function fast() {
tarLuShu.fast();
accLuShu.fast();
}
</script>
</body>
</html>