-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathecef_path_generator.html
More file actions
executable file
·331 lines (300 loc) · 49.1 KB
/
ecef_path_generator.html
File metadata and controls
executable file
·331 lines (300 loc) · 49.1 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
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
<!DOCTYPE html>
<html>
<!--
/*
/*********************************************************************
* ecef_path_generator.js *
* *
* Version: 2.0 *
* Date: 28-01-2022 review 10-11-2025 *
* Author: Dan Machado *
*********************************************************************/
This program is free software. It comes without any warranty, to
the extent permitted by applicable law. You can redistribute it
and/or modify it under the terms of the Do What The Fuck You Want
To Public License, Version 2, as published by Sam Hocevar. See
http://www.wtfpl.net/ for more details. */
-->
<head> <meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>ECEF Path Generator</title>
<!-- link rel="stylesheet" href="ecef.css" type="text/css" media="screen"-->
<!-- script type="text/javascript" src="raphael.min.js"></script -->
<script src="https://unpkg.com/raphael@2.3.0/raphael.min.js" crossorigin=""></script>
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.7.0/dist/leaflet.css" dintegrity="sha512-xwE/Az9zrjBIphAcBb3F6JVqxf46+CDLwfLMHloNu6KEQCAWi6HcDUbeOfBIptF7tcCzusKFjFw2yuvEpDL9wQ==" crossorigin=""/>
<script src="https://unpkg.com/leaflet@1.7.1/dist/leaflet.js" dintegrity="sha512-gZwIG9x3wUXg2hdXF6+rVkLF/0Vi9U8D2Ntg4Ga5I5BZpVkVxlJWbSQtXPSiUTtC0TjtGOmxa1AJPuV0CPthew==" crossorigin=""></script>
<!-- -->
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style type="text/css">
* {box-sizing: border-box;padding: 0;margin: 0;}* {-khtml-user-select: none;-ms-user-select: none;-moz-user-select: none;-webkit-user-select: none;-o-user-select: none;user-select: none;}body {background: #fff;padding: 1px;}.row::after {content: "";clear: both;display: table;}[class*="col-"] {float: left;padding: 15px;}html {font-family: "Lucida Sans", sans-serif;}ul {list-style-type: none;margin: 0;padding: 0;}#gadgets li{margin-bottom: 15px;font-size:14px;text-align:right }.menus li {padding: 8px;margin-bottom: 7px;background-color: #33b5e5;color: #ffffff;box-shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24);text-align:center;}.menus li:hover {background-color: #0099cc;}.aside {background-color: #33b5e5;padding: 15px;color: #ffffff;text-align: center;font-size: 14px;box-shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24);}#speed-panel {text-align:left;margin:0;}@media only screen and (min-width: 600px) {.col-s-1 {width: 8.33%;}.col-s-2 {width: 16.66%;}.col-s-3 {width: 25%;}.col-s-4 {width: 33.33%;}.col-s-5 {width: 41.66%;}.col-s-6 {width: 50%;}.col-s-7 {width: 58.33%;}.col-s-8 {width: 66.66%;}.col-s-9 {width: 75%;}.col-s-10 {width: 83.33%;}.col-s-11 {width: 91.66%;}.col-s-12 {width: 100%;}}@media only screen and (min-width: 768px) {.col-1 {width: 8.33%;}.col-2 {width: 16.66%;}.col-3 {width: 25%;}.col-4 {width: 33.33%;}.col-5 {width: 41.66%;}.col-6 {width: 50%;}.col-7 {width: 58.33%;}.col-8 {width: 66.66%;}.col-9 {width: 75%;}.col-10 {width: 83.33%;}.col-11 {width: 91.66%;}.col-12 {width: 100%;}}#canvasContainer {width:100%;border:1px solid black;position:relative;}#canvas {width:100%;position:absolute;z-index:80;}#map {width:100%;position:absolute;z-index:10;}#sbar{margin:5px;height:24px;padding:1px;}div.cntBotton{margin:10px 0;line-height:37px;text-align:center;background-color: #33b5e5;color: #ffffff;font-size:18px;}div.cntBotton:hover{background-color: #00ffff;font-weight:bold;}.clear{clear:both;}.fLeft{float:left;}.fRight{float:right;}#speed{color:#0066cc;}#distance {color:#00b300;}#altitude{color: #e8ef13;}.font1{font-size: 25px;}input[type="file"] {display: none;}.custom-btn {border: 1px solid #0066cc;display: inline-block;width:100%;text-align:center;padding: 10px 12px;cursor: pointer;}.custom-btn:hover {background-color: #00ffff;}.slider {-moz-appearance: none;-webkit-appearance: none;width: 100%;height: 5px;background: #d3d3d3;outline: none;opacity: 0.7;-webkit-transition: .2s;transition: opacity .2s;margin:0px;}.slider:hover {opacity: 2;}.slider::-webkit-slider-thumb {-moz-appearance: none;-webkit-appearance: none;appearance: none;width: 25px;height: 25px;background: #0066cc;cursor: pointer;}.slider::-moz-range-thumb {width: 25px;height: 25px;background: #0066cc;cursor: pointer;}#dim {position:fixed;top: 0;left: 0;width: 100%;height:200em;background: #a1a1a1;z-index: 1000;opacity:0.40;display:none;}#pop_wrapper {position:fixed;width: 100%;height:0;top:0;left:0;visibility:hidden;-webkit-transition: opacity 0.7s;-moz-transition: opacity 0.7s;-ms-transition: opacity 0.7s;-o-transition: opacity 0.7s;transition: opacity 0.7s;z-index:1001;text-align: center;}#pop_up {position: relative;display: inline-block;background:#ffffff;border-radius: 5px;}#pop_up_content {padding:20px;overflow-y:auto;max-height:600px;}#pop_up_header {background:#4c9df1;line-height:20px;text-align:left;padding:5px;color:#fff;}#popup_content {padding:5px;}#popup_content > div {display:none;}#closePopUp {float:right;margin-right:4px;font-size:16px;font-weight:bold;cursor:default;}.abcr td{padding:3px;}.tleft{text-align:right;}.tright{text-align:left;}.flex-container {display: flex;justify-content: space-around;}.divRow{display:table-row;}.divCell{display:table-row;}#squareList{list-style-position: inside;list-style-type: square;}#squareList li{padding:10px;}#docList{list-style-position: inside;list-style-type: initial;}#docList li{padding:10px;}#docList ul{list-style-position: inside;list-style-type: circle;}
</style>
</head>
<body>
<!-- ####################################################-->
<div id="dim"></div>
<div id="pop_wrapper">
<div id="pop_up">
<div id="pop_up_header">
<span id="popup_title"></span>
<span id="closePopUp">×</span>
<div style="clear:both;"></div>
</div>
<div id="popup_content">
<div id="ecef">
<table class="abcr">
<tr>
<td class="tleft">Frequency:</td>
<td class="tright">
<input type="text" id="frequency" maxlength="4" size="4">Hz
</td>
</tr>
<tr>
<td class="tleft">Save as:</td>
<td><input type="text" id="fileName"></td>
</tr>
</table>
<button id="ecefButton">Download</button>
</div>
<div id="wait22">
<p>Processing data, please wait...</p>
</div>
<div id="rawData">
<div id="form2">
Save as: <input type="text" id="fileNameR"><br/>
<button id="rawDataButton">Download</button>
</div>
</div>
<div id="gpxData">
<div id="form2">
GPX file name: <input type="text" id="gpxNameR"><br/>
Description: <input type="text" id="gpxDesc"><br/>
<button id="gpxDataButton">Download</button>
</div>
</div>
<div id="configuration">
<fieldset>
<legend>Location:</legend>
<table class="abcr">
<tr>
<td class="tleft">Latitude:</td>
<td><input type="text" id="latitude" maxlength="10" size="10" value="53.2672"></td>
</tr>
<tr>
<td class="tleft">Longitude:</td>
<td><input type="text" id="longitude" maxlength="10" size="10" value="-1.63"></td>
</tr>
<tr>
<td colspan="2" style="text-align:right;">
<button id="locationButton">Set location</button>
</td>
</tr>
</table>
</fieldset>
<fieldset>
<legend>Colour:</legend>
<table class="abcr">
<tr>
<td class="tleft">Trail:</td>
<td><input type="text" id="trail_colour" maxlength="7" size="7"></td>
</tr>
<td class="tleft">Mover:</td>
<td><input type="text" id="mover_colour" maxlength="7" size="7"></td>
</tr>
<tr>
<td></td>
<td><button id="coloursButton">Change</button></td>
</tr>
</table>
</fieldset>
</div>
<div id="description" style="width:800px; padding:10px;text-align:justify; font-size:1em;overflow-y:scroll; max-height:300px">
<p>
This is an application that generates ECEF coordinates from a drawn path on a map.
The data generated can be used to generate GPS signal files for applications that
simulate GPS signal <a href="https://github.com/osqzss/gps-sdr-sim" target="_blank">gps-sdr-sim</a>
</p>
<br/>
<h4>Quick start:</h4>
<ul id="squareList">
<li>
Click "More Actions", select Settings, input the desire latitude, longitude and altitude
where the map will be centered and adjust the Zoom.
</li>
<li>
Over the map, draw a path using the mouse while pressing the left button, if it is needed
you can delete the last points drawn with the button Remove.
</li>
<li>
Adjust the initial speed using the bar below the map.
</li>
<li>
Adjust the initial time elapsed. At x1 this means that the mover will take 15 seconds
on a 1 kilometre path at 240 km/hr, at x2 it will take 7.5 (of real time),
at x4 3.75 sec (of real time) and so on. This will not affect the recording.
</li>
<li>
Click "Recorder / Player", click Record, a blue point will start moving along the
drawn path. You can modify the speed as you wish.
</li>
<li>
After finishes the recording, you can see the result by pressing the Play button.
</li>
</ul><br/>
<h4>Documentation</h4>
<ul id="docList">
<li>Key binding
<ul>
<li><i>W</i> increment speed by 5km</li>
<li><i>Q</i> decrement it by 5km</li>
<li><i>S</i> increment speed by 2km</li>
<li><i>A</i> decrement it by 2km</li>
<li><i>X</i> increment speed by 1km</li>
<li><i>Z</i> decrement it by 1km</li>
<li><i>RightArrow</i> increment speed by 0.5km</li>
<li><i>LeftArrow</i> decrement it by 0.5km</li>
<li><i>UpArrow</i> increment the altitude by 10 mtrs</li>
<li><i>DownArrow</i> decrement the altitude by 10 mtrs</li>
</ul>
</li>
<li>Recorder / Player
<ul>
<li><i>Record</i> starts to record the position and speed of the mover. Once the recording
has finished, speed can not be change. However it can be reset.</li>
<li><i>Reset</i> reset the path ready to be recorded again from the beginning. Speed is override.</li>
<li><i>Delete</i> delete the current path.</li>
<li><i>Remove</i> as far as the path have not been recorded, clicking remove will remove
the last point of the path, click it as needed to remove the many point.</li>
<li><i>Append</i> allows to add more points to the path. After recording a path, you can add more points to it by clicking Reset.</li>
</ul>
</li>
<li>More Actions
<ul>
<li><i>SSet View</i> clicking this button will allow you to center the map on the location selected by clicking on the map with the mouse's left button. Click it again to draw a path.</li>
<li><i>Settings</i> here you can set the latitude, longitude, altitude, zoom and colour for the path and mover.</li>
<li><i>Export to ECEF</i> after recording, you can download the path in ECEF
coordinates, you will need to input the frequency in Hertz for the
sample data. To use with <a href="https://github.com/osqzss/gps-sdr-sim" target="_blank">gps-sdr-sim</a> the sampling rate of the user motion has to be 10Hz.</li>
<li><i>Download Raw Data</i> this allows you to download the raw data a path was recorded, so you can import it later to play it, reset and change the speed and generate a different ECEF coordinate file.</li>
<li><i>Download GPX</i> export the path as gpx. The gpx format is widely supported by various GPS devices and software, making it a standard choice for outdoor enthusiasts and professionals.</li>
</ul>
</li>
</ul>
<br/>
<h4>Download</h4>
<p>
You can download this application from <a href="https://github.com/fpdf-easytable/ECEF_path_generator">here</a>.
</p>
</div>
</div>
</div>
</div>
<!-- ####################################################-->
<div class="row">
<div class="col-2 col-s-2 rightBlock">
<div id="left_pannel" style="overflow-x: hidden;overflow-y: auto; padding-right: 10px;">
<ul id="gadgets">
<li>
<div>Speed</div>
<div class="font1" id="speed" style="display:inline;">0.00</div>
<div style="display:inline;">km/h</div>
</li>
<li>
<div>Total Distance</div>
<div class="font1" id="Tdistance" style="display:inline;">0.00</div>
<div style="display:inline;">km</div>
</li>
<li>
<div>Distance</div>
<div class="font1" id="distance" style="display:inline;">0.00</div>
<div style="display:inline;">km</div>
</li>
<li>
<div>Altitude</div>
<div class="font1" id="altitude" style="display:inline;">0.00</div>
<div style="display:inline;">mt</div>
</li>
<li>
<div>Time</div>
<div class="font1" id="elapsedtime" style="display:inline;">0.00</div>
<div style="display:inline;">secs</div>
</li>
</ul>
<!-- ############################################ -->
<div style="display:table;padding:1px; dborder:1px solid; width:100%;">
<div style="display:table-row;">
<div style="margin-top:0px;">
<button id="recordButton" type="button" style="width:100%;">Record</button>
<button id="recordingButton" type="button" disabled="disable" style="width:100%;display:none;">Recording</button>
<button id="playButton" type="button" style="width:100%;display:none;">Play</button>
<button id="pauseButton" type="button" style="width:100%;display:none;margin-right: 3px;">Pause</button>
</div>
</div>
<div style="display:table-row;">
<div style="margin-top:6px;">
<button id="resetButton" type="button" style="width:45%;display:table-cell;margin-right:3px;">Reset</button>
<button id="eraseButton" type="button" style="float:right;width:45%;display:table-cell;margin-right:3px;">Remove</button>
</div>
</div>
<div style="display:table-row;">
<div style="margin-top:6px;">
<button id="appendButton" type="button" style="width:45%;display:table-cell;margin-right:3px;">Append</button>
<button id="deletButton" type="button" style="float:right;display:table-cell;margin-right: 3px; padding: 1px 3px;">Delete</button>
</div>
</div>
<div style="display:table-row;">
<div style="display: inline-block;">
<div style="font-size: 12px;margin-top:6px;">Time Elapsed</div>
<button id="time_speed_less" type="button" style="margin-right: 1px; padding: 1px 7px;">-</button>
<div id="x_time" style="font-size:12px; display:inline;padding: 5px;">x1</div>
<button id="time_speed_more" type="button" style="margin-right: 10px; padding: 1px 5px;">+</button>
</div>
</div>
<div style="display:table-row;">
<div style="display: inline-block;">
<div style="font-size: 12px;margin-top:6px;">Zoom</div>
<button id="zoom_less" type="button" style="margin-right: 5px; padding: 1px 7px;">-</button>
<button id="zoom_more" type="button" style="margin-right: 10px; padding: 1px 5px;">+</button>
</div>
<button id="moveToBtn" style="padding:1px 3px">Set View</button>
</div>
<div style="display:table-row;">
<div style="margin-top:6px;">
<button id="export" type="button" style="width:100%;">Export to ECEF</button>
<button id="exportData" type="button" style="width:100%;margin-top: 5px;">Download Raw Data</button>
<button id="exportGPX" type="button" style="width:100%;margin-top: 5px;">Export to GPX</button>
<button style="width:100%;margin-top: 5px;">
<label for="upload">
<div >Import data</div>
</label>
<input id="upload" type="file"/>
</button>
<button id="settings" type="button" style="width:100%;margin-top: 5px;">Settings</button>
<button id="whatisit" type="button" style="width:100%;margin-top: 5px">Documentation</button>
</div>
</div>
</div>
<!-- ############################################ -->
</div>
</div>
<div id="container" class="col-s-10" style="padding:0px;">
<div id="canvasContainer">
<div id="canvas"></div>
<div id="map"></div>
</div>
<div id="speed-panel">
</div>
</div>
</div>
</body>
<!-- script type="text/javascript" src="src/ecef_path_generator.js"></script-->
<script type="text/javascript">
/*********************************************************************
* ecef_path_generator.js *
* *
* Version: 2.0 *
* Date: 28-01-2022 review 10-11-2025 *
* Author: Dan Machado *
* Require raphaeljs v2.2.1 *
**********************************************************************/
function roundNumber(t,e){var n="number"==typeof e?e:2;return(Math.round(t*Math.pow(10,n))/Math.pow(10,n)).toFixed(e)}function readSingleFile(t){var e=t.target.files[0];e&&((t=new FileReader).readAsText(e,"UTF-8"),t.onload=function(t){drawer.upload(t.target.result.toString())})}const defaultZoom=13.5;function ReadCookie(){cookies={};for(var t,e,n=document.cookie.split(";"),o=0;o<n.length;o++)name=n[o].split("=")[0],cookies[name.trim()]=n[o].split("=")[1];return cookies.hasOwnProperty("latitude")&&cookies.hasOwnProperty("longitude")&&(t=Number(cookies.latitude),e=Number(cookies.longitude)),isNaN(t)||isNaN(e)?{lat:53.2672,lng:-1.63}:(document.getElementById("latitude").value=cookies.latitude,document.getElementById("longitude").value=cookies.longitude,{lat:t,lng:e})}function distance2DPoints(t,e,n,o){return Math.sqrt(Math.pow(t-n,2)+Math.pow(e-o,2))}var mkVect2D=function(){var o={x:0,y:0,add:function(t){this.x+=t.x,this.y+=t.y},subs:function(t){this.x-=t.x,this.y-=t.y},multiply:function(t){this.x*=t,this.y*=t},add2:function(t,e){this.x+=t,this.y+=e},length:function(){return distance2DPoints(this.x,this.y,0,0)},clone:function(){return mkVect2D(this.x,this.y)},normalise:function(){this.multiply(1/this.length())},distance:function(t){if("object"==typeof t)return distance2DPoints(this.x,this.y,t.x,t.y);throw"parameter passed is not an object."},setPositionAt:function(t,e){this.x=t,this.y=e},copyTo:function(t){t.x=this.x,t.y=this.y},print:function(){return"("+this.x+", "+this.y+")"}};return function(t,e){var n=Object.create(o);return n.setPositionAt(t,e),n}}();Conversion={a:1/60,b:1/3600,kmToDDNorth:function(){var o=110.574,i=o/60;return function(t){var e=t/o,n=Math.floor(e),e=t-n*o,t=Math.floor(e/i);return n+(60*t+(e-t*i)/.030715)/3600}}(),kmToDDEast:function(){var n,o,i,s,a=Math.PI/180;return function(t,e){s=111.321*Math.cos(a*t),n=s/60,o=s/3600,i=e/s;t=Math.floor(i);s=e-t*s;e=Math.floor(s/n);return t+(60*e+(s-e*n)/o)/3600}}(),toECEF:function(){var t=6378137,e=6356752.3,s=t*t,a=e*e,r=Math.PI/180;return function(t,e,n){var o=Math.sqrt(s*Math.pow(Math.cos(r*t),2)+a*Math.pow(Math.sin(r*t),2)),i=s/o,o=(i+n)*Math.cos(r*t)*Math.cos(r*e),e=(i+n)*Math.cos(r*t)*Math.sin(r*e),t=(a/s*i+n)*Math.sin(r*t);return roundNumber(o,3)+", "+roundNumber(e,3)+", "+roundNumber(t,3)}}()},Settings={alt:30,currentZoom:14.25,setAltitude:function(t){this.alt=Number(t)},initialZoom:function(){return 14.25},zoomDelta:function(){return.25},updateZoom:function(t){currentZoom+=t}},Settings;var map=L.map("map",{minZoom:0,zoomSnap:0,zoomDelta:.25,zoomControl:!1});!function(){var t=document.getElementById("container"),e=document.getElementById("speed-panel"),e=window.innerHeight-e.offsetHeight;t.style.height=document.body.clientHeight+"px",t.style.height=window.innerHeight+"px",document.getElementById("canvasContainer").style.height=e+"px",document.getElementById("canvas").style.height=e+"px",document.getElementById("map").style.height=e+"px",document.getElementById("left_pannel").style.height=e+"px",t=document.getElementById("canvas").clientWidth,globalSettings={canvas:document.getElementById("canvas"),baseZ:14.25,grid:[],Height:e,Width:t,scaleFactor:206,getScaleFactor:function(){return this.scaleFactor},gridSettings:{stroke:"#2929a3","stroke-width":.2,opacity:.6},paper:Raphael("canvas",t,e),wMtPx:0,hMtPx:0,mkGrid:function(){if(0<this.grid.length){for(var t=0;t<this.grid.length;t++)this.grid[t].remove();this.grid.length=0}var e=map.distance(map.containerPointToLatLng(L.point(0,0)),map.containerPointToLatLng(L.point(this.Width,0)));this.wMtPx=e/this.Width;e=map.distance(map.containerPointToLatLng(L.point(0,0)),map.containerPointToLatLng(L.point(0,this.Height)));this.hMtPx=e/this.Height;for(var n=1e3/this.hMtPx,o=Math.floor(this.Height/n),t=0;t<o;t++)this.grid.push(this.paper.path("M0,"+(t+1)*n+"L"+this.Width+","+(t+1)*n).attr(this.gridSettings));var i=1e3/this.wMtPx,s=Math.floor(this.Width/i);this.scaleFactor=Math.floor(i),this.scFacInv=1/this.scaleFactor;for(t=0;t<s;t++)this.grid.push(this.paper.path("M"+(t+1)*i+",0L"+(t+1)*i+","+this.Height).attr(this.gridSettings))},mtsToPxs:function(t){return.001*t*this.scaleFactor},kmsToPxs:function(t){return t*this.scaleFactor},pixelsToKms:function(t){return t*this.scFacInv},pixelsToMts:function(t){return 1e3*this.pixelsToKms(t)},containerPointToLatLng:function(t,e){var n=map.getCenter(),e=Number(n.lat+Conversion.kmToDDNorth((.5*this.Height-e)*this.scFacInv));return{lat:e,lng:Number(n.lng+Conversion.kmToDDEast(e,(t-.5*this.Width)*this.scFacInv))}},containerCenter:function(){return mkVect2D(.5*this.Width,.5*this.Height)},latLngToPixelCoordinates:function(t){var e=this.mtsToPxs(map.distance(t,map.getCenter())),n=this.containerCenter(),o=map.latLngToContainerPoint(t),i=e/distance2DPoints(n.x,n.y,o.x,o.y),t=i*Math.abs(n.x-o.x),e=i*Math.abs(n.y-o.y),i={x:n.x+t,y:n.y+e};return o.x<=n.x&&(i.x=n.x-t),o.y<=n.y&&(i.y=n.y-e),i},latLngToMtsCoordinates:function(t){var e=map.distance(t,map.getCenter()),n=this.containerCenter(),t=map.latLngToContainerPoint(t),e=e/distance2DPoints(n.x,n.y,t.x,t.y);return{x:e*(t.x-n.x),y:e*(n.y-t.y)}},mtsCoordinatesToPxs:function(t,e){return mkVect2D(this.mtsToPxs(t)+.5*this.Width,-1*this.mtsToPxs(e)+.5*this.Height)},mtsCooPxs:function(t,e,n){n(this.mtsToPxs(t)+.5*this.Width,-1*this.mtsToPxs(e)+.5*this.Height)},mtsCooPxs2:function(t,e){return{transform:"t"+(this.mtsToPxs(t)+.5*this.Width)+","+(-1*this.mtsToPxs(e)+.5*this.Height)}},getPosition:function(e){var n=this.canvas.getBoundingClientRect().left,o=this.canvas.getBoundingClientRect().top,i=n+this.Width,s=o+this.Height;function t(t){x=t.clientX,y=t.clientY,x>n&&x<i&&y>o&&y<s&&e(x-n,y-o)}function a(){document.onmouseup=null,document.onmousemove=null}canvas.onmousedown=function(){document.onmouseup=a,document.onmousemove=t}},getPosition3:function(t,e){var n=this.canvas.getBoundingClientRect().left,o=this.canvas.getBoundingClientRect().top,i=n+this.Width,s=o+this.Height;x=e.clientX,y=e.clientY,x>n&&x<i&&y>o&&y<s&&t(x-n,y-o)}},globalSettings}(),L.tileLayer("https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",{attribution:'© <a href="https://openstreetmap.org/copyright">OpenStreetMap contributors</a>'}).addTo(map),L.control.scale({maxWidth:300}).addTo(map);var mkObjectEvt=function(){var e={addHandler:function(t,e){this.handlers[t]=this.handlers[t]||[],this.handlers[t].push(e)},fire:function(t){for(var e in this.handlers[t])this.handlers[t][e].apply(null,Array.prototype.slice.call(arguments,1))}};return function(){var t=Object.create(e);return t.handlers={},t}}();controlModule=mkObjectEvt(),controlModule.playButton=document.getElementById("playButton"),controlModule.pauseButton=document.getElementById("pauseButton"),controlModule.recordButton=document.getElementById("recordButton"),controlModule.recordingButton=document.getElementById("recordingButton"),controlModule.deleteButton=document.getElementById("deletButton"),controlModule.eraseButton=document.getElementById("eraseButton"),controlModule.appendButton=document.getElementById("appendButton"),controlModule.resetButton=document.getElementById("resetButton"),controlModule.exportButton=document.getElementById("export"),controlModule.exportDataButton=document.getElementById("exportData"),controlModule.exportGPXButton=document.getElementById("exportGPX"),controlModule.disableButtons=function(t){controlModule.deleteButton.disabled=t,controlModule.eraseButton.disabled=t,controlModule.appendButton.disabled=t,controlModule.resetButton.disabled=t,controlModule.exportButton.disabled=t,controlModule.exportDataButton.disabled=t,controlModule.exportGPXButton.disabled=t},controlModule.addHandler("reset",function(){controlModule.pauseButton.style.display="none",controlModule.playButton.style.display="none",controlModule.recordingButton.style.display="none",controlModule.recordButton.style.display="block",controlModule.disableButtons(!1)}),controlModule.init=function(){document.getElementById("upload").addEventListener("change",readSingleFile);var e=globalSettings.baseZ;controlModule.setZoom=function(t){(e=.25*Math.floor(t/.25))<12&&(e=globalSettings.baseZ),map.setZoom(e)},document.getElementById("zoom_less").addEventListener("click",function(){11<=e-.25&&(e-=.25,map.setZoom(e))}),document.getElementById("zoom_more").addEventListener("click",function(){e+.25<=17&&(e+=.25,map.setZoom(e))});var n=1;controlModule.setSpeedTime=function(t){0<t&&t<6&&(n=t,controlModule.fire("timeFactor",n),document.getElementById("x_time").innerHTML="x"+n)},document.getElementById("time_speed_less").addEventListener("click",function(){1<n&&(n--,controlModule.setSpeedTime(n))}),document.getElementById("time_speed_more").addEventListener("click",function(){n<5&&(n++,controlModule.setSpeedTime(n))}),this.playButton.addEventListener("click",function(){controlModule.fire("play"),controlModule.playButton.style.display="none",controlModule.pauseButton.style.display="block"}),this.pauseButton.addEventListener("click",function(){controlModule.fire("pause"),controlModule.pauseButton.style.display="none",controlModule.playButton.style.display="block"}),this.recordButton.addEventListener("click",function(){controlModule.recordButton.style.display="none",controlModule.recordingButton.style.display="block",controlModule.disableButtons(!0),controlModule.fire("record")}),this.deleteButton.addEventListener("click",function(){controlModule.fire("delete"),controlModule.pauseButton.style.display="none",controlModule.playButton.style.display="none",controlModule.recordingButton.style.display="none",controlModule.recordButton.style.display="block",controlModule.eraseButton.disabled=!1,controlModule.appendButton.disabled=!1,controlModule.exportButton.disabled=!0,controlModule.exportDataButton.disabled=!0,controlModule.exportGPXButton.disabled=!0}),this.resetButton.addEventListener("click",function(){controlModule.fire("reset"),controlModule.exportButton.disabled=!0,controlModule.exportDataButton.disabled=!0,controlModule.exportGPXButton.disabled=!0}),this.eraseButton.addEventListener("click",function(){controlModule.fire("erase")}),this.appendButton.addEventListener("click",function(){controlModule.fire("append")}),this.addHandler("readyToPlay",function(){controlModule.pauseButton.style.display="none",controlModule.playButton.style.display="block"}),this.addHandler("recordingFinished",function(){controlModule.recordingButton.style.display="none",controlModule.recordButton.style.display="none",controlModule.playButton.style.display="block",controlModule.disableButtons(!1),controlModule.eraseButton.disabled=!0,controlModule.appendButton.disabled=!0})},controlModule.altitude=10,controlModule.setAltitude=function(t){controlModule.altitude=Math.abs(t),controlModule.fire("altitudeChanged",controlModule.altitude)},controlModule.changeAltitude=function(t){40==t?5<=controlModule.altitude&&(controlModule.altitude-=5):38==t&&(controlModule.altitude<1495?controlModule.altitude+=5:controlModule.altitude=1500),controlModule.fire("altitudeChanged",controlModule.altitude)},controlModule.exportButton.disabled=!0,controlModule.exportDataButton.disabled=!0,controlModule.exportGPXButton.disabled=!0,controlModule;var ZoomViewer=L.Control.extend({onAdd:function(){var t=L.DomUtil.create("div"),n=L.DomUtil.create("div");return t.style.width="200px",t.style.background="rgba(255,255,255,0.5)",t.style.tespeedTimeAlign="left",map.on("zoomstart zoom zoomend",function(t){var e=map.getZoom();n.innerHTML="Zoom level: "+e,controlModule.fire("scaleChange",e-globalSettings.baseZ)}),t.appendChild(n),t}});(new ZoomViewer).addTo(map);var popUpAPI,gadgetModule=function(){var i=mkObjectEvt();return i.distance=document.getElementById("distance"),i.totalDistance=document.getElementById("Tdistance"),i.speed=document.getElementById("speed"),i.altitude=document.getElementById("altitude"),i.elapsedTime=document.getElementById("elapsedtime"),i.averageSpeed=document.getElementById("average_speed"),i.active=!1,i.reset=!1,i.timer=function(){var e,n=0,o=1;i.resetR=function(){n=0},i.setFactor=function(t){o=1};return function(t){e=roundNumber(.001*(n+=o*t),2),gadgetModule.elapsedTime.innerHTML=e}}(),i.changeTimeFactor=function(t){i.factor=t,i.setFactor(t)},i.resetTimer=function(){i.factor=1,i.active=!1,i.resetR(),i.elapsedTime.innerHTML="0.00"},i.startTimer=function(){i.active=!0},i.stopTimer=function(){i.active=!1},i.updateAlt=function(t){i.altitude.innerHTML=t},i.updateSpeed=function(t){i.speed.innerHTML=t},i}(),mkPOI=function(){var r={geoPosition2D:null,POI:null,lat:"lat",lng:0,setAttr:function(t){this.POI.attr(t)},pointToLatLng:function(t,e){e=globalSettings.containerPointToLatLng(t,e);this.lat=e.lat,this.lng=e.lng},setPositionXY:function(t,e){this.POI.attr({transform:"t"+t+","+e}),this.POI.toFront(),this.pointToLatLng(t,e),this.geoPosition2D=globalSettings.latLngToMtsCoordinates({lat:this.lat,lng:this.lng})},setLatLng:function(t){this.lat=t.lat,this.lng=t.lng;t=globalSettings.latLngToPixelCoordinates(t);this.POI.attr({transform:"t"+t.x+","+t.y}),this.POI.toFront(),this.geoPosition2D=globalSettings.latLngToMtsCoordinates({lat:this.lat,lng:this.lng})},onZoom:function(){var t=globalSettings.latLngToPixelCoordinates({lat:this.lat,lng:this.lng});this.POI.attr({transform:"t"+t.x+","+t.y}),this.POI.toFront()},translate:function(t,e){this.POI.translate(t,e),this.POI.toFront(),this.geoPosition2D=globalSettings.latLngToMtsCoordinates({lat:this.lat,lng:this.lng})},getGeoX:function(){return this.geoPosition2D.x},getGeoY:function(){return this.geoPosition2D.y},positionToECEF:function(t){Conversion.toECEF(this.lat,this.lng,t)},remove:function(){this.POI.remove()},getLatLng:function(){return{lat:this.lat,lng:this.lng}},setColour:function(t){this.POI.attr({stroke:"none",fill:t})}};return function(t,e,n,o){var i=Object.create(r),s=2,a={stroke:"none"};return void 0!==n&&"object"==typeof n&&(a=n,void 0!==o&&(s=o)),i.POI=globalSettings.paper.circle(0,0,s),i.POI.attr(a),i.setPositionXY(t,e),i}}();!function(){var n,o,i;Trail={set:[],directions:[],looping:function(t){for(var e=0;e<this.set.length;e++)t(this.set[e])},onZoom:function(){this.looping(function(t){t.onZoom()}),this.mover.attr(globalSettings.mtsCooPxs2(this.currentGeoPos.x,this.currentGeoPos.y)),this.mover.toFront()},onTranslate:function(e,n){this.looping(function(t){t.translate(e,n)}),this.mover.translate(e,n),this.mover.toFront()},reset:function(){this.looping(function(t){t.remove()}),this.set.length=0,this.directions.length=0,this.trailLength=0,this.segmentNum=0,this.distanceMt=0},removeLast:function(){var t;0<this.set.length&&(0<(t=this.set.length-1)&&(this.trailLength-=this.segmentMtLength(t-1)),this.set[t].remove(),this.set.pop())},trailPOIcolour:"#ffb366",trailLength:0,mover:null,init:function(){this.mover=globalSettings.paper.circle(0,0,2),this.mover.attr({stroke:"none",fill:"blue"}),this.mover.attr({transform:"t-100,-100"})},addPoint:function(t,e){this.set.push(mkPOI(t,e,{stroke:"none",fill:this.trailPOIcolour})),this.setUp()},addPointLatLng:function(t){this.set.push(mkPOI(0,0,{stroke:"none",fill:this.trailPOIcolour}));var e=this.set.length-1;this.set[e].setLatLng(t),this.setUp()},setUp:function(){var t;1<this.set.length&&(t=this.set.length-1,this.directions.push(mkVect2D(this.getGeoX(t)-this.getGeoX(t-1),this.getGeoY(t-1)-this.getGeoY(t))),this.trailLength+=this.segmentMtLength(t-1),t=this.directions.length-1,this.directions[t].normalise())},getTrailLengthKm:function(){return.001*this.trailLength},segmentMtLength:function(t){if(t<this.set.length-1)return distance2DPoints(this.getGeoX(t),this.getGeoY(t),this.getGeoX(t+1),this.getGeoY(t+1));throw"something wrong in segmentMtLength"},getGeoX:function(t){return this.set[t].getGeoX()},getGeoY:function(t){return this.set[t].getGeoY()},getLastGeoX:function(){return this.set[this.set.length-1].getGeoX()},getLastGeoY:function(){return this.set[this.set.length-1].getGeoY()},currentGeoPos:mkVect2D(0,0),moveToStart:function(){0<this.set.length&&(this.currentGeoPos.setPositionAt(this.getGeoX(0),this.getGeoY(0)),this.mover.attr(globalSettings.mtsCooPxs2(this.currentGeoPos.x,this.currentGeoPos.y)),this.mover.toFront(),this.segmentNum=0)},moveToNext:function(t){this.currentGeoPos.add(this.deltaGeo),this.mover.animate(globalSettings.mtsCooPxs2(this.currentGeoPos.x,this.currentGeoPos.y),t,"linear"),this.mover.toFront()},segmentNum:0,distanceMt:0,deltaGeo:mkVect2D(0,0),getDelta:function(t,e){return this.segmentNum+1==this.set.length?{time:-1}:(this.distanceMt<=0&&(this.distanceMt=this.segmentMtLength(this.segmentNum)),o=t*(1/3600),n=this.distanceMt/o,i=!0,250<n&&(550<n?i=!(n=300):420<n&&(n*=.5,i=!1)),o=o*n,this.distanceMt-=o,this.directions[this.segmentNum].copyTo(this.deltaGeo),this.deltaGeo.multiply(o),this.deltaGeo.y*=-1,this.moveToNext(n,e),i&&(this.distanceMt=0,this.segmentNum++),{time:n,distance:.001*o,geoX:this.currentGeoPos.x,geoY:this.currentGeoPos.y})},exportData:function(){for(var t=[],e=0;e<this.set.length;e++)t.push(this.set[e].getLatLng());return t},setColours:function(t,e){if(""!=e&&this.mover.attr({stroke:"none",fill:e}),""!=t){this.trailPOIcolour=t;for(var n=0;n<this.set.length;n++)this.set[n].setColour(this.trailPOIcolour)}}},Trail}();var drawer={speedTime:2,status:0,getPositionFromPointer:!1,offSetX:-1.63,offSetY:53.2672,altitude:10,init:function(){globalSettings.getPosition(function(t,e){drawer.getData(t,e)}),Trail.init(),controlModule.init(),this.setSpeed(10),controlModule.addHandler("timeFactor",function(t){drawer.speedTime=t,gadgetModule.changeTimeFactor(t)}),controlModule.setSpeedTime(0),controlModule.addHandler("play",function(){drawer.getPositionFromPointer=!1,document.getElementById("moveToBtn").style.fontWeight="normal",drawer.play()}),controlModule.addHandler("record",function(){drawer.isRecording=!0,drawer.getPositionFromPointer=!1,document.getElementById("moveToBtn").style.fontWeight="normal",drawer.record()}),controlModule.addHandler("pause",function(){drawer.halt()}),controlModule.addHandler("reset",function(){drawer.reset()}),controlModule.addHandler("delete",function(){drawer.erase()}),controlModule.addHandler("erase",function(){drawer.deleteLast()}),controlModule.addHandler("append",function(){drawer.append()}),controlModule.addHandler("scaleChange",function(t){drawer.mapReady()&&(globalSettings.mkGrid(),Trail.onZoom())}),controlModule.addHandler("altitudeChanged",function(t){drawer.altitude=t,gadgetModule.updateAlt(t)}),controlModule.setAltitude(10)},mxG:10,speedData:[],altData:[],lastX:0,lastY:0,getData:function(t,e){if(!(0<this.status||this.getPositionFromPointer)){var n,o=0;if(0<this.head&&(n=globalSettings.mtsCoordinatesToPxs(Trail.getGeoX(this.head-1),Trail.getGeoY(this.head-1)),this.lastX=n.x,this.lastY=n.y,o=distance2DPoints(this.lastX,this.lastY,t,e)),o>this.mxG){this.head;var i=Math.ceil(o/this.mxG),s=1;t-this.lastX<0&&(s=-1);var a=1;e-this.lastY<0&&(a=-1);for(var r=Math.abs(t-this.lastX)/i,d=Math.abs(e-this.lastY)/i,l=1;l<i;l++)Trail.addPoint(this.lastX+l*r*s,this.lastY+l*d*a),this.head++}(o>this.mxG||0==this.head)&&(Trail.addPoint(t,e),this.head++,gadgetModule.totalDistance.innerHTML=roundNumber(Trail.getTrailLengthKm(),2))}},deleteLast:function(){0<this.status&&1<this.head||(this.head--,Trail.removeLast(),0<this.head&&(gadgetModule.totalDistance.innerHTML=roundNumber(Trail.getTrailLengthKm(),2)))},append:function(){this.status=0},counter:0,head:0,paused:!1,halt:function(){this.paused=!0},isRunning:!1,speed:1,play:function(){this.paused&&(gadgetModule.startTimer(),this.paused=!1,this.run()),this.isRunning||(this.counter=0,this.wkDistance=0,this.status=1,gadgetModule.resetTimer(),gadgetModule.startTimer(),Trail.moveToStart(),0<this.speed&&(this.isRunning=!0,this.counter++,this.run()))},wkDistance:0,run:function(){var t=!0,e=0,n=0;return function(){this.paused||(t?(dt=Trail.getDelta(this.speedData[e+1],this.speedTime),t=0<=dt.time&&e<this.speedData.length,0<dt.time?(setTimeout(function(){this.run()}.bind(this),dt.time/this.speedTime),this.wkDistance+=dt.distance):(this.run(),t=!0,n=e=0),this.isRunning&&(gadgetModule.speed.innerHTML=roundNumber(this.speedData[e],2),gadgetModule.updateAlt(this.altData[e++])),gadgetModule.distance.innerHTML=roundNumber(this.wkDistance,2),gadgetModule.timer(n),n=dt.time):(gadgetModule.timer(n),this.isRunning&&controlModule.fire("readyToPlay"),this.isRunning=!1))}}(),canMove:function(){return!this.isRunning&&!this.isRecording},resetRecording:!0,dataR:[],timeOutID:0,isRecording:!1,record:function(){var t=!0,e=0;return function(){if(0==this.head)return controlModule.fire("reset"),void(this.isRecording=!1);this.resetRecording&&(t=!0,e=0,this.resetRecording=!1,this.dataR.length=0,this.dataR.push([Trail.getGeoX(0),Trail.getGeoY(0)]),this.speedData.length=0,this.speedData.push(this.speed),this.altData.length=0,this.altData.push(this.altitude),Trail.moveToStart(),this.status=1,gadgetModule.startTimer()),t?(this.altData.push(this.altitude),this.speedData.push(this.speed),dt=Trail.getDelta(this.speed,this.speedTime),t=0<=dt.time,0<dt.time?(this.dataR.push([dt.geoX,dt.geoY]),this.timeOutID=setTimeout(function(){this.record()}.bind(this),dt.time/this.speedTime),this.wkDistance+=dt.distance):this.record(),gadgetModule.timer(e),e=dt.time,gadgetModule.distance.innerHTML=roundNumber(this.wkDistance,2)):(this.altData.push(this.altitude),this.speedData.push(this.speed),this.dataR.push([Trail.getLastGeoX(),Trail.getLastGeoY()]),controlModule.fire("recordingFinished"),this.isRecording=!1)}}(),clearData:function(){this.dataR.length=0,this.speedData.length=0,this.altData.length=0},erase:function(){this.clearData(),this.resetRecording=!0,this.head=0,Trail.reset(),gadgetModule.totalDistance.innerHTML="0.00",gadgetModule.distance.innerHTML="0.00",this.counter=0,this.wkDistance=0,this.isRunning=!1,this.paused=!1,this.status=0,gadgetModule.resetTimer(),this.setSpeed(10)},reset:function(){this.clearData(),this.resetRecording=!0,gadgetModule.distance.innerHTML="0.00",Trail.moveToStart(),this.counter=0,this.wkDistance=0,this.isRunning=!1,this.paused=!1,gadgetModule.resetTimer(),gadgetModule.speed.innerHTML=roundNumber(this.speed,2)},segmentLength:function(t,e){return Math.sqrt(Math.pow(t[0]-e[0],2)+Math.pow(t[1]-e[1],2))},changeFrequency:function(t){this.frequency=t},isMapReady:!1,mapReady:function(){return this.isMapReady},setCoordinates:function(t,e,n){this.offSetX=Number(e),this.offSetY=Number(t),map.setView([Number(t),Number(e)],n),this.isMapReady=!0,globalSettings.mkGrid()},frequency:10,toECEF:!0,processData:function(t){if(0!=this.dataR.length){var e,n=1/this.frequency,o=!1,i=n,s=[],a=Number(0),r=this.offSetY+Conversion.kmToDDNorth(.001*this.dataR[0][1]),d=this.altData[0];this.toECEF?(s.push([a.toFixed(1),Conversion.toECEF(r,this.offSetX+Conversion.kmToDDEast(r,.001*this.dataR[0][0]),d)]),a+=.1):s.push([r,this.offSetX+Conversion.kmToDDEast(r,.001*this.dataR[0][0]),d]);for(var l=1;l<this.dataR.length;l++)if(d=this.altData[l],e=this.segmentLength(this.dataR[l],this.dataR[l-1]),!isNaN(e)){var u=this.speedData[l-1]*(10/36);if(0!=u){for(var c,h,m=e/u,g=i*u,p=(c=(this.dataR[l][0]-this.dataR[l-1][0])/e)*g,f=(h=(this.dataR[l][1]-this.dataR[l-1][1])/e)*g,y=this.dataR[l-1][0],x=this.dataR[l-1][1];0<=m-i;)y+=p,x+=f,r=this.offSetY+Conversion.kmToDDNorth(.001*x),this.toECEF?(s.push([a.toFixed(1),Conversion.toECEF(r,this.offSetX+Conversion.kmToDDEast(r,.001*y),d)]),a+=.1):s.push([r,this.offSetX+Conversion.kmToDDEast(r,.001*y),d]),m-=i,o&&(p=c*(i=n)*u,f=h*i*u,o=!1);m<i&&.001<m&&(o=!0,i=n-m)}}for(var M="",v=a.toFixed(1).toString().length,l=0;l<s.length;l++)this.toECEF?M+=s[l][0].toString().padStart(v," ")+","+s[l][1]+"\n":M+=s[l][0]+", "+s[l][1]+"\n";this.toECEF?download(t+".csv",M,"application/csv;charset=utf-8;"):download(t+".txt",M,"data:text/plain;charset=utf-8;")}else alert("No data recorded.")},downloadData:function(e,n){var o={};if(o.trail=Trail.exportData(),o.recordedData=this.dataR,o.speedData=this.speedData,o.altitudeData=this.altData,o.timeData=this.timeData,o.coordinates={lat:this.offSetY,lng:this.offSetX},o.zoom=map.getZoom(),"txt"!=n){const l=new Date;var i=l.toISOString();let t='<?xml version="1.0"?><gpx xmlns="http://www.topografix.com/GPX/1/1" xmlns:gpxx="http://www.garmin.com/xmlschemas/GpxExtensions/v3" xmlns:gpxtrkx="http://www.garmin.com/xmlschemas/TrackStatsExtension/v1" xmlns:gpxtpx="http://www.garmin.com/xmlschemas/TrackPointExtension/v1" creator="ECEF Path Generator" version="2.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd http://www.garmin.com/xmlschemas/GpxExtensions/v3 http://www8.garmin.com/xmlschemas/GpxExtensionsv3.xsd http://www.garmin.com/xmlschemas/TrackStatsExtension/v1 http://www8.garmin.com/xmlschemas/TrackStatsExtension.xsd http://www.garmin.com/xmlschemas/TrackPointExtension/v1 http://www.garmin.com/xmlschemas/TrackPointExtensionv1.xsd"><metadata><link href="https://github.com/fpdf-easytable/ECEF_path_generator"><text>ECEF Path Generator</text></link>';t+="<time>"+i+"</time>",t+="<desc>"+document.getElementById("gpxDesc").value.trim()+"</desc>",t+="</metadata><trk>",document.getElementById("gpxDesc").value="";for(var n=roundNumber(this.wkDistance,3),i=document.getElementById("elapsedtime").innerHTML,s=0,a=0;a<o.speedData.length;a++)s<o.speedData[a]&&(s=o.speedData[a]);for(var r=0,d=1e5,a=0;a<o.altitudeData.length;a++)r<o.altitudeData[a]&&(r=o.altitudeData[a]),o.altitudeData[a]<d&&(d=o.altitudeData[a]);t+="<name>"+e+"</name><extensions><gpxx:TrackExtension>",t+="<gpxx:DisplayColor>Blue</gpxx:DisplayColor></gpxx:TrackExtension><gpxtrkx:TrackStatsExtension>",t+="<gpxtrkx:Distance>"+n+"</gpxtrkx:Distance>",t+="<gpxtrkx:TotalElapsedTime>"+i+"</gpxtrkx:TotalElapsedTime>",t+="<gpxtrkx:MaxSpeed>"+s+"</gpxtrkx:MaxSpeed>",t+="<gpxtrkx:MaxElevation>"+r+"</gpxtrkx:MaxElevation>",t+="<gpxtrkx:MinElevation>"+d+"</gpxtrkx:MinElevation>",t+="</gpxtrkx:TrackStatsExtension></extensions><trkseg>";for(a=0;a<o.trail.length;a++)t+='<trkpt lat="'+o.trail[a].lat+'" lon="'+o.trail[a].lng+'"></trkpt>';t+="</trkseg></trk></gpx>",download(e+".gpx",t,"data:text/xml;charset=utf-8;")}else download(e+".txt",JSON.stringify(o),"data:text/plain;charset=utf-8;")},upload:function(t){var e;this.erase();try{e=JSON.parse(t.toString())}catch(t){return void alert("File could not be loaded because it has bad syntax or it's corrupted.")}if(e.hasOwnProperty("coordinates")){let t=defaultZoom;e.hasOwnProperty("zoom")&&(t=e.zoom),this.setCoordinates(e.coordinates.lat,e.coordinates.lng,t)}if(this.head=0,e.hasOwnProperty("trail"))for(var n=0;n<e.trail.length;n++)Trail.addPointLatLng(e.trail[n]),this.head++;e.hasOwnProperty("recordedData")&&(this.dataR=e.recordedData),e.hasOwnProperty("speedData")&&(this.speedData=e.speedData,this.speed=this.speedData[0],gadgetModule.speed.innerHTML=roundNumber(this.speedData[0],2)),e.hasOwnProperty("altitudeData")&&(this.altData=e.altitudeData),gadgetModule.totalDistance.innerHTML=roundNumber(Trail.getTrailLengthKm(),2),Trail.moveToStart(),controlModule.fire("recordingFinished")},speedStep:.5,speedStep5:5,speedStep2:2,speedStep1:1,maxSpeed:350,changeSpeed:function(t){var e=.5;81==t||87==t?e=this.speedStep5:65==t||83==t?e=this.speedStep2:88==t||90==t?e=this.speedStep1:37!=t&&39!=t||(e=this.speedStep),(37!=t&&81!=t&&65!=t&&90!=t?1:-1)<0?(this.speed>=e&&(this.speed-=e),this.speed<=0&&(this.speed=.5)):this.speed<=this.maxSpeed-e?this.speed+=e:this.speed=this.maxSpeed,document.getElementById("speed").innerHTML=roundNumber(this.speed,2)},setSpeed:function(t){this.speed=Math.abs(t),document.getElementById("speed").innerHTML=roundNumber(this.speed,2)}};function download(t,e,n){e=new Blob([e],{type:n});window.navigator.msSaveBlob?navigator.msSaveBlob(e,t):((n=document.createElement("a")).setAttribute("href",URL.createObjectURL(e)),n.setAttribute("download",t),n.style.display="none",document.body.appendChild(n),n.click(),document.body.removeChild(n)),popUpAPI.closing()}drawer.init(),controlModule.setZoom(13.5),window.addEventListener("keydown",function(t){38==t.keyCode||40==t.keyCode?controlModule.changeAltitude(t.keyCode):37!=t.keyCode&&39!=t.keyCode&&81!=t.keyCode&&87!=t.keyCode&&65!=t.keyCode&&83!=t.keyCode&&88!=t.keyCode&&90!=t.keyCode||drawer.changeSpeed(t.keyCode)}),document.onkeydown=function(t){t=(t=t||window.event).keyCode;if(37<=t&&t<=40)return!1},window.addEventListener("DOMContentLoaded",function(){var e,n,t,o;window.scrollTo(0,0),e=document.getElementById("dim"),n=document.getElementById("pop_wrapper"),t=document.getElementById("pop_up"),o=document.getElementById("popup_content"),n.style.top=.1*window.innerHeight+"px",t.style.maxHeight=.8*window.innerHeight+"px",popUpAPI={display:function(){e.style.display="block",n.style.visibility="visible"},closing:function(t){void 0===t?(n.style.visibility="hidden",e.style.display="none",document.getElementById("ecef").style.display="none",document.getElementById("rawData").style.display="none",document.getElementById("gpxData").style.display="none",document.getElementById("configuration").style.display="none",document.getElementById("description").style.display="none"):t.stopPropagation()},exportECEF:function(){document.getElementById("popup_title").innerHTML="Export to ECEF",document.getElementById("ecef").style.display="block",this.display()},processECEF:function(){var t=document.getElementById("frequency"),e=document.getElementById("fileName"),n=Number(t.value.trim());Number.isInteger(n)&&0!=n?e.value.trim()?(popUpAPI.wait(),drawer.changeFrequency(n),drawer.processData(e.value.trim()),t.value="",e.value=""):alert("Please enter a valid file name."):alert("Please enter a valid integer frequency.")},download:function(){document.getElementById("popup_title").innerHTML="Download Path Configuration",document.getElementById("rawData").style.display="block",this.display()},downloadGPX:function(){document.getElementById("popup_title").innerHTML="Download Path GPX",document.getElementById("gpxData").style.display="block",this.display()},settingsECEF:function(){document.getElementById("popup_title").innerHTML="Settings",document.getElementById("configuration").style.display="block",this.display()},whatisit:function(){document.getElementById("popup_title").innerHTML="Description",document.getElementById("description").style.display="block",this.display()},wait:function(){document.getElementById("popup_title").innerHTML="Processing data",this.display()},processDownload:function(t,e,n){t.value.trim()?(drawer.downloadData(t.value.trim(),n),t.value="",this.closing(),document.getElementById(e).style.display="none"):alert("Please enter a valid file name.")}},document.getElementById("closePopUp").addEventListener("click",function(){popUpAPI.closing()}),e.addEventListener("click",function(){popUpAPI.closing()}),n.addEventListener("click",function(){popUpAPI.closing()}),o.addEventListener("click",function(t){popUpAPI.closing(t)}),document.getElementById("export").addEventListener("click",function(){popUpAPI.exportECEF()}),document.getElementById("settings").addEventListener("click",function(){popUpAPI.settingsECEF()}),document.getElementById("ecefButton").addEventListener("click",function(){popUpAPI.processECEF()}),document.getElementById("exportData").addEventListener("click",function(){popUpAPI.download()}),document.getElementById("exportGPX").addEventListener("click",function(){popUpAPI.downloadGPX()}),document.getElementById("moveToBtn").addEventListener("click",function(){drawer.getPositionFromPointer=!drawer.getPositionFromPointer&&drawer.canMove(),drawer.getPositionFromPointer?document.getElementById("moveToBtn").style.fontWeight="bold":document.getElementById("moveToBtn").style.fontWeight="normal"}),document.getElementById("canvasContainer").addEventListener("mousedown",function(t){drawer.getPositionFromPointer&&globalSettings.getPosition3(function(e,n){var t=globalSettings.containerPointToLatLng(e,n);drawer.setCoordinates(t.lat,t.lng,map.getZoom()),map.once("moveend",function(){var t=globalSettings.containerCenter();t.add2(-1*e,-1*n),Trail.onTranslate(t.x,t.y)}.bind(this))},t)}),document.getElementById("whatisit").addEventListener("click",function(){popUpAPI.whatisit()}),document.getElementById("rawDataButton").addEventListener("click",function(){popUpAPI.processDownload(document.getElementById("fileNameR"),"rawData","txt")}),document.getElementById("gpxDataButton").addEventListener("click",function(){popUpAPI.processDownload(document.getElementById("gpxNameR"),"gpxData","gpx")}),document.getElementById("locationButton").addEventListener("click",function(){var t=Number(document.getElementById("latitude").value),e=Number(document.getElementById("longitude").value);Number.isNaN(t)||Number.isNaN(e)?alert("Please enter a valid number."):(drawer.setCoordinates(t,e,defaultZoom),document.cookie="longitude="+e,document.cookie="latitude="+t)}),document.getElementById("coloursButton").addEventListener("click",function(){var t=document.getElementById("trail_colour").value,e=document.getElementById("mover_colour").value;""==(t=t.trim())&&(t="#ffb366"),""==(e=e.trim())&&(e="blue"),Trail.setColours(t,e)}),""==document.cookie&&(document.cookie="whatisit=yes"),o=ReadCookie(),drawer.setCoordinates(o.lat,o.lng,defaultZoom)});
</script>
</html>