From dacb080e697f7c2f045864b618ed6ba759fb0e08 Mon Sep 17 00:00:00 2001 From: strukturart Date: Tue, 2 Jan 2024 00:24:31 +0100 Subject: [PATCH] files --- application/assets/css/main.css | 3 +- application/assets/js/exportGeoJson.js | 11 +- application/assets/js/maps.js | 10 +- application/assets/js/module.js | 49 +++-- application/assets/js/osm.js | 35 ++-- application/assets/js/overpass.js | 16 +- application/index.html | 3 +- application/index.js | 246 ++++++++++++------------- application/manifest.webapp | 4 +- application/manifest.webmanifest | 3 +- docs/assets/css/main.css | 3 +- docs/assets/js/exportGeoJson.js | 11 +- docs/assets/js/maps.js | 10 +- docs/assets/js/module.js | 53 +++--- docs/assets/js/osm.js | 35 ++-- docs/assets/js/overpass.js | 16 +- docs/index.html | 3 +- docs/index.js | 240 ++++++++++++------------ docs/manifest.webapp | 4 +- docs/manifest.webmanifest | 3 +- 20 files changed, 380 insertions(+), 378 deletions(-) diff --git a/application/assets/css/main.css b/application/assets/css/main.css index 78e0a241..155c2891 100644 --- a/application/assets/css/main.css +++ b/application/assets/css/main.css @@ -10,6 +10,7 @@ --color-seven: gainsboro; --color-eight: rgb(241, 86, 24); --color-ten: rgb(218, 229, 253); + --color-eleven: rgb(44, 83, 17); } *, @@ -650,7 +651,7 @@ div#intro div#icon img { } div#intro div#icon { - background: var(--color-ten); + background: var(--color-eleven); border-radius: 10px; width: 70px; display: block; diff --git a/application/assets/js/exportGeoJson.js b/application/assets/js/exportGeoJson.js index b9b2ba9f..e8fed8c5 100644 --- a/application/assets/js/exportGeoJson.js +++ b/application/assets/js/exportGeoJson.js @@ -26,7 +26,6 @@ const geojson = ((_) => { if (type == "path") { let p = geoJSON_group.toGeoJSON(); extData = JSON.stringify(p); - console.log(p); } if (type == "tracking") { @@ -57,6 +56,8 @@ const geojson = ((_) => { extData = JSON.stringify(collection); } + console.log(extData); + let geojson_file = new Blob([extData], { type: "application/json", }); @@ -89,10 +90,14 @@ const geojson = ((_) => { module.measure_distance("destroy"); } helper.side_toaster("saved", 5000); + let filename = file_path_name.split("/"); + filename = filename[filename.length - 1]; + // files_.push({ name: filename, path: file_path_name, type: "geoJSON" }); }; - requestAdd.onerror = function () { - helper.toaster( + requestAdd.onerror = function (e) { + console.log(e); + helper.side_toaster( file_path_name + " Unable to write the file, the file name may already be used", 10000 diff --git a/application/assets/js/maps.js b/application/assets/js/maps.js index 3db1f77e..16f0e9b3 100644 --- a/application/assets/js/maps.js +++ b/application/assets/js/maps.js @@ -212,6 +212,8 @@ const maps = (() => { let overlayer = ""; let addMap = function (url, attribution, max_zoom, type) { + if (attribution == null) attribution = ""; + if (max_zoom == null) max_zoom = 12; //remove layer if (url == "") { if (map.hasLayer(tilesLayer)) { @@ -325,13 +327,9 @@ const maps = (() => { if (overpass_query == url) { overpass.call(map, url, "climbing_icon"); general.active_layer.splice(general.active_layer.indexOf(url), 1); - return false; - } - - map.setZoom(14); - setTimeout(function () { + } else { overpass.call(map, url, "climbing_icon"); - }, 1000); + } } }; diff --git a/application/assets/js/module.js b/application/assets/js/module.js index bc8b7f1b..c4a84d4e 100644 --- a/application/assets/js/module.js +++ b/application/assets/js/module.js @@ -378,20 +378,21 @@ const module = (() => { //////////////////// // Flag to keep track of the need // of generating the new marker list - var f_upd_markers_list = true; - let set_f_upd_markers = function () { - f_upd_markers_list = true; + let markers_updated = function () { + marker_list_updated = false; }; + let marker_list_updated = false; + let markers_collection = []; //makers in map boundingbox - let l = []; let index = -1; let select_marker = function () { - if (f_upd_markers_list) { + index++; + + if (marker_list_updated == false) { // Reset contained list markers_collection = []; - //merge markers in viewport if (overpass_group != "") { overpass_group.eachLayer(function (l) { markers_collection.push(l); @@ -402,14 +403,13 @@ const module = (() => { markers_collection.push(l); }); - // Clear flag - f_upd_markers_list = false; + marker_list_updated = true; } status.marker_selection = true; status.windowOpen = "marker"; - index++; + console.log(markers_collection, index); if (index >= markers_collection.length) index = 0; map.setView(markers_collection[index]._latlng, map.getZoom()); @@ -461,6 +461,7 @@ const module = (() => { } return markers_collection[index]; }; + //remove GPX let remove_gpx = function () { let i = 0; @@ -523,7 +524,9 @@ const module = (() => { let update_gpx_info = function () { document.getElementById("gpx-name").innerText = gpx_selection_info.name; - document.getElementById("gpx-time").innerText = format_ms(gpx_selection_info.duration); + document.getElementById("gpx-time").innerText = format_ms( + gpx_selection_info.duration + ); document.querySelector("#gpx-evo-up span").innerText = gpx_selection_info.elevation_gain.toFixed(2); @@ -732,7 +735,7 @@ const module = (() => { if (altitudeDifference > 0) { gain += altitudeDifference; } else { - loss += Math.abs(altitudeDifference); + loss += Math.abs(altitudeDifference); } } } @@ -813,9 +816,12 @@ const module = (() => { document.querySelector("#tracking-view .average-speed div").innerText = isNaN(tracking.speed_average) ? "-" : tracking.speed_average; - document.querySelector("#tracking-evo-down span").innerText = tracking.loss.toFixed(2); - document.querySelector("#tracking-evo-up span").innerText = tracking.gain.toFixed(2); - document.getElementById("tracking-altitude").innerText = tracking.altitude.toFixed(2); + document.querySelector("#tracking-evo-down span").innerText = + tracking.loss.toFixed(2); + document.querySelector("#tracking-evo-up span").innerText = + tracking.gain.toFixed(2); + document.getElementById("tracking-altitude").innerText = + tracking.altitude.toFixed(2); document.querySelector("#tracking-speed-average-time").innerText = isNaN( tracking.speed_average @@ -849,6 +855,7 @@ const module = (() => { console.log(e); } + tracking_timestamp = []; tracking_altitude = []; document.getElementById("tracking-altitude").innerText = ""; document.querySelector("div#tracking-distance").innerText = ""; @@ -903,8 +910,8 @@ const module = (() => { tracking_cache[i].alt, ]); - tracking_timestamp.push(tracking_cache[i].timestamp); - tracking_altitude.push(tracking_cache[i].alt); + //tracking_timestamp.push(tracking_cache[i].timestamp); + //tracking_altitude.push(tracking_cache[i].alt); } } else { localStorage.removeItem("tracking_cache"); @@ -922,13 +929,12 @@ const module = (() => { //store time let ts = new Date(); - tracking_timestamp.push(ts.toISOString()); + // tracking_timestamp.push(ts.toISOString()); // Store altitude let alt = null; if (mainmarker.device_alt && !isNaN(mainmarker.device_alt)) { alt = mainmarker.device_alt; - // tracking_altitude.push(alt); } polyline_tracking.addLatLng([ @@ -965,6 +971,11 @@ const module = (() => { .map((latlng) => latlng.alt) .filter((altitude) => altitude !== null); + // Extract time from the LatLng objects and filter out null values + tracking_timestamp = tracking_cache + .map((latlng) => latlng.timestamp) + .filter((timestamp) => timestamp !== null); + // Now you can use the filtered tracking_altitude array in the calculateGainAndLoss function const { gain, loss } = calculateGainAndLoss(tracking_altitude, 50); @@ -1191,7 +1202,7 @@ const module = (() => { return { hotline, convert_units, - set_f_upd_markers, + markers_updated, select_marker, select_gpx, calc_distance, diff --git a/application/assets/js/osm.js b/application/assets/js/osm.js index 41c77242..3b0f82ca 100644 --- a/application/assets/js/osm.js +++ b/application/assets/js/osm.js @@ -130,8 +130,8 @@ const osm = (() => { } }; - const get_user = function () { - if (!general.osm_token) { + const get_user = function (notification = true) { + if (!general.osm_token && notification) { helper.side_toaster( "looks like you are not connected to openstreetmap", 5000 @@ -246,7 +246,7 @@ const osm = (() => { ///List files ///////////// - let osm_server_list_gpx = function () { + let osm_server_list_gpx = function (callback) { let n = "Bearer " + localStorage.getItem("openstreetmap_token"); const myHeaders = new Headers({ @@ -272,8 +272,12 @@ const osm = (() => { id: s[i].getAttribute("id"), }; - files.push({ name: m.name, id: m.id, type: "osm_sever" }); - files_.push({ name: m.name, id: m.id, type: "osm_sever" }); + files.push({ + name: "_" + m.name, + path: m.id, + id: m.id, + type: "osm_sever", + }); files.sort((a, b) => { return b.name.localeCompare(a.name); @@ -287,8 +291,12 @@ const osm = (() => { id: s[i].getAttribute("id"), }; - files.push({ name: m.name, id: m.id, type: "osm_sever" }); - files_.push({ name: m.name, id: m.id, type: "osm_sever" }); + files.push({ + name: m.name, + path: m.id, + id: m.id, + type: "osm_sever", + }); files.sort((a, b) => { return b.name.localeCompare(a.name); @@ -298,18 +306,7 @@ const osm = (() => { } } } - files.forEach((e) => { - document - .querySelector("div#osm-server-gpx") - .insertAdjacentHTML( - "afterend", - '
' + - e.name + - "
" - ); - }); + callback(files); }) .catch((error) => { diff --git a/application/assets/js/overpass.js b/application/assets/js/overpass.js index e91010f0..f797b7a4 100644 --- a/application/assets/js/overpass.js +++ b/application/assets/js/overpass.js @@ -1,7 +1,14 @@ const overpass = (() => { function call(map, overpassQuery, icon) { + console.log(general.zoomlevel); //clear group before ad new items - + if (general.zoomlevel > 13) { + helper.side_toaster( + "Please zoom, otherwise too much data will be loaded", + 2000 + ); + return false; + } if (overpass_group != "") { overpass_group.clearLayers(); contained = []; @@ -42,10 +49,6 @@ const overpass = (() => { fetch(resultUrl) .then((response) => response.json()) .then(function (data) { - if (!data) { - return false; - } - let no_data = false; data.elements.forEach((element) => { if (element.type == "node") { @@ -54,9 +57,8 @@ const overpass = (() => { .addTo(overpass_group) .setIcon(maps[icon]); try { - } catch (e) { k.bindPopup(element.tags.name); - } + } catch (e) {} } }); diff --git a/application/index.html b/application/index.html index 1aa83a46..49472435 100644 --- a/application/index.html +++ b/application/index.html @@ -865,7 +865,6 @@

Thank You!

- @@ -883,8 +882,10 @@

Thank You!

+ + diff --git a/application/index.js b/application/index.js index f635f6ed..96d7c7c1 100644 --- a/application/index.js +++ b/application/index.js @@ -25,7 +25,7 @@ let tilesLayer = ""; let n; let gps_lock; -let files_ = []; +let files = []; const audio = document.createElement("audio"); audio.mozAudioChannelType = "content"; @@ -165,7 +165,7 @@ map = new L.map("map-container", { }); document.addEventListener("DOMContentLoaded", function () { - osm.get_user(); + osm.get_user(false); settings.load_settings(); let routing_service_callback = function (e) { @@ -426,6 +426,97 @@ document.addEventListener("DOMContentLoaded", function () { //get files and store + // Function to remove duplicates based on the 'name' property + function removeDuplicates(arr, prop) { + return arr.filter((obj, index, array) => { + return array.findIndex((o) => o[prop] === obj[prop]) === index; + }); + } + let writeFileList = function (data) { + // Clear existing items before adding new ones + // Remove existing items with the same data-map attribute + document.querySelectorAll('[data-map="gpx"]').forEach((element) => { + element.remove(); + }); + + document.querySelectorAll('[data-map="geojson"]').forEach((element) => { + element.remove(); + }); + + document.querySelectorAll('[data-map="gpx-osm"]').forEach((element) => { + element.remove(); + }); + + // Remove duplicates based on the 'name' property + var uniqueData = removeDuplicates(data, "name"); + + files = uniqueData; + + console.log(uniqueData); + + uniqueData.forEach((e) => { + if (e.type == "gpx") { + document.getElementById("gpx-title").style.display = "block"; + + document + .querySelector("div#gpx") + .insertAdjacentHTML( + "afterend", + '
' + + e.name + + "
" + ); + + // Load gpx file on start + if (e.name.substring(0, 1) == "_") { + module.loadGPX(e.path); + } + } + + if (e.type == "geoJSON") { + document.getElementById("tracks-title").style.display = "block"; + + document + .querySelector("div#tracksmarkers") + .insertAdjacentHTML( + "afterend", + '
' + + e.name + + "
" + ); + + // Load startup item + if (e.name.substring(0, 1) == "_") { + module.loadGeoJSON(e.path + "/" + e.name, false); + } + } + + if (e.type == "osm_sever") { + document.getElementById("osm-server-gpx-title").style.display = "block"; + document + .querySelector("div#osm-server-gpx") + .insertAdjacentHTML( + "afterend", + '
' + + e.name + + "
" + ); + } + }); + }; + ////////////////////////////////// //READ GPX//////////////////////// ///////////////////////////////// @@ -434,8 +525,6 @@ document.addEventListener("DOMContentLoaded", function () { let find_gpx = function () { //KaiOS 2.x try { - let files = []; - //search gpx let finder_gpx = new Applait.Finder({ type: "sdcard", @@ -444,36 +533,15 @@ document.addEventListener("DOMContentLoaded", function () { finder_gpx.search(".gpx"); finder_gpx.on("searchComplete", function (needle, filematchcount) { - files.forEach((e) => { - document - .querySelector("div#gpx") - .insertAdjacentHTML( - "afterend", - '
' + - e.name + - "
" - ); - //load gpx file on start - if (e.name.substring(0, 1) == "_") { - module.loadGPX(e.path + "/" + e.name); - } - }); + writeFileList(files); }); finder_gpx.on("fileFound", function (file, fileinfo, storageName) { - files_.push({ name: fileinfo.name, path: fileinfo.path, type: "gpx" }); - - files.push({ name: fileinfo.name, path: fileinfo.path, type: "gpx" }); - files.sort((a, b) => { - return b.name.localeCompare(a.name); + files.push({ + name: fileinfo.name, + path: file.name, + type: "gpx", }); - document.getElementById("gpx-title").style.display = "block"; }); } catch (e) {} @@ -486,30 +554,9 @@ document.addEventListener("DOMContentLoaded", function () { let filename = e.split("/"); filename = filename[filename.length - 1]; - files_.push({ name: filename, path: e, type: "gpx" }); files.push({ name: filename, path: e, type: "gpx" }); - files.sort((a, b) => { - return b.name.localeCompare(a.name); - }); - files.forEach((e) => { - document - .querySelector("div#gpx") - .insertAdjacentHTML( - "afterend", - '
' + - e.name + - "
" - ); - //load gpx file on start - if (e.name.substring(0, 1) == "_") { - module.loadGPX(e.path); - } - }); + writeFileList(files); }; try { @@ -526,8 +573,6 @@ document.addEventListener("DOMContentLoaded", function () { let find_geojson = function () { try { - let files = []; - //search geojson let finder = new Applait.Finder({ type: "sdcard", @@ -536,79 +581,24 @@ document.addEventListener("DOMContentLoaded", function () { finder.search(".geojson"); finder.on("searchComplete", function (needle, filematchcount) { - files.forEach((e) => { - document - .querySelector("div#tracksmarkers") - .insertAdjacentHTML( - "afterend", - '
' + - e.name + - "
" - ); - //load startup item - - if (e.name.substring(0, 1) == "_") { - module.loadGeoJSON(e.path + "/" + e.name, false); - } - document.getElementById("tracks-title").style.display = "block"; - }); + writeFileList(files); }); finder.on("fileFound", function (file, fileinfo, storageName) { - files_.push({ - name: fileinfo.name, - path: fileinfo.path, - type: "geoJSON", - }); - files.push({ name: fileinfo.name, - path: fileinfo.path, + path: file.name, type: "geoJSON", }); - files.sort((a, b) => { - return b.name.localeCompare(a.name); - }); }); } catch (e) {} //KaiOS 3.x let list_files_callback = function (e) { - let files = []; - let filename = e.split("/"); filename = filename[filename.length - 1]; - files_.push({ name: filename, path: e, type: "geoJSON" }); - files.push({ name: filename, path: e, type: "geoJSON" }); - files.sort((a, b) => { - return b.name.localeCompare(a.name); - }); - files.forEach((e) => { - document - .querySelector("div#tracksmarkers") - .insertAdjacentHTML( - "afterend", - '
' + - e.name + - "
" - ); - - if (e.name.substring(0, 1) == "_") { - module.loadGeoJSON(e.path, false); - } - document.getElementById("tracks-title").style.display = "block"; - }); + writeFileList(files); }; try { @@ -713,8 +703,13 @@ document.addEventListener("DOMContentLoaded", function () { if (localStorage.getItem("openstreetmap_token") == null) { document.getElementById("osm-server-gpx-title").style.display = "none"; } else { - osm.osm_server_list_gpx(); - document.getElementById("osm-server-gpx-title").style.display = "block"; + let osm_server_list_gpx_callback = (e) => { + e.forEach((m) => { + files.push(m); + }); + writeFileList(files); + }; + osm.osm_server_list_gpx(osm_server_list_gpx_callback); } const osm_oauth_callback = function () { document.getElementById("osm-user").innerText = @@ -723,18 +718,7 @@ document.addEventListener("DOMContentLoaded", function () { let gpx_callback = function (filename) { helper.side_toaster(filename + " saved", 5000); - document - .querySelector("div#gpx") - .nextSibling.insertAdjacentHTML( - "afterend", - "
" + - filename + - "
" - ); + find_gpx(); hotline_group.clearLayers(); }; @@ -901,7 +885,7 @@ document.addEventListener("DOMContentLoaded", function () { }; let open_finder = function () { - console.log(files_); + console.log(files); settings.load_settings(); finder_tabindex(); document.querySelector("div#finder").style.display = "block"; @@ -1377,7 +1361,7 @@ document.addEventListener("DOMContentLoaded", function () { document.querySelector("div#markers-option").style.display = "none"; status.windowOpen = "map"; helper.bottom_bar("", "", ""); - module.set_f_upd_markers(); + module.markers_updated(); } if (item_value == "save_marker") { @@ -2362,6 +2346,8 @@ document.addEventListener("DOMContentLoaded", function () { w = module.user_input("return"); } + console.log(setting.export_path + w + ".geojson"); + geojson.save_geojson( setting.export_path + w + ".geojson", "single-direct" @@ -2724,7 +2710,7 @@ document.addEventListener("DOMContentLoaded", function () { L.marker([mainmarker.current_lat, mainmarker.current_lng]).addTo( markers_group ); - module.set_f_upd_markers(); + module.markers_updated(); } break; @@ -2737,7 +2723,7 @@ document.addEventListener("DOMContentLoaded", function () { case "*": if (status.intro) return false; if (status.keylock) return false; - if (status.windowOpen == "map") { + if (status.windowOpen == "map" || status.windowOpen == "marker") { mainmarker.selected_marker = module.select_marker(); } diff --git a/application/manifest.webapp b/application/manifest.webapp index 0e5b7a0c..cd5ccb5d 100644 --- a/application/manifest.webapp +++ b/application/manifest.webapp @@ -1,5 +1,5 @@ { - "version": "1.9.759", + "version": "1.9.762", "version_name": "hotline", "name": "o.map", "description": "O.map, your ultimate navigation companion for KaiOS-powered devices. O.map is a lightweight and feature-rich map application designed specifically for KaiOS, enabling you to explore and navigate the world with ease. Whether you're a local resident, a tourist, or an adventurer, O.map is here to enhance your journey and keep you on the right track.", @@ -44,7 +44,7 @@ "locales": { "en-US": { "name": "o.map", - "subtitle": "openstreetmap app", + "subtitle": "O.map is a lightweight and feature-rich map application", "description": "O.map, your ultimate navigation companion for KaiOS-powered devices. O.map is a lightweight and feature-rich map application designed specifically for KaiOS, enabling you to explore and navigate the world with ease. Whether you're a local resident, a tourist, or an adventurer, o.map is here to enhance your journey and keep you on the right track." } diff --git a/application/manifest.webmanifest b/application/manifest.webmanifest index e8557b8e..3bb6b81f 100644 --- a/application/manifest.webmanifest +++ b/application/manifest.webmanifest @@ -2,7 +2,6 @@ "name": "o.map", "id": "o.map", "description": "O.map, your ultimate navigation companion for KaiOS-powered devices. O.map is a lightweight and feature-rich map application designed specifically for KaiOS, enabling you to explore and navigate the world with ease. Whether you're a local resident, a tourist, or an adventurer, O.map is here to enhance your journey and keep you on the right track.", - "lang": "en-US", "start_url": "/index.html", "priority": "high", @@ -22,7 +21,7 @@ ], "b2g_features": { - "version": "2.0.79", + "version": "2.0.81", "id": "o.map", "core": true, "categories": ["utilities"], diff --git a/docs/assets/css/main.css b/docs/assets/css/main.css index 78e0a241..155c2891 100644 --- a/docs/assets/css/main.css +++ b/docs/assets/css/main.css @@ -10,6 +10,7 @@ --color-seven: gainsboro; --color-eight: rgb(241, 86, 24); --color-ten: rgb(218, 229, 253); + --color-eleven: rgb(44, 83, 17); } *, @@ -650,7 +651,7 @@ div#intro div#icon img { } div#intro div#icon { - background: var(--color-ten); + background: var(--color-eleven); border-radius: 10px; width: 70px; display: block; diff --git a/docs/assets/js/exportGeoJson.js b/docs/assets/js/exportGeoJson.js index b9b2ba9f..e8fed8c5 100644 --- a/docs/assets/js/exportGeoJson.js +++ b/docs/assets/js/exportGeoJson.js @@ -26,7 +26,6 @@ const geojson = ((_) => { if (type == "path") { let p = geoJSON_group.toGeoJSON(); extData = JSON.stringify(p); - console.log(p); } if (type == "tracking") { @@ -57,6 +56,8 @@ const geojson = ((_) => { extData = JSON.stringify(collection); } + console.log(extData); + let geojson_file = new Blob([extData], { type: "application/json", }); @@ -89,10 +90,14 @@ const geojson = ((_) => { module.measure_distance("destroy"); } helper.side_toaster("saved", 5000); + let filename = file_path_name.split("/"); + filename = filename[filename.length - 1]; + // files_.push({ name: filename, path: file_path_name, type: "geoJSON" }); }; - requestAdd.onerror = function () { - helper.toaster( + requestAdd.onerror = function (e) { + console.log(e); + helper.side_toaster( file_path_name + " Unable to write the file, the file name may already be used", 10000 diff --git a/docs/assets/js/maps.js b/docs/assets/js/maps.js index 3db1f77e..16f0e9b3 100644 --- a/docs/assets/js/maps.js +++ b/docs/assets/js/maps.js @@ -212,6 +212,8 @@ const maps = (() => { let overlayer = ""; let addMap = function (url, attribution, max_zoom, type) { + if (attribution == null) attribution = ""; + if (max_zoom == null) max_zoom = 12; //remove layer if (url == "") { if (map.hasLayer(tilesLayer)) { @@ -325,13 +327,9 @@ const maps = (() => { if (overpass_query == url) { overpass.call(map, url, "climbing_icon"); general.active_layer.splice(general.active_layer.indexOf(url), 1); - return false; - } - - map.setZoom(14); - setTimeout(function () { + } else { overpass.call(map, url, "climbing_icon"); - }, 1000); + } } }; diff --git a/docs/assets/js/module.js b/docs/assets/js/module.js index 851fc673..c4a84d4e 100644 --- a/docs/assets/js/module.js +++ b/docs/assets/js/module.js @@ -378,20 +378,21 @@ const module = (() => { //////////////////// // Flag to keep track of the need // of generating the new marker list - var f_upd_markers_list = true; - let set_f_upd_markers = function () { - f_upd_markers_list = true; + let markers_updated = function () { + marker_list_updated = false; }; + let marker_list_updated = false; + let markers_collection = []; //makers in map boundingbox - let l = []; let index = -1; let select_marker = function () { - if (f_upd_markers_list) { + index++; + + if (marker_list_updated == false) { // Reset contained list markers_collection = []; - //merge markers in viewport if (overpass_group != "") { overpass_group.eachLayer(function (l) { markers_collection.push(l); @@ -402,14 +403,13 @@ const module = (() => { markers_collection.push(l); }); - // Clear flag - f_upd_markers_list = false; + marker_list_updated = true; } status.marker_selection = true; status.windowOpen = "marker"; - index++; + console.log(markers_collection, index); if (index >= markers_collection.length) index = 0; map.setView(markers_collection[index]._latlng, map.getZoom()); @@ -461,6 +461,7 @@ const module = (() => { } return markers_collection[index]; }; + //remove GPX let remove_gpx = function () { let i = 0; @@ -523,7 +524,9 @@ const module = (() => { let update_gpx_info = function () { document.getElementById("gpx-name").innerText = gpx_selection_info.name; - document.getElementById("gpx-time").innerText = format_ms(gpx_selection_info.duration); + document.getElementById("gpx-time").innerText = format_ms( + gpx_selection_info.duration + ); document.querySelector("#gpx-evo-up span").innerText = gpx_selection_info.elevation_gain.toFixed(2); @@ -732,7 +735,7 @@ const module = (() => { if (altitudeDifference > 0) { gain += altitudeDifference; } else { - loss += Math.abs(altitudeDifference); + loss += Math.abs(altitudeDifference); } } } @@ -796,13 +799,13 @@ const module = (() => { tracking.gain ) ? "-" - : tracking.gain; + : tracking.gain.toFixed(2); document.querySelector("#tracking-view .loss div").innerText = isNaN( tracking.loss ) ? "-" - : tracking.loss; + : tracking.loss.toFixed(2); document.querySelector("#tracking-view .altitude div").innerText = isNaN( tracking.altitude @@ -813,9 +816,12 @@ const module = (() => { document.querySelector("#tracking-view .average-speed div").innerText = isNaN(tracking.speed_average) ? "-" : tracking.speed_average; - document.querySelector("#tracking-evo-down span").innerText = tracking.loss.toFixed(2); - document.querySelector("#tracking-evo-up span").innerText = tracking.gain.toFixed(2); - document.getElementById("tracking-altitude").innerText = tracking.altitude.toFixed(2); + document.querySelector("#tracking-evo-down span").innerText = + tracking.loss.toFixed(2); + document.querySelector("#tracking-evo-up span").innerText = + tracking.gain.toFixed(2); + document.getElementById("tracking-altitude").innerText = + tracking.altitude.toFixed(2); document.querySelector("#tracking-speed-average-time").innerText = isNaN( tracking.speed_average @@ -849,6 +855,7 @@ const module = (() => { console.log(e); } + tracking_timestamp = []; tracking_altitude = []; document.getElementById("tracking-altitude").innerText = ""; document.querySelector("div#tracking-distance").innerText = ""; @@ -903,8 +910,8 @@ const module = (() => { tracking_cache[i].alt, ]); - tracking_timestamp.push(tracking_cache[i].timestamp); - tracking_altitude.push(tracking_cache[i].alt); + //tracking_timestamp.push(tracking_cache[i].timestamp); + //tracking_altitude.push(tracking_cache[i].alt); } } else { localStorage.removeItem("tracking_cache"); @@ -922,13 +929,12 @@ const module = (() => { //store time let ts = new Date(); - tracking_timestamp.push(ts.toISOString()); + // tracking_timestamp.push(ts.toISOString()); // Store altitude let alt = null; if (mainmarker.device_alt && !isNaN(mainmarker.device_alt)) { alt = mainmarker.device_alt; - // tracking_altitude.push(alt); } polyline_tracking.addLatLng([ @@ -965,6 +971,11 @@ const module = (() => { .map((latlng) => latlng.alt) .filter((altitude) => altitude !== null); + // Extract time from the LatLng objects and filter out null values + tracking_timestamp = tracking_cache + .map((latlng) => latlng.timestamp) + .filter((timestamp) => timestamp !== null); + // Now you can use the filtered tracking_altitude array in the calculateGainAndLoss function const { gain, loss } = calculateGainAndLoss(tracking_altitude, 50); @@ -1191,7 +1202,7 @@ const module = (() => { return { hotline, convert_units, - set_f_upd_markers, + markers_updated, select_marker, select_gpx, calc_distance, diff --git a/docs/assets/js/osm.js b/docs/assets/js/osm.js index 41c77242..3b0f82ca 100644 --- a/docs/assets/js/osm.js +++ b/docs/assets/js/osm.js @@ -130,8 +130,8 @@ const osm = (() => { } }; - const get_user = function () { - if (!general.osm_token) { + const get_user = function (notification = true) { + if (!general.osm_token && notification) { helper.side_toaster( "looks like you are not connected to openstreetmap", 5000 @@ -246,7 +246,7 @@ const osm = (() => { ///List files ///////////// - let osm_server_list_gpx = function () { + let osm_server_list_gpx = function (callback) { let n = "Bearer " + localStorage.getItem("openstreetmap_token"); const myHeaders = new Headers({ @@ -272,8 +272,12 @@ const osm = (() => { id: s[i].getAttribute("id"), }; - files.push({ name: m.name, id: m.id, type: "osm_sever" }); - files_.push({ name: m.name, id: m.id, type: "osm_sever" }); + files.push({ + name: "_" + m.name, + path: m.id, + id: m.id, + type: "osm_sever", + }); files.sort((a, b) => { return b.name.localeCompare(a.name); @@ -287,8 +291,12 @@ const osm = (() => { id: s[i].getAttribute("id"), }; - files.push({ name: m.name, id: m.id, type: "osm_sever" }); - files_.push({ name: m.name, id: m.id, type: "osm_sever" }); + files.push({ + name: m.name, + path: m.id, + id: m.id, + type: "osm_sever", + }); files.sort((a, b) => { return b.name.localeCompare(a.name); @@ -298,18 +306,7 @@ const osm = (() => { } } } - files.forEach((e) => { - document - .querySelector("div#osm-server-gpx") - .insertAdjacentHTML( - "afterend", - '
' + - e.name + - "
" - ); - }); + callback(files); }) .catch((error) => { diff --git a/docs/assets/js/overpass.js b/docs/assets/js/overpass.js index e91010f0..f797b7a4 100644 --- a/docs/assets/js/overpass.js +++ b/docs/assets/js/overpass.js @@ -1,7 +1,14 @@ const overpass = (() => { function call(map, overpassQuery, icon) { + console.log(general.zoomlevel); //clear group before ad new items - + if (general.zoomlevel > 13) { + helper.side_toaster( + "Please zoom, otherwise too much data will be loaded", + 2000 + ); + return false; + } if (overpass_group != "") { overpass_group.clearLayers(); contained = []; @@ -42,10 +49,6 @@ const overpass = (() => { fetch(resultUrl) .then((response) => response.json()) .then(function (data) { - if (!data) { - return false; - } - let no_data = false; data.elements.forEach((element) => { if (element.type == "node") { @@ -54,9 +57,8 @@ const overpass = (() => { .addTo(overpass_group) .setIcon(maps[icon]); try { - } catch (e) { k.bindPopup(element.tags.name); - } + } catch (e) {} } }); diff --git a/docs/index.html b/docs/index.html index 1aa83a46..49472435 100644 --- a/docs/index.html +++ b/docs/index.html @@ -865,7 +865,6 @@

Thank You!

- @@ -883,8 +882,10 @@

Thank You!

+ + diff --git a/docs/index.js b/docs/index.js index f635f6ed..bfa9aea9 100644 --- a/docs/index.js +++ b/docs/index.js @@ -165,7 +165,7 @@ map = new L.map("map-container", { }); document.addEventListener("DOMContentLoaded", function () { - osm.get_user(); + osm.get_user(false); settings.load_settings(); let routing_service_callback = function (e) { @@ -426,6 +426,97 @@ document.addEventListener("DOMContentLoaded", function () { //get files and store + // Function to remove duplicates based on the 'name' property + function removeDuplicates(arr, prop) { + return arr.filter((obj, index, array) => { + return array.findIndex((o) => o[prop] === obj[prop]) === index; + }); + } + let writeFileList = function (data) { + // Clear existing items before adding new ones + // Remove existing items with the same data-map attribute + document.querySelectorAll('[data-map="gpx"]').forEach((element) => { + element.remove(); + }); + + document.querySelectorAll('[data-map="geojson"]').forEach((element) => { + element.remove(); + }); + + document.querySelectorAll('[data-map="gpx-osm"]').forEach((element) => { + element.remove(); + }); + + // Remove duplicates based on the 'name' property + var uniqueData = removeDuplicates(data, "name"); + + _files = uniqueData; + + console.log(uniqueData); + + uniqueData.forEach((e) => { + if (e.type == "gpx") { + document.getElementById("gpx-title").style.display = "block"; + + document + .querySelector("div#gpx") + .insertAdjacentHTML( + "afterend", + '
' + + e.name + + "
" + ); + + // Load gpx file on start + if (e.name.substring(0, 1) == "_") { + module.loadGPX(e.path); + } + } + + if (e.type == "geoJSON") { + document.getElementById("tracks-title").style.display = "block"; + + document + .querySelector("div#tracksmarkers") + .insertAdjacentHTML( + "afterend", + '
' + + e.name + + "
" + ); + + // Load startup item + if (e.name.substring(0, 1) == "_") { + module.loadGeoJSON(e.path + "/" + e.name, false); + } + } + + if (e.type == "osm_sever") { + document.getElementById("osm-server-gpx-title").style.display = "block"; + document + .querySelector("div#osm-server-gpx") + .insertAdjacentHTML( + "afterend", + '
' + + e.name + + "
" + ); + } + }); + }; + ////////////////////////////////// //READ GPX//////////////////////// ///////////////////////////////// @@ -434,8 +525,6 @@ document.addEventListener("DOMContentLoaded", function () { let find_gpx = function () { //KaiOS 2.x try { - let files = []; - //search gpx let finder_gpx = new Applait.Finder({ type: "sdcard", @@ -444,36 +533,15 @@ document.addEventListener("DOMContentLoaded", function () { finder_gpx.search(".gpx"); finder_gpx.on("searchComplete", function (needle, filematchcount) { - files.forEach((e) => { - document - .querySelector("div#gpx") - .insertAdjacentHTML( - "afterend", - '
' + - e.name + - "
" - ); - //load gpx file on start - if (e.name.substring(0, 1) == "_") { - module.loadGPX(e.path + "/" + e.name); - } - }); + writeFileList(files_); }); finder_gpx.on("fileFound", function (file, fileinfo, storageName) { - files_.push({ name: fileinfo.name, path: fileinfo.path, type: "gpx" }); - - files.push({ name: fileinfo.name, path: fileinfo.path, type: "gpx" }); - files.sort((a, b) => { - return b.name.localeCompare(a.name); + files_.push({ + name: fileinfo.name, + path: file.name, + type: "gpx", }); - document.getElementById("gpx-title").style.display = "block"; }); } catch (e) {} @@ -487,29 +555,8 @@ document.addEventListener("DOMContentLoaded", function () { let filename = e.split("/"); filename = filename[filename.length - 1]; files_.push({ name: filename, path: e, type: "gpx" }); - files.push({ name: filename, path: e, type: "gpx" }); - files.sort((a, b) => { - return b.name.localeCompare(a.name); - }); - files.forEach((e) => { - document - .querySelector("div#gpx") - .insertAdjacentHTML( - "afterend", - '
' + - e.name + - "
" - ); - //load gpx file on start - if (e.name.substring(0, 1) == "_") { - module.loadGPX(e.path); - } - }); + writeFileList(files_); }; try { @@ -526,8 +573,6 @@ document.addEventListener("DOMContentLoaded", function () { let find_geojson = function () { try { - let files = []; - //search geojson let finder = new Applait.Finder({ type: "sdcard", @@ -536,44 +581,14 @@ document.addEventListener("DOMContentLoaded", function () { finder.search(".geojson"); finder.on("searchComplete", function (needle, filematchcount) { - files.forEach((e) => { - document - .querySelector("div#tracksmarkers") - .insertAdjacentHTML( - "afterend", - '
' + - e.name + - "
" - ); - //load startup item - - if (e.name.substring(0, 1) == "_") { - module.loadGeoJSON(e.path + "/" + e.name, false); - } - document.getElementById("tracks-title").style.display = "block"; - }); + writeFileList(files_); }); finder.on("fileFound", function (file, fileinfo, storageName) { files_.push({ name: fileinfo.name, - path: fileinfo.path, - type: "geoJSON", - }); - - files.push({ - name: fileinfo.name, - path: fileinfo.path, + path: file.name, type: "geoJSON", }); - files.sort((a, b) => { - return b.name.localeCompare(a.name); - }); }); } catch (e) {} @@ -585,30 +600,7 @@ document.addEventListener("DOMContentLoaded", function () { filename = filename[filename.length - 1]; files_.push({ name: filename, path: e, type: "geoJSON" }); - files.push({ name: filename, path: e, type: "geoJSON" }); - files.sort((a, b) => { - return b.name.localeCompare(a.name); - }); - - files.forEach((e) => { - document - .querySelector("div#tracksmarkers") - .insertAdjacentHTML( - "afterend", - '
' + - e.name + - "
" - ); - - if (e.name.substring(0, 1) == "_") { - module.loadGeoJSON(e.path, false); - } - document.getElementById("tracks-title").style.display = "block"; - }); + writeFileList(files_); }; try { @@ -713,8 +705,13 @@ document.addEventListener("DOMContentLoaded", function () { if (localStorage.getItem("openstreetmap_token") == null) { document.getElementById("osm-server-gpx-title").style.display = "none"; } else { - osm.osm_server_list_gpx(); - document.getElementById("osm-server-gpx-title").style.display = "block"; + let osm_server_list_gpx_callback = (e) => { + e.forEach((m) => { + files_.push(m); + }); + writeFileList(files_); + }; + osm.osm_server_list_gpx(osm_server_list_gpx_callback); } const osm_oauth_callback = function () { document.getElementById("osm-user").innerText = @@ -723,18 +720,7 @@ document.addEventListener("DOMContentLoaded", function () { let gpx_callback = function (filename) { helper.side_toaster(filename + " saved", 5000); - document - .querySelector("div#gpx") - .nextSibling.insertAdjacentHTML( - "afterend", - "
" + - filename + - "
" - ); + find_gpx(); hotline_group.clearLayers(); }; @@ -1377,7 +1363,7 @@ document.addEventListener("DOMContentLoaded", function () { document.querySelector("div#markers-option").style.display = "none"; status.windowOpen = "map"; helper.bottom_bar("", "", ""); - module.set_f_upd_markers(); + module.markers_updated(); } if (item_value == "save_marker") { @@ -2362,6 +2348,8 @@ document.addEventListener("DOMContentLoaded", function () { w = module.user_input("return"); } + console.log(setting.export_path + w + ".geojson"); + geojson.save_geojson( setting.export_path + w + ".geojson", "single-direct" @@ -2724,7 +2712,7 @@ document.addEventListener("DOMContentLoaded", function () { L.marker([mainmarker.current_lat, mainmarker.current_lng]).addTo( markers_group ); - module.set_f_upd_markers(); + module.markers_updated(); } break; @@ -2737,7 +2725,7 @@ document.addEventListener("DOMContentLoaded", function () { case "*": if (status.intro) return false; if (status.keylock) return false; - if (status.windowOpen == "map") { + if (status.windowOpen == "map" || status.windowOpen == "marker") { mainmarker.selected_marker = module.select_marker(); } diff --git a/docs/manifest.webapp b/docs/manifest.webapp index fe295b6a..cd5ccb5d 100644 --- a/docs/manifest.webapp +++ b/docs/manifest.webapp @@ -1,5 +1,5 @@ { - "version": "1.9.758", + "version": "1.9.762", "version_name": "hotline", "name": "o.map", "description": "O.map, your ultimate navigation companion for KaiOS-powered devices. O.map is a lightweight and feature-rich map application designed specifically for KaiOS, enabling you to explore and navigate the world with ease. Whether you're a local resident, a tourist, or an adventurer, O.map is here to enhance your journey and keep you on the right track.", @@ -44,7 +44,7 @@ "locales": { "en-US": { "name": "o.map", - "subtitle": "openstreetmap app", + "subtitle": "O.map is a lightweight and feature-rich map application", "description": "O.map, your ultimate navigation companion for KaiOS-powered devices. O.map is a lightweight and feature-rich map application designed specifically for KaiOS, enabling you to explore and navigate the world with ease. Whether you're a local resident, a tourist, or an adventurer, o.map is here to enhance your journey and keep you on the right track." } diff --git a/docs/manifest.webmanifest b/docs/manifest.webmanifest index e8557b8e..3bb6b81f 100644 --- a/docs/manifest.webmanifest +++ b/docs/manifest.webmanifest @@ -2,7 +2,6 @@ "name": "o.map", "id": "o.map", "description": "O.map, your ultimate navigation companion for KaiOS-powered devices. O.map is a lightweight and feature-rich map application designed specifically for KaiOS, enabling you to explore and navigate the world with ease. Whether you're a local resident, a tourist, or an adventurer, O.map is here to enhance your journey and keep you on the right track.", - "lang": "en-US", "start_url": "/index.html", "priority": "high", @@ -22,7 +21,7 @@ ], "b2g_features": { - "version": "2.0.79", + "version": "2.0.81", "id": "o.map", "core": true, "categories": ["utilities"],