-
Notifications
You must be signed in to change notification settings - Fork 0
/
map.html
331 lines (310 loc) · 16.4 KB
/
map.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
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
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
<html>
<head>
<title>HAB's Location</title>
<!--<meta http-equiv="refresh" content="30" />-->
<meta charset="utf-8" />
<!-- <meta name="viewport" content="width=device-width, initial-scale=1.0">-->
<link rel="stylesheet" href="leaflet/leaflet.css" />
<script type="text/javascript" src="leaflet/leaflet.js"></script>
<script type="text/javascript" src="leafletembed.js"></script>
<!--<script type="text/javascript" src="leaflet-omnivore/leaflet-omnivore.min.js"></script>-->
<script src='//api.tiles.mapbox.com/mapbox.js/plugins/leaflet-omnivore/v0.3.1/leaflet-omnivore.min.js'></script>
<!--<script type="text/javascript" src="Chart.js/Chart.js"></script>-->
<!--<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/3.6.0/chart.min.js"></script>-->
<!--<script type="text/javascript" src="Chart.Scatter/Chart.Scatter.js"></script>-->
<script
src="https://code.jquery.com/jquery-3.3.1.min.js"
integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
crossorigin="anonymous"></script>
<script src='https://api.mapbox.com/mapbox.js/plugins/leaflet-fullscreen/v1.0.1/Leaflet.fullscreen.min.js'></script>
<link href='https://api.mapbox.com/mapbox.js/plugins/leaflet-fullscreen/v1.0.1/leaflet.fullscreen.css' rel='stylesheet' />
</head>
<body>
<h2><span class="distintivo"></span>'s status as of <span class="tiempo"></span>:</h2>
<!-- <h4>Battery: (<span class="voltios"></span> V)</h4>-->
<h4>Data: (<span class="datos"></span>)</h4>
<h4>Globo: (<a class="globo"></a>)</h4>
<h4>Meta: (<a class="meta"></a>)</h4>
<label for="indicativo">Indicativo:</label>
<select id="indicativo" onchange="recarga()">
<option value="EA2DVJ-11">EA2DVJ-11</option>
<option value="EA4GZT-11">EA4GZT-11</option>
</select>
<input type="button" onclick="recarga()" value="Recarga" ></input>
<!--<input type="button" onclick="simula(globo_position)" value="¡Simula ahora!" ></input>-->
<label><input type="checkbox" id="bajando" value="bajando" onchange="recarga()">Simula caída</label>
<label><input type="checkbox" id="inicial" value="inicial" onchange="recarga()">Simula desde base</label>
<!--<input type="button" onclick="simula_caida(globo_position)" value="Simula caida" ></input>-->
<!--<input type="button" onclick="simula_inicial([42.0408,-0.5762])" value="Simula Almudevar" ></input>-->
<!--<input type="button" onclick="llevame_dest(globo_position)" value="Llevame globo" ></input>-->
<!--<input id="button_llevame_meta" disabled="true" type="button" onclick="llevame_dest(finish_position)" value="Llevame meta" ></input>-->
<br/>
<label for="refresh_interval">Internvalo de actualziación (s)</label><input type="text" id="refresh_interval" name="refresh_interval" size="3" value="30" onchange="set_interval()">
<br/>
<fieldset>
<legend>Destino:</legend>
<div>
<input type="radio" id="dest_nada" name="destino" value="dest_nada" onchange="recarga()">
<label for="dest_nada">No calcular</label>
</div>
<div>
<input type="radio" id="dest_globo" name="destino" value="dest_globo" onchange="recarga()">
<label for="dest_globo">Globo</label>
</div>
<div>
<input type="radio" id="dest_meta" name="destino" value="dest_meta" checked onchange="recarga()">
<label for="dest_meta">Meta</label>
</div>
</fieldset>
<br/>
<label for="ascent_rate">Velocidad de ascenso</label><input type="text" id="ascent_rate" name="ascent_rate" size="10" value="7">
<label for="burst_alt">Altura máxima</label><input type="text" id="burst_alt" name="burst_alt" size="10" value="31500">
<label for="descent_rate">Velocidad de descenso</label><input type="text" id="descent_rate" name="descent_rate" size="10" value="6.23">
<canvas height="30"></canvas>
<br/>
<!--Mallen
-->
<!--
<label for="lat_ini">Latitud inicial</label><input type="text" id="lat_ini" name="lat_ini" size="10" value="41.9008">
<label for="lon_ini">Longitud inicial</label><input type="text" id="lon_ini" name="lon_ini" size="10" value="-1.4232">
-->
<!--Borja
-->
<!--
<label for="lat_ini">Latitud inicial</label><input type="text" id="lat_ini" name="lat_ini" size="10" value="41.8324">
<label for="lon_ini">Longitud inicial</label><input type="text" id="lon_ini" name="lon_ini" size="10" value="-1.5265">
-->
<!--Morata
-->
<!--
<label for="lat_ini">Latitud inicial</label><input type="text" id="lat_ini" name="lat_ini" size="10" value="41.4733">
<label for="lon_ini">Longitud inicial</label><input type="text" id="lon_ini" name="lon_ini" size="10" value="-1.4834">
-->
<!--Ateca
-->
<!--
<label for="lat_ini">Latitud inicial</label><input type="text" id="lat_ini" name="lat_ini" size="10" value="41.33184">
<label for="lon_ini">Longitud inicial</label><input type="text" id="lon_ini" name="lon_ini" size="10" value="-1.79040">
-->
<!--Calamocha
-->
<label for="lat_ini">Latitud inicial</label><input type="text" id="lat_ini" name="lat_ini" size="10" value="40.92184">
<label for="lon_ini">Longitud inicial</label><input type="text" id="lon_ini" name="lon_ini" size="10" value="-1.29942">
<label for="alt_ini">Altitud inicial</label><input type="text" id="alt_ini" name="alt_ini" size="5" value="884">
<label for="fecha_ini">Fecha inicial</label><input type="text" id="fecha_ini" name="fecha_ini" size="30" value="2024-04-27T09:00:00.000Z">
<canvas id="historyChart" height="30"></canvas>
<!-- <iframe width="<?=$width?>" height="<?=$height?>" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="<?=$embedUrl?>" style="border: 1px solid black"></iframe> -->
<div id="map" style=" height: 70%"></div>
<small><!--<a href="">View Larger Map</a>--></small>
<script>
var my_position;
var globo_position;
var finish_position;
var track;
var asc_poly, des_poly;
var globo_marker, my_marker, finish_marker;
var refresh_interval_id;
recarga();
//simula();
//simula_inicial([42.0408,-0.5762]);
initmap();
map.addControl(new L.Control.Fullscreen());
let textbox_payload = L.Control.extend({
onAdd: function() {
var text = L.DomUtil.create('div');
text.id = "info_text";
text.innerHTML = '<h2><span class="distintivo"></span>: <span class="tiempo"></span></h2><h3>Data: (<span class="datos"></span>)</h3>'
return text;
},
});
new textbox_payload({ position: 'bottomleft' }).addTo(map);
let textbox_eta = L.Control.extend({
onAdd: function() {
var text = L.DomUtil.create('div');
text.id = "info_text";
text.innerHTML = '<h2>Llegada:</h2><h3>Globo: <span class="eta_globo"></span></h3><h3>Coche: <span class="eta_coche"></span></h3>'
return text;
},
});
new textbox_eta({ position: 'topright' }).addTo(map);
/* Rectángulo límites */
var bounds = [[41.48937,-0.53218], [40.871279,-1.381347]];
L.rectangle(bounds, {fill:false,color: "#ff7800", weight: 2}).addTo(map);
//map.setView(new L.LatLng(40, 0),17);
//omnivore.gpx('s2g.php?file=tmplocation.log').addTo(map);
refresh_interval_id = setInterval(function () {recarga(); }, 1000 * parseInt($("#refresh_interval").val()));
function set_interval() {
if (refresh_interval_id !== undefined) {
clearInterval(refresh_interval_id);
}
refresh_interval_id = setInterval(function () {recarga(); }, 1000 * parseInt($("#refresh_interval").val()));
}
function millis2time(diff) {
let ms = diff % 1000;
let ss = Math.floor(diff / 1000) % 60;
let mm = Math.floor(diff / 1000 / 60) % 60;
let hh = Math.floor(diff / 1000 / 60 / 60);
return "" + hh + ":" + mm;
}
function recarga() {
//$.getJSON( 'https://api.aprs.fi/api/get?name=EA2DVJ-11&what=loc&apikey=109984.vUFksEiAq8PAsJQ&format=json', function ( data ) { alert(data);} );
let encuentrame = navigator.geolocation.getCurrentPosition((pos) => {
//encuentrame();
my_position = [pos.coords.latitude, pos.coords.longitude];
//console.log(pos);
var coor = "" + pos.coords.latitude + "," + pos.coords.longitude + ";" + $lat + "," + $lng ;
var coortxt = "" + pos.coords.latitude + "," + pos.coords.longitude + "|" + $lat + "," + $lng ;
my_marker = L.marker([pos.coords.latitude, pos.coords.longitude]).addTo(map);
//map.setView(new L.LatLng(pos.coords.latitude, pos.coords.longitude));
//console.log(coor);
llevame();
});
$.ajax({
url: "aprs.php?indicativo=" + $("#indicativo").val(),
type: "GET",
dataType: "json",
//beforeSend: function(request) {
// request.setRequestHeader("User-Agent","HAB-tracker/0.0.1 (https://github.com/alejandroscf/hab-tracker)");
//},
success: function (foo) {
$(".distintivo").text($("#indicativo").val());
//console.log(foo);
$fecha = new Date();
$fecha.setTime(foo.entries[0].lasttime*1000);
//console.log(foo.entries[0].lasttime);
//console.log(foo.entries[0].time);
//console.log($fecha);
$(".tiempo").text($fecha.toLocaleString('en-GB'));
$(".datos").text(foo.entries[0].comment.replace(/,/g,', '));
url = "https://osmand.net/go?lat="+foo.entries[0].lat+"&lon="+foo.entries[0].lng;
$(".globo").text(url);
$(".globo").attr("href",url);
$lat = foo.entries[0].lat;
$lng = foo.entries[0].lng;
globo_position = [foo.entries[0].lat, foo.entries[0].lng, foo.entries[0].altitude]
var globoIcon = new L.Icon({iconUrl: 'globo.png'});
globo_marker = L.marker([$lat, $lng], {icon: globoIcon}).addTo(map);
map.setView(new L.LatLng($lat, $lng));
simula(globo_position);
},
});
};
function llevame () {
if ( $("input[name=destino]:checked").val() == 'dest_globo' ){
llevame_dest(globo_position);
} else if ( $("input[name=destino]:checked").val() == 'dest_meta' ){
llevame_dest(finish_position);
}
}
function llevame_dest (dest) {
if (my_position !== undefined) {
try { map.removeLayer(track); } catch (error) {};
var point1 = "" + my_position[0] + "," + my_position[1];
var point2 = "" + dest[0] + "," + dest[1] ;
$.ajax({
//osrm (osm)
//url: "https://router.project-osrm.org/route/v1/driving/" + coor,
//data: {overview: "false", geometries: "polyline", steps: "true"},
//osrm (api)
//url: "https://api.openrouteservice.org/directions",
//data: { coordinates: coortxt, profile: "driving-car", geometry: "true", geometry_format: "polyline",},
//profile: "foot-hiking"
url: "https://graphhopper.com/api/1/route?point="+ point1,
data: {point: point2, type: "gpx", key: "a54c1ef8-63cb-42c5-817d-326e8aa31587"},
//data: {point: point2, key: "a54c1ef8-63cb-42c5-817d-326e8aa31587"},
type: "GET",
success: function (gpx_track) {
//console.log(gpx_track);
track = omnivore.gpx.parse(gpx_track)
//console.log(track);
track.addTo(map);
track.eachLayer(function(layer){
if (layer.feature && layer.feature.properties && layer.feature.properties.coordTimes) {
//console.log(layer.feature.properties.coordTimes);
first_point_c = layer.feature.properties.coordTimes.at(0);
last_point_c = layer.feature.properties.coordTimes.at(-1);
let first_date_c = new Date(first_point_c);
let last_date_c = new Date(last_point_c);
//console.log(first_date_c);
//console.log(last_date_c);
eta_coche = millis2time(last_date_c - first_date_c);
if ( $("input[name=destino]:checked").val() == 'dest_meta' ) {
$('.eta_coche').text(eta_coche)
} else {
$('.eta_coche').text(eta_coche + " a globo")
}
}
});
//map.fitBounds(track.getBounds());
},
});
} else {
console.log("Location not available");
}
}
function wrapLng(lng) {
if (lng < 0) { lng = parseFloat(lng) + 360 };
return lng;
}
function unWrapLng(lng) {
if (lng > 180) { lng = lng - 360 };
return lng;
}
function simula(position) {
$fecha_sim = new Date().toISOString();
$ascent_rate = $("#ascent_rate").val();
$descent_rate = $("#descent_rate").val();
$burst_alt = $("#burst_alt").val();
if ( $("#inicial").prop('checked') ) {
position[0] = $("#lat_ini").val();
position[1] = $("#lon_ini").val();
position[2] = $("#alt_ini").val();
$fecha_sim = $("#fecha_ini").val();
} else if ( $("#bajando").prop('checked') || parseInt(position[2]) > parseInt($burst_alt) ) {
$burst_alt = (parseInt(position[2])+1)
}
$url = "https://api.v2.sondehub.org/tawhiri?launch_latitude="+position[0]+"&launch_longitude="+wrapLng(position[1])+"&launch_datetime="+$fecha_sim+"&ascent_rate="+$ascent_rate+"&descent_rate="+$descent_rate+"&burst_altitude="+$burst_alt+"&launch_altitude="+position[2];
try { map.removeLayer(asc_poly);map.removeLayer(des_poly);map.removeLayer(finish_marker); } catch (error) {};
//console.log(position[1]);
//console.log(wrapLng(position[1]));
$.getJSON(
$url,
function ( data ) {
//console.log(data);
var asc_points = data.prediction[0].trajectory.map(function(x) {
return [x.latitude,unWrapLng(x.longitude)];
});
asc_poly = L.polyline(asc_points, {color: 'green'}).addTo(map);
//map.fitBounds(asc_poly.getBounds());
//console.log(asc_poly);
var des_points = data.prediction[1].trajectory.map(function(x) {
return [x.latitude,unWrapLng(x.longitude)];
});
//console.log(des_points);
first_point = data.prediction[0].trajectory.at(0);
last_point = data.prediction[1].trajectory.at(-1);
let first_date = new Date(first_point.datetime);
let last_date = new Date(last_point.datetime);
//console.log(first_date);
//console.log(last_date);
eta_globo = millis2time(last_date - first_date);
des_poly = L.polyline(des_points, {color: 'red'}).addTo(map);
map.fitBounds(des_poly.getBounds().extend(asc_poly.getBounds()));
//map.setView(new L.LatLng(41.6633,-0.8250),12);
//console.log(des_poly);
//console.log(des_points[des_points.length - 1]);
finish_position = des_points[des_points.length - 1];
finish_marker = L.marker(finish_position).addTo(map);
//finish_marker.bindPopup("Llegada:<br\>Globo:<br\>Coche:").openPopup();
//console.log(globo_position);
url = "https://osmand.net/go?lat="+finish_position[0]+"&lon="+finish_position[1];
$(".meta").text(url);
$(".meta").attr("href",url);
$("#button_llevame_meta").prop('disabled', false);
$(".eta_globo").text(eta_globo);
}
);
};
</script>
</body>
</html>