Skip to content

Commit 1964f2c

Browse files
committed
cragsNear
1 parent bf50eaf commit 1964f2c

15 files changed

+266
-46
lines changed

application/assets/css/main.css

+53
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,59 @@ label {
392392
background-color: #ffffff;
393393
}
394394

395+
/*crosshair*/
396+
397+
div#cross {
398+
width: 20px;
399+
height: 20px;
400+
position: absolute;
401+
top: 50%;
402+
left: 50%;
403+
transform: translate(-50%, -50%);
404+
z-index: 3000000000000;
405+
opacity: 1;
406+
}
407+
408+
div#cross div#cross-inner {
409+
position: relative;
410+
}
411+
412+
div#cross div {
413+
min-width: 20px;
414+
height: 3px;
415+
background: black;
416+
position: absolute;
417+
}
418+
419+
div#cross div:nth-child(1) {
420+
transform: rotate(90deg);
421+
z-index: 20000000;
422+
}
423+
424+
div#cross div:nth-child(2) {
425+
z-index: 20000000;
426+
}
427+
428+
div#cross div:nth-child(3) {
429+
min-width: 20px;
430+
outline: 2px solid white;
431+
}
432+
433+
div#cross div:nth-child(4) {
434+
outline: 2px solid white;
435+
transform: rotate(90deg);
436+
}
437+
438+
div.unavailable div:nth-child(4) {
439+
outline: 2px solid yellow !important;
440+
}
441+
442+
div.unavailable div:nth-child(3) {
443+
outline: 2px solid yellow !important;
444+
}
445+
446+
/*ticks*/
447+
395448
#ticks-view span.name {
396449
font-weight: bold;
397450
flex: 1;
2.41 KB
Loading

application/assets/js/helper.js

-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ export const geolocation = function (callback) {
7878
let lastCallbackTime = 0;
7979

8080
let showPosition = function (position) {
81-
console.log(position);
8281
const now = Date.now();
8382

8483
// Only proceed if 20 seconds have passed since the last callback

application/index.js

+150-32
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,7 @@ function map_function(lat, lng, id) {
203203
}
204204
};
205205
geolocation(geolocation_cb);
206-
207-
L.marker([lat, lng]).addTo(map);
206+
if (lat != 0 && lng != 0) L.marker([lat, lng]).addTo(map);
208207
map.setView([lat, lng]);
209208

210209
articles.map((e) => {
@@ -348,6 +347,8 @@ async function fetchGraphQL(query, variables) {
348347
body: JSON.stringify({ query, variables }),
349348
});
350349

350+
const requestBody = JSON.stringify({ query, variables });
351+
351352
if (!response.ok) {
352353
console.error(`HTTP error! status: ${response.status}`);
353354
return { errors: [{ message: `HTTP ${response.status}` }] };
@@ -544,11 +545,10 @@ async function fetchAreas(searchValue) {
544545
}
545546
}
546547

547-
/*
548548
let operationsDocLocation = `
549549
query MyQuery($lat: Float!, $lng: Float!) {
550550
cragsNear(
551-
maxDistance: 10000000
551+
maxDistance: 100000
552552
minDistance: 0
553553
includeCrags: true
554554
lnglat: { lat: $lat, lng: $lng }
@@ -558,13 +558,24 @@ let operationsDocLocation = `
558558
areaName
559559
totalClimbs
560560
pathTokens
561+
uuid
562+
id
563+
climbs {
564+
id
565+
name
566+
pathTokens
567+
uuid
568+
}
569+
children {
570+
id
571+
}
561572
metadata {
562573
lng
563574
lat
564575
isBoulder
565576
leftRightIndex
566577
}
567-
uuid
578+
568579
}
569580
}
570581
}
@@ -585,9 +596,48 @@ async function fetchAreasByLocation(lat, lng) {
585596
return { success: false, error: error.message };
586597
}
587598
}
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+
}
591641

592642
var root = document.getElementById("app");
593643

@@ -954,6 +1004,7 @@ let articles = [];
9541004
let current_article;
9551005

9561006
let searchTerm = "";
1007+
let searchTerm_id = "";
9571008
let stats = "";
9581009
let focused_article;
9591010
localforage
@@ -964,6 +1015,10 @@ localforage
9641015
.catch(() => {});
9651016

9661017
const start = {
1018+
onbeforeremove: function () {
1019+
status.previousView = "/start";
1020+
},
1021+
9671022
async search() {
9681023
document.querySelector(".loading-spinner-2").style.display = "block";
9691024
const result = await fetchAreas(searchTerm);
@@ -998,6 +1053,7 @@ const start = {
9981053
searchTerm = params;
9991054
this.search();
10001055
}
1056+
// Retrieve the `id` parameter from the URL
10011057
},
10021058
onremove: () => {
10031059
scrollToTop();
@@ -1417,30 +1473,45 @@ var detail = {
14171473

14181474
let mapView = {
14191475
view: function () {
1420-
return m("div", {
1421-
id: "map-container",
1476+
return m(
1477+
"div",
1478+
{
1479+
id: "map-container",
14221480

1423-
oncreate: (vnode) => {
1424-
bottom_bar("", "", "");
1481+
oncreate: (vnode) => {
1482+
status.AfterCragsNear = false;
14251483

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+
);
14321492

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"));
14371497

1438-
map_function(lat, lng, id);
1498+
map_function(lat, lng, id);
14391499

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+
},
14421503
},
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+
);
14441515
},
14451516
};
14461517

@@ -2113,8 +2184,15 @@ document.addEventListener("DOMContentLoaded", function (e) {
21132184
}
21142185

21152186
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;
21182196
if (focused_article != null) {
21192197
m.route.set("/mapView", {
21202198
lat: current_article.metadata.lat,
@@ -2123,9 +2201,9 @@ document.addEventListener("DOMContentLoaded", function (e) {
21232201
});
21242202
} else {
21252203
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,
21292207
});
21302208
}
21312209
}
@@ -2153,6 +2231,42 @@ document.addEventListener("DOMContentLoaded", function (e) {
21532231
document.activeElement.children[0].focus();
21542232
}
21552233

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+
21562270
break;
21572271

21582272
case "#":
@@ -2163,7 +2277,11 @@ document.addEventListener("DOMContentLoaded", function (e) {
21632277
history.back();
21642278
}
21652279
if (r.startsWith("/mapView")) {
2166-
history.back();
2280+
if (status.AfterCragsNear) {
2281+
m.route.set("/start", { "search": "" });
2282+
} else {
2283+
history.back();
2284+
}
21672285
}
21682286

21692287
if (r.startsWith("/article")) {

application/manifest.webmanifest

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
],
5555

5656
"b2g_features": {
57-
"version": "1.64",
57+
"version": "1.66",
5858
"id": "PicTick",
5959
"subtitle": "PicTick",
6060
"core": true,

application/sw.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ sw_channel.postMessage({});
2929
const userAgent = navigator.userAgent || "";
3030

3131
if (userAgent && !userAgent.includes("KAIOS")) {
32-
const CACHE_NAME = "pwa-cache-v2.1z";
32+
const CACHE_NAME = "pwa-cache-v2.2002";
3333
const FILE_LIST_URL = "file-list.json"; // URL of the JSON file containing the array of files
3434

3535
self.addEventListener("install", (event) => {

0 commit comments

Comments
 (0)