@@ -203,8 +203,7 @@ function map_function(lat, lng, id) {
203
203
}
204
204
} ;
205
205
geolocation ( geolocation_cb ) ;
206
-
207
- L . marker ( [ lat , lng ] ) . addTo ( map ) ;
206
+ if ( lat != 0 && lng != 0 ) L . marker ( [ lat , lng ] ) . addTo ( map ) ;
208
207
map . setView ( [ lat , lng ] ) ;
209
208
210
209
articles . map ( ( e ) => {
@@ -348,6 +347,8 @@ async function fetchGraphQL(query, variables) {
348
347
body : JSON . stringify ( { query, variables } ) ,
349
348
} ) ;
350
349
350
+ const requestBody = JSON . stringify ( { query, variables } ) ;
351
+
351
352
if ( ! response . ok ) {
352
353
console . error ( `HTTP error! status: ${ response . status } ` ) ;
353
354
return { errors : [ { message : `HTTP ${ response . status } ` } ] } ;
@@ -544,11 +545,10 @@ async function fetchAreas(searchValue) {
544
545
}
545
546
}
546
547
547
- /*
548
548
let operationsDocLocation = `
549
549
query MyQuery($lat: Float!, $lng: Float!) {
550
550
cragsNear(
551
- maxDistance: 10000000
551
+ maxDistance: 100000
552
552
minDistance: 0
553
553
includeCrags: true
554
554
lnglat: { lat: $lat, lng: $lng }
@@ -558,13 +558,24 @@ let operationsDocLocation = `
558
558
areaName
559
559
totalClimbs
560
560
pathTokens
561
+ uuid
562
+ id
563
+ climbs {
564
+ id
565
+ name
566
+ pathTokens
567
+ uuid
568
+ }
569
+ children {
570
+ id
571
+ }
561
572
metadata {
562
573
lng
563
574
lat
564
575
isBoulder
565
576
leftRightIndex
566
577
}
567
- uuid
578
+
568
579
}
569
580
}
570
581
}
@@ -585,9 +596,48 @@ async function fetchAreasByLocation(lat, lng) {
585
596
return { success : false , error : error . message } ;
586
597
}
587
598
}
588
- */
589
- // Test
590
- //fetchAreasByLocation(43, -79).then((result) => console.log(result));
599
+
600
+ const operationsDocId = `
601
+ query MyQuery($uuid: ID!) {
602
+ area(uuid: $uuid) {
603
+ climbs {
604
+ uuid
605
+ name
606
+ boltsCount
607
+ gradeContext
608
+ length
609
+ fa
610
+ type {
611
+ bouldering
612
+ sport
613
+ trad
614
+ }
615
+ grades {
616
+ brazilianCrux
617
+ ewbank
618
+ font
619
+ french
620
+ uiaa
621
+ vscale
622
+ yds
623
+ }
624
+ }
625
+ }
626
+ }
627
+ ` ;
628
+
629
+ async function fetchAreasById ( uuid ) {
630
+ try {
631
+ const variables = { uuid : uuid } ; // Passing uuid as a variable
632
+ const { errors, data } = await fetchGraphQL ( operationsDocId , variables ) ;
633
+
634
+ if ( errors ) throw new Error ( JSON . stringify ( errors ) ) ;
635
+
636
+ return { success : true , data } ;
637
+ } catch ( error ) {
638
+ console . error ( "Error:" , error ) ; // Handle errors
639
+ }
640
+ }
591
641
592
642
var root = document . getElementById ( "app" ) ;
593
643
@@ -954,6 +1004,7 @@ let articles = [];
954
1004
let current_article ;
955
1005
956
1006
let searchTerm = "" ;
1007
+ let searchTerm_id = "" ;
957
1008
let stats = "" ;
958
1009
let focused_article ;
959
1010
localforage
@@ -964,6 +1015,10 @@ localforage
964
1015
. catch ( ( ) => { } ) ;
965
1016
966
1017
const start = {
1018
+ onbeforeremove : function ( ) {
1019
+ status . previousView = "/start" ;
1020
+ } ,
1021
+
967
1022
async search ( ) {
968
1023
document . querySelector ( ".loading-spinner-2" ) . style . display = "block" ;
969
1024
const result = await fetchAreas ( searchTerm ) ;
@@ -998,6 +1053,7 @@ const start = {
998
1053
searchTerm = params ;
999
1054
this . search ( ) ;
1000
1055
}
1056
+ // Retrieve the `id` parameter from the URL
1001
1057
} ,
1002
1058
onremove : ( ) => {
1003
1059
scrollToTop ( ) ;
@@ -1417,30 +1473,45 @@ var detail = {
1417
1473
1418
1474
let mapView = {
1419
1475
view : function ( ) {
1420
- return m ( "div" , {
1421
- id : "map-container" ,
1476
+ return m (
1477
+ "div" ,
1478
+ {
1479
+ id : "map-container" ,
1422
1480
1423
- oncreate : ( vnode ) => {
1424
- bottom_bar ( "" , "" , "" ) ;
1481
+ oncreate : ( vnode ) => {
1482
+ status . AfterCragsNear = false ;
1425
1483
1426
- if ( ! status . notKaiOS )
1427
- bottom_bar (
1428
- "<img src='assets/icons/plus.svg'>" ,
1429
- "" ,
1430
- "<img src='assets/icons/minus.svg'>"
1431
- ) ;
1484
+ bottom_bar ( "" , "<img src='assets/icons/save.svg'>" , "" ) ;
1485
+
1486
+ if ( ! status . notKaiOS )
1487
+ bottom_bar (
1488
+ "<img src='assets/icons/plus.svg'>" ,
1489
+ "<img src='assets/icons/save.svg'>" ,
1490
+ "<img src='assets/icons/minus.svg'>"
1491
+ ) ;
1432
1492
1433
- const params = new URLSearchParams ( m . route . get ( ) . split ( "?" ) [ 1 ] ) ;
1434
- const lat = parseFloat ( params . get ( "lat" ) ) ;
1435
- const lng = parseFloat ( params . get ( "lng" ) ) ;
1436
- const id = parseFloat ( params . get ( "uuid" ) ) ;
1493
+ const params = new URLSearchParams ( m . route . get ( ) . split ( "?" ) [ 1 ] ) ;
1494
+ const lat = parseFloat ( params . get ( "lat" ) ) ;
1495
+ const lng = parseFloat ( params . get ( "lng" ) ) ;
1496
+ const id = parseFloat ( params . get ( "uuid" ) ) ;
1437
1497
1438
- map_function ( lat , lng , id ) ;
1498
+ map_function ( lat , lng , id ) ;
1439
1499
1440
- if ( status . notKaiOS )
1441
- top_bar ( "<img src='assets/icons/back.svg'>" , "" , "" ) ;
1500
+ if ( status . notKaiOS )
1501
+ top_bar ( "<img src='assets/icons/back.svg'>" , "" , "" ) ;
1502
+ } ,
1442
1503
} ,
1443
- } ) ;
1504
+ [
1505
+ m ( "div" , { id : "cross" } , [
1506
+ m ( "div" , { id : "cross-inner" } , [
1507
+ m ( "div" ) ,
1508
+ m ( "div" ) ,
1509
+ m ( "div" ) ,
1510
+ m ( "div" ) ,
1511
+ ] ) ,
1512
+ ] ) ,
1513
+ ]
1514
+ ) ;
1444
1515
} ,
1445
1516
} ;
1446
1517
@@ -2113,8 +2184,15 @@ document.addEventListener("DOMContentLoaded", function (e) {
2113
2184
}
2114
2185
2115
2186
if ( r . startsWith ( "/start" ) ) {
2116
- console . log ( current_article ) ;
2117
- if ( articles . length == 0 ) return false ;
2187
+ if ( current_article == undefined ) {
2188
+ m . route . set ( "/mapView" , {
2189
+ lat : 0 ,
2190
+ lng : 0 ,
2191
+ uuid : 0 ,
2192
+ } ) ;
2193
+ return ;
2194
+ }
2195
+ //if (articles.length == 0) return false;
2118
2196
if ( focused_article != null ) {
2119
2197
m . route . set ( "/mapView" , {
2120
2198
lat : current_article . metadata . lat ,
@@ -2123,9 +2201,9 @@ document.addEventListener("DOMContentLoaded", function (e) {
2123
2201
} ) ;
2124
2202
} else {
2125
2203
m . route . set ( "/mapView" , {
2126
- lat : current_article . metadata . lat ,
2127
- lng : current_article . metadata . lng ,
2128
- uuid : current_article . uuid ,
2204
+ lat : current_article . metadata . lat || 0 ,
2205
+ lng : current_article . metadata . lng || 0 ,
2206
+ uuid : current_article . uuid || 0 ,
2129
2207
} ) ;
2130
2208
}
2131
2209
}
@@ -2153,6 +2231,42 @@ document.addEventListener("DOMContentLoaded", function (e) {
2153
2231
document . activeElement . children [ 0 ] . focus ( ) ;
2154
2232
}
2155
2233
2234
+ if ( r . startsWith ( "/map" ) ) {
2235
+ let m = map . getCenter ( ) ;
2236
+
2237
+ document . querySelector ( ".loading-spinner" ) . style . display = "block" ;
2238
+ //get crags around map center
2239
+ fetchAreasByLocation ( m . lat , m . lng ) . then ( ( result ) => {
2240
+ status . AfterCragsNear = true ;
2241
+ result . data . cragsNear . map ( ( e ) => {
2242
+ e . crags . map ( ( n ) => {
2243
+ if ( n . totalClimbs > 0 ) {
2244
+ //get climbs of crags
2245
+ // openbeta api do not provide the climbs not
2246
+ //direct with cragsNear endpoint :-(
2247
+ fetchAreasById ( n . uuid ) . then ( ( e ) => {
2248
+ n . climbs = e . data . area . climbs ;
2249
+ articles = result . data . cragsNear [ 0 ] . crags ;
2250
+ } ) ;
2251
+ }
2252
+ // Create the marker with a custom 'id' property
2253
+ let marker = L . marker ( [ n . metadata . lat , n . metadata . lng ] , {
2254
+ id : n . uuid ,
2255
+ } )
2256
+ . addTo ( map )
2257
+ . bindPopup ( n . areaName ) ;
2258
+
2259
+ // Add a click event listener to the marker
2260
+ marker . on ( "click" , ( event ) => {
2261
+ const markerId = event . target . options . id ; // Retrieve the ID from the marker options
2262
+ status . selected_marker = markerId ;
2263
+ } ) ;
2264
+ } ) ;
2265
+ } ) ;
2266
+ document . querySelector ( ".loading-spinner" ) . style . display = "none" ;
2267
+ } ) ;
2268
+ }
2269
+
2156
2270
break ;
2157
2271
2158
2272
case "#" :
@@ -2163,7 +2277,11 @@ document.addEventListener("DOMContentLoaded", function (e) {
2163
2277
history . back ( ) ;
2164
2278
}
2165
2279
if ( r . startsWith ( "/mapView" ) ) {
2166
- history . back ( ) ;
2280
+ if ( status . AfterCragsNear ) {
2281
+ m . route . set ( "/start" , { "search" : "" } ) ;
2282
+ } else {
2283
+ history . back ( ) ;
2284
+ }
2167
2285
}
2168
2286
2169
2287
if ( r . startsWith ( "/article" ) ) {
0 commit comments