-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.html
More file actions
282 lines (269 loc) · 7.75 KB
/
test.html
File metadata and controls
282 lines (269 loc) · 7.75 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
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
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="chrome=1">
<meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
<link rel="stylesheet" href="js/ol3/ol.css" type="text/css"/>
<link rel="stylesheet" href="js/ol3/ol3-popup.css" type="text/css"/>
<link rel="stylesheet" href="css/layout.css" type="text/css"/>
<script src="js/ol3/ol.js" type="text/javascript"></script>
<script src="js/ol3/ol3-popup.js" type="text/javascript"></script>
<script type="text/javascript" src="js/jquery-2.1.3.min.js"></script>
<script type="text/javascript" src="js/jquery.datetimepicker.js"></script>
<link rel='stylesheet' href='css/jquery.datetimepicker.css' type='text/css' />
<style>
.ol-popup {
background-color : rgba(0,0,0,0.35);
padding-left : 2em;
}
</style>
</head>
<body>
<div id='map' style='position:absolute;top:0;left:0;right:0;bottom:0;background-color:white;'>
</div>
<input id="from" type="text" style="position:absolute;top:5px;left:5px;width:150px;"/>
<input id="to" type="text" style="position:absolute;top:5px;left:160px;width:150px;"/>
<input id="imei" type="text" value="000000000000" style="position:absolute;top:5px;right:5px;width:150px;text-align:right;"/>
<div id="go" style="position:absolute;top:5px;left:315px;width:auto;background-color:white;border:1px solid black;line-height:1.5em;padding-left:5px;padding-right:5px;cursor:pointer;"/>Show</div>
<div style="position:absolute;top:6px;right:165px;width:auto;line-height:1.5em;background-color: white;padding-left:5px;padding-right:5px;"/>IMEI</div>
<script>
$('#from,#to').datetimepicker({format:'d.m.Y h:m'});
if (localStorage.getItem("from"))
$("#from").val(localStorage.getItem("from"));
if (localStorage.getItem("to"))
$("#to").val(localStorage.getItem("to"));
if (localStorage.getItem("imei"))
$("#imei").val(localStorage.getItem("imei"));
var map;
var popup;
function formatDate(d) {
var dd = d.getDate();
var mm = d.getMonth()+1; //January is 0!
var yyyy = d.getFullYear();
if(dd<10){
dd='0'+dd
}
if(mm<10){
mm='0'+mm
}
return dd+'.'+mm+'.'+yyyy;
}
function formatTime(d) {
var hh = d.getHours();
if(hh<10){
hh='0'+hh
}
var mm = d.getMinutes();
if(mm<10){
mm='0'+mm
}
var ss = d.getSeconds();
if(ss<10){
ss='0'+ss
}
return hh+":"+mm+":"+ss;
}
function getMillis(id,def)
{
var str = $("#"+id).val();
var pp = str.split(" ");
if (!pp || pp.length != 2)
return def;
var p1 = pp[0].split(".");
var p2 = pp[1].split(":");
if (!p1 || p1.length != 3)
return def;
if (!p2 || p2.length != 2)
return def;
return (new Date(parseInt(p1[2]),
parseInt(p1[1]) - 1,
parseInt(p1[0]),
parseInt(p2[0]),
parseInt(p2[1])
)).getTime();
}
function style(feature,resolution)
{
var isSOS = feature.data.type == "ECALL" ? true : false;
var styles=[];
styles.push(new ol.style.Style(
{
zIndex : feature.data.EPOCH,
image : new ol.style.Circle({
radius: 5,
fill: new ol.style.Fill({
color: isSOS ? "rgba(255,0,0,0.7)" : "rgba(0,255,0,0.7)"
}),
stroke: new ol.style.Stroke({
color: isSOS ? "rgba(0,0,0,0.7)" : "#000000",
width: 1.5
})
}),
text: new ol.style.Text({
font: 'bold 9px Arial,Lucida Grande,Tahoma,Verdana',
fill: new ol.style.Fill({
color: "#000000"
}),
stroke: new ol.style.Stroke({
color: [255, 255, 255, 0.5],
width: 4
}),
text : formatDate(new Date(feature.data.EPOCH)),
offsetX : 0,
offsetY : -12
})
}));
styles.push(new ol.style.Style(
{
zIndex : feature.data.EPOCH,
text: new ol.style.Text({
font: 'bold 9px Arial,Lucida Grande,Tahoma,Verdana',
fill: new ol.style.Fill({
color: "#000000"
}),
stroke: new ol.style.Stroke({
color: [255, 255, 255, 0.5],
width: 4
}),
text : formatTime(new Date(feature.data.EPOCH)),
offsetX : 0,
offsetY : 12
})
}));
return styles;
}
var gps = new ol.layer.Vector({
source: new ol.source.Vector()
,style : style
});
function onData(data)
{
gps.getSource().clear();
if (!data.length)
return;
var minx=null,miny=null,maxx=null,maxy=null;
for (var i=0;i<data.length;i++)
{
var e = data[i];
//----------------------------------
delete e._id;
delete e.TS;
e.LON=parseInt(e.LON);
e.LAT=parseInt(e.LAT);
if (isNaN(e.LON) || isNaN(e.LAT))
continue;
if (e.ALT)
e.ALT=parseFloat(e.ALT);
if (e.TIME)
e.TIME=parseFloat(e.TIME);
if (e.HRT)
e.HRT=parseInt(e.HRT);
if (e.LON == 0 && e.LAT == 0)
continue;
//----------------------------------
var c = ol.proj.transform([e.LON / 1000000.0,e.LAT / 1000000.0], 'EPSG:4326', 'EPSG:3857');
if (minx == null || c[0] < minx)
minx=c[0];
if (miny == null || c[1] < miny)
miny=c[1];
if (maxx == null || c[0] > maxx)
maxx=c[0];
if (maxy == null || c[1] > maxy)
maxy=c[1];
var geom = new ol.geom.Point(c);
var feature = new ol.Feature();
feature.data=e;
feature.setGeometry(geom);
gps.getSource().addFeature(feature);
}
map.getView().fitExtent([minx,miny,maxx,maxy],map.getSize());
}
function saveState() {
localStorage.setItem("from",$("#from").val());
localStorage.setItem("to",$("#to").val());
localStorage.setItem("imei",$("#imei").val());
}
function doGet()
{
var from = getMillis("from",0);
var to = getMillis("to",(new Date()).getTime() + 31556952000*100 /* 100 years */);
console.log("GET DATA FOR ["+from+" > "+to+"]");
// RANDOM
/*var data = [];
for (var i=0;i<20;i++)
{
var lon = 10.366229+(Math.random()*2-1)*2;
var lat = 50.998475+(Math.random()*2-1)*2;
var rate = parseInt(Math.random()*100);
var alt = Math.random()*1000;
var type = Math.random() > 0.85 ? "ECALL" : "RACEDATA";
var timestamp = parseInt(Math.random()*1000000000000);
data.push(
{
LON : parseInt(Math.round(lon*1000000)),
LAT : parseInt(Math.round(lat*1000000)),
HRT : rate,
ALT : alt,
SOS : sos,
EPOCH : timestamp
});
}
onData(data);*/
var url = "/triathlon/rest/raceRecord/"+$("#imei").val()+"?from="+from+"&to="+to;
$.getJSON(url, function(result)
{
if (!(result instanceof Array) && result.data)
result=result.data;
if (result instanceof Array)
onData(result);
else{
alert("ERROR : "+JSON.stringify(result));
}
});
}
$(document).ready(function() {
map = new ol.Map({
renderer : "canvas",
target: 'map',
layers: [
new ol.layer.Tile({
source: new ol.source.OSM({
//url: 'http://{a-c}.tile.opencyclemap.org/cycle/{z}/{x}/{y}.png'
})
}),
gps
],
view: new ol.View({
center: ol.proj.transform([10.366229,50.998475], 'EPSG:4326', 'EPSG:3857'),
zoom: 6,
minZoom: 0,
maxZoom: 19
//,extent : extent ? extent : undefined
})
});
popup = new ol.Overlay.Popup({ani:false,panMapIfOutOfView : false});
map.on('click', function(event)
{
var ok=false;
map.forEachFeatureAtPixel(event.pixel, function(feature, layer)
{
ok=true;
var spos = feature.getGeometry().getCoordinates();
var html = JSON.stringify(feature.data);
html=html.split(",").join(",<br/> ");
html=html.split("{").join("{<br/> ");
html=html.split("}").join("<br/>}");
html=html.split(":").join(" : ");
popup.show(spos, html);
},this);
if (!ok)
popup.hide();
});
map.addOverlay(popup);
});
$("#go").click(doGet);
$("input").change(saveState);
</script>
</body>
</html>