1
1
// ------------ Copywrite Dominik Honzak (c) 2024 ------------ //
2
2
//Created Entirely from scratch by Dominik Honzak//
3
3
4
-
5
4
const replaceGit = "/EagleProject" ; /* /EagleProject
6
5
*/
7
6
const basic = {
@@ -56,7 +55,8 @@ const mapArray = document.getElementById("maps");
56
55
const mapDetails = {
57
56
name : document . getElementById ( "mapname" ) ,
58
57
display : document . getElementById ( "mapdisplay" ) ,
59
- detail : document . getElementById ( "mapdetail" )
58
+ detail : document . getElementById ( "mapdetail" ) ,
59
+ leaders : document . getElementById ( "mapleaders" )
60
60
} ;
61
61
const resultsPage = {
62
62
controls : document . getElementById ( "courseControlLength_off" ) ,
@@ -206,7 +206,7 @@ const loadMap = function(i) {
206
206
else {
207
207
mapDetails . display . src = basic . maps [ i ] [ "Map" ] ;
208
208
}
209
-
209
+ mapDetails . leaders . onclick = function ( ) { openLeaderboard ( basic . maps [ i ] [ "Name" ] ) ; } ;
210
210
mapDetails . detail . innerHTML = "" ;
211
211
tab ( 3 ) ;
212
212
@@ -332,7 +332,7 @@ let accuracyLat = (accuracy/(2*Math.PI*6371000*Math.cos(toRad(targetLat))/360)).
332
332
}
333
333
else {
334
334
335
- testing . innerHTML = ( "off by: " + calculateDistance ( currentLat , currentLong , targetLat , targetLong ) + `m<div onclick='warning("Cords","` + currentLat . toFixed ( 6 ) + ", " + currentLong . toFixed ( 6 ) + ` <br> ` + targetLat . toFixed ( 6 ) + ", " + targetLong . toFixed ( 6 ) + `",false);'>testing</div>` ) ;
335
+ // testing.innerHTML = ("off by: "+calculateDistance(currentLat,currentLong,targetLat,targetLong)+`m<div onclick='warning("Cords","`+currentLat.toFixed(6)+", "+currentLong.toFixed(6)+` <br> `+targetLat.toFixed(6)+", "+targetLong.toFixed(6)+`",false);'>testing</div>`);
336
336
if ( ! ( position . coords . accuracy <= 15 ) ) {
337
337
tab ( 11 ) ;
338
338
setTimeout ( function ( ) {
@@ -359,7 +359,7 @@ const showError = function(error) {
359
359
case error . UNKNOWN_ERROR :
360
360
break ;
361
361
}
362
- warning ( "Location Request" , "Your device likely does not have location services enabled.</p><b class='grey'>IOS : </b>aA → Settings → Scroll Down → Location → Allow<br><b class='grey'>Android: </b>⋮ → Scroll Down → ⓘ → Permissions → Location → On" , true ) ;
362
+ warning ( "Location Request" , "Your device likely does not have location services enabled.</p><b class='grey'>Safari : </b>aA → Settings → Scroll Down → Location → Allow<br><b class='grey'>Android: </b>⋮ → Scroll Down → ⓘ → Permissions → Location → On" , true ) ;
363
363
} ;
364
364
const getLocation = function ( ) {
365
365
if ( navigator . geolocation ) {
@@ -401,11 +401,28 @@ const endCourse = function() {
401
401
document . getElementsByClassName ( 'time' ) [ 0 ] . textContent = "Time: " + ( parseInt ( cc / 60 ) + ':' + cc1 ) ;
402
402
resultsPage . controls . textContent = orienteering [ "Controls" ] . length ;
403
403
resultsPage . distance . textContent = orienteering [ "distance" ] . toFixed ( 1 ) + " / " + orienteering [ "length" ] . toFixed ( 1 ) + " km" ;
404
- resultsPage . elevation . textContent = orienteering [ "elevation" ] . reduce ( ( acc , curr ) => acc + curr , 0 ) . toFixed ( 1 ) + "m" ;
404
+ const elevations = orienteering [ "elevation" ] ;
405
+ let elevationGain = 0 ;
406
+ let elevationLoss = 0 ;
407
+
408
+ for ( let i = 1 ; i < elevations . length ; i ++ ) {
409
+ const diff = elevations [ i ] - elevations [ i - 1 ] ;
410
+ if ( diff > 0 ) {
411
+ elevationGain += diff ;
412
+ } else {
413
+ elevationLoss -= diff ; // Using subtraction to handle negative differences
414
+ }
415
+ }
416
+
417
+ const gainString = elevationGain . toFixed ( 1 ) + "m" ;
418
+ const lossString = elevationLoss . toFixed ( 1 ) + "m" ;
419
+ resultsPage . elevation . textContent = gainString ;
405
420
resultsPage . split . textContent = Math . round ( cc / ( orienteering [ "Controls" ] . length - 1 ) ) + "s" ;
406
421
407
422
408
- localStorage . clear ( ) ;
423
+ // Now use `imported.insertData` to call the function
424
+ insertData ( orienteering , warning ) ;
425
+
409
426
} ;
410
427
const repeating = function ( ) {
411
428
getLocation ( ) ;
@@ -419,7 +436,7 @@ const loadCourse = function() {
419
436
document . getElementById ( "courseControlLength_on" ) . textContent = ( basic . maps [ orienteering [ "courseindex" ] ] [ "Controls" ] . length - 2 ) ;
420
437
document . getElementById ( "courseDistance_on" ) . textContent = orienteering [ "length" ] . toFixed ( 1 ) + " km" ;
421
438
document . getElementById ( "courseDifficulty_on" ) . style . background = basic . colorhue [ orienteering [ "difficulty" ] ] ;
422
- warning ( "Warning" , "We suggest that you refrain from staring at your phone while doing the course as this may result in injury. Be aware that some controls are placed off of paths. Conditions such as weather may impact how dangerous a course is. <br>Please be aware that although this is a website it will still save your course where you left off so you can turn off your phone while running. (if the screen is off distance mesurement will be slightly off )" , true ) ;
439
+ warning ( "Warning" , "We suggest that you refrain from staring at your phone while doing the course as this may result in injury. Be aware that some controls are placed off of paths. Conditions such as weather may impact how dangerous a course is. <br>Please be aware that although this is a website it will still save your course where you left off so you can turn off your phone while running. (please be aware distance measurement may have issues )" , true ) ;
423
440
} ;
424
441
const openOptions = function ( ) {
425
442
tab ( 9 ) ;
@@ -493,6 +510,7 @@ basic.maps = JSON.parse(responseText)["Maps"];
493
510
}
494
511
else {
495
512
orienteering = JSON . parse ( `{
513
+ "name":"Anonymous",
496
514
"course":"",
497
515
"courseindex":null,
498
516
"difficulty":0,
@@ -596,4 +614,15 @@ const hotCold = function(dist) {
596
614
document . querySelector ( ':root' ) . style . setProperty ( '--bg_overlay' , "rgba(" + rgb . r + "," + rgb . g + "," + rgb . b + ",0.65)" ) ;
597
615
//change background overlay color
598
616
}
617
+ } ;
618
+ const openLeaderboard = function ( crs ) {
619
+ tab ( 16 ) ;
620
+ requestData ( crs ) ;
621
+ } ;
622
+ const setName = function ( ) {
623
+ const val = document . getElementById ( "name" ) . value ;
624
+ if ( val ) {
625
+ orienteering [ "name" ] = document . getElementById ( "name" ) . value ;
626
+ }
627
+ tab ( 6 ) ; loadCourse ( ) ;
599
628
} ;
0 commit comments