forked from itemir/dump1090_sdrplus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gmap.html
246 lines (221 loc) · 6.14 KB
/
gmap.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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
<style type="text/css">
html {
height: 100%
}
body {
height: 100%;
width: 100%;
margin: 0;
padding: 0
}
#container {
height: 100%;
width: 80%;
}
#info {
position: absolute;
width: 20%;
height: 100%;
bottom: 0px;
right: 0px;
top: 0px;
background-color: white;
border-left: 1px #666 solid;
font-family: Helvetica;
}
#info div {
padding: 0px;
padding-left: 10px;
margin: 0px;
}
#info div h1 {
margin-top: 10px;
font-size: 16px;
}
#info div p {
font-size: 14px;
color: #333;
}
</style>
<script src="https://code.jquery.com/jquery-1.12.4.min.js"
integrity="sha256-ZosEbRLbNQzLpnKIkEdrPv7lOy9C27hHQ+Xp8a4MxAQ=" crossorigin="anonymous">
</script>
<title>DUMP1090</title>
</head>
<body>
<div id="container"></div>
<div id="info">
<div>
<h1>Dump1090 by PokeBox</h1>
<p id="geninfo"></p>
<p id="selinfo">点击飞机查看具体信息</p>
</div>
</div>
<script type="text/javascript">
Map = null;
CenterLat = 0;
CenterLon = 0;
Planes = {}; //飞机列表对象
NumPlanes = 0;
Selected = null;
function getIconForPlane(plane) {
var iconurl = "https://www.easyicon.net/api/resizeApi.php?id=1082137&size=128";
return new AMap.Icon({
size: new AMap.Size(32, 32), //画布大小
image: iconurl, //图像路径
imageSize: new AMap.Size(32, 32), //图标大小(实际缩放)
imageOffset: new AMap.Pixel(0, 0) //显示偏移
});
}
function selectPlane() {
if (!Planes[this.planehex]) return;
var old = Selected;
Selected = this.planehex;
if (Planes[old]) {
// Remove the highlight in the previously selected plane.
Planes[old].marker.setIcon(getIconForPlane(Planes[old]));
}
Planes[Selected].marker.setIcon(getIconForPlane(Planes[Selected]));
refreshSelectedInfo();
}
function refreshGeneralInfo() {
var i = document.getElementById('geninfo');
i.innerHTML = NumPlanes + ' 个飞机在范围内';
}
function refreshSelectedInfo() {
var i = document.getElementById('selinfo');
var p = Planes[Selected];
var icaoplan = p.flight.slice(0, 3);
var arr = [
['AMU', '澳门航空'],
['CCA', '中国国际航空'],
['CCD', '大连航空'],
['CDG', '山东航空'],
['CES', '中国东方航空'],
['CHH', '海南航空'],
['CKK', '中国货运航空'],
['CQH', '春秋航空'],
['CQN', '重庆航空'],
['CSC', '四川航空'],
['CSH', '上海航空'],
['CSN', '中国南方航空'],
['CSZ', '深圳航空'],
['CUA', '中国联合航空'],
['CXA', '厦门航空'],
['DKH', '吉祥航空'],
['GCR', '天津航空'],
['HBH', '河北航空'],
['HDA', '港龙航空'],
['HKE', '香港快运航空'],
['HXA', '华夏航空'],
['OKA', '奥凯航空'],
['TBA', '西藏航空']
];
if (!p) return;
var zh = '未知';
for (ii = 0; ii < arr.length; ii++) {
if (icaoplan === arr[ii][0]) {
zh = arr[ii][1];
break;
}
}
var html = 'ICAO: ' + p.hex + '<br>';
if (p.flight.length) {
html += '<b>' + p.flight + '</b><br>';
}
html += '高度: ' + (p.altitude * 0.3048).toFixed(2) + ' 米<br>';
html += '速度: ' + (p.speed * 1.852).toFixed(2) + ' km/h<br>';
html += '坐标: ' + p.lat + ', ' + p.lon + '<br>';
html += '航空公司:' + zh + '<br>';
i.innerHTML = html;
}
function fetchData() {
$.getJSON('/data.json', function (data) {
var stillhere = {}
//循环获取每个飞机数据
for (var j = 0; j < data.length; j++) {
var plane = data[j];
var marker = null;
stillhere[plane.hex] = true; //飞机还在
plane.flight = $.trim(plane.flight); //飞机名字
if (Planes[plane.hex]) {
var myplane = Planes[plane.hex];
marker = myplane.marker;
var icon = marker.getIcon();
var newpos = new AMap.LngLat(plane.lon, plane.lat);
//坐标转换
AMap.convertFrom([plane.lon, plane.lat], 'gps', function (status, result) {
if (result.info === 'ok') {
newpos = result.locations[0];
}
});
marker.setPosition(newpos);
marker.setIcon(getIconForPlane(plane));
marker.setAngle(plane.track);
myplane.altitude = plane.altitude;
myplane.speed = plane.speed;
myplane.lat = plane.lat;
myplane.lon = plane.lon;
myplane.track = plane.track;
myplane.flight = plane.flight;
if (myplane.hex == Selected)
refreshSelectedInfo();
} else {
var newpos = new AMap.LngLat(plane.lon, plane.lat);
//坐标转换
AMap.convertFrom([plane.lon, plane.lat], 'gps', function (status, result) {
if (result.info === 'ok') {
newpos = result.locations[0];
}
});
marker = new AMap.Marker({
position: newpos,
map: Map,
angle: plane.track,
icon: getIconForPlane(plane)
});
plane.marker = marker;
marker.planehex = plane.hex;
Planes[plane.hex] = plane;
//绑定点击事件
AMap.event.addListener(marker, 'click', selectPlane);
}
if (plane.flight.length == 0)
marker.setTitle(plane.hex)
else
marker.setTitle(plane.flight + ' (' + plane.hex + ')')
}
NumPlanes = data.length;
// Remove idle planes.
for (var p in Planes) {
if (!stillhere[p]) {
Planes[p].marker.setMap(null);
delete Planes[p];
}
}
});
}
function initialize() {
var mapOptions = {
resizeEnable: true, //是否监控地图容器尺寸变化
zoom: 9 //初始化地图层级
};
Map = new AMap.Map(document.getElementById("container"), mapOptions);
/* Setup our timer to poll from the server. */
window.setInterval(function () {
fetchData();
refreshGeneralInfo();
}, 1000);
}
</script>
<script src="https://webapi.amap.com/js/marker.js"></script>
<script
src="https://webapi.amap.com/maps?v=1.4.14&key=你的key&callback=initialize&plugin=AMap.Geocoder"></script>
</body>
</html>