diff --git a/application/assets/css/main.css b/application/assets/css/main.css index 79a8cd93..9d927dc0 100644 --- a/application/assets/css/main.css +++ b/application/assets/css/main.css @@ -787,16 +787,12 @@ div#files-option { display: none; } -div#files-option ul { - padding: 5px; - display: block; -} - div#files-option div { color: white; margin: 0 0 10px 0; padding: 5px; background: gray; + display: block; } div#files-option div:focus { diff --git a/application/assets/js/module.js b/application/assets/js/module.js index 23f20961..019e24f2 100644 --- a/application/assets/js/module.js +++ b/application/assets/js/module.js @@ -185,108 +185,96 @@ const module = (() => { //select marker //////////////////// // Flag to keep track of the need - // of generating the new marker lis + // of generating the new marker list var f_upd_markers_list = true; let set_f_upd_markers = function () { f_upd_markers_list = true; }; - contained = []; //makers in map boundingbox + let markers_collection = []; //makers in map boundingbox let l = []; let index = -1; let select_marker = function () { if (f_upd_markers_list) { // Reset contained list - contained = []; + markers_collection = []; //merge markers in viewport if (overpass_group != "") { overpass_group.eachLayer(function (l) { - if (l instanceof L.Marker && map.getBounds().contains(l.getLatLng())) - contained.push(l); + markers_collection.push(l); + if ( + l instanceof L.Marker && + map.getBounds().contains(l.getLatLng()) + ) { + } + //markers_collection.push(l); }); } markers_group.eachLayer(function (l) { - if (l instanceof L.Marker && map.getBounds().contains(l.getLatLng())) - contained.push(l); + markers_collection.push(l); + if (l instanceof L.Marker && map.getBounds().contains(l.getLatLng())) { + } + // markers_collection.push(l); }); // Clear flag f_upd_markers_list = false; } - l = contained; + //l = contained; status.marker_selection = true; status.windowOpen = "marker"; index++; - if (index >= l.length) index = 0; + if (index >= markers_collection.length) index = 0; bottom_bar("cancel", "option", ""); //reset icons and close popus - for (let t = 0; t < l.length; t++) { - let p = l[t].getIcon(); + for (let t = 0; t < markers_collection.length; t++) { + let p = markers_collection[t].getIcon(); if ( p.options.className != "follow-marker" && p.options.className != "goal-marker" ) { - //l[t].setIcon(maps.default_icon); + markers_collection[t].setIcon(maps.default_icon); } - - setTimeout(function () { - l[index].closePopup(); - }, 3000); + markers_collection[index].closePopup(); } - let p = l[index].getIcon(); + + //show selected marker + let p = markers_collection[index].getIcon(); if ( p.options.className != "follow-marker" && p.options.className != "goal-marker" ) { - //l[index].setIcon(maps.select_icon); + markers_collection[index].setIcon(maps.select_icon); } //popup document.querySelector("textarea#popup").value = ""; - let pu = l[index].getPopup(); + let pu = markers_collection[index].getPopup(); if (pu != undefined && pu._content != undefined) { //get popup content document.querySelector("textarea#popup").value = pu._content; //show popup - l[index].bindPopup(pu._content, popup_option).openPopup(); + markers_collection[index] + .bindPopup(pu._content, popup_option) + .openPopup(); //close popup setTimeout(function () { - l[index].closePopup(); + markers_collection[index].closePopup(); }, 3000); } - //check if marker set as startup marker - - for (let i = 0; i < mainmarker.startup_markers.length; i++) { - if ( - l[index]._latlng.lng == mainmarker.startup_markers[i].latlng.lng && - l[index]._latlng.lat == mainmarker.startup_markers[i].latlng.lat - ) { - mainmarker.startup_marker_toggle = true; - document.querySelector( - "div#markers-option div[data-action='set_startup_marker']" - ).innerText = "unset startup marker"; - i = mainmarker.startup_markers.length; - } else { - document.querySelector( - "div#markers-option div[data-action='set_startup_marker']" - ).innerText = "set startup marker"; - mainmarker.startup_marker_toggle = false; - } - } - - map.setView(l[index]._latlng, map.getZoom()); + map.setView(markers_collection[index]._latlng, map.getZoom()); - return l[index]; + return markers_collection[index]; }; //SELECT GPX diff --git a/application/assets/js/route-service.js b/application/assets/js/route-service.js new file mode 100644 index 00000000..ac72d716 --- /dev/null +++ b/application/assets/js/route-service.js @@ -0,0 +1,61 @@ +const rs = ((_) => { + let request = function (from, to, apikey, profile, callback) { + let xhr = new XMLHttpRequest({ + mozSystem: true, + "Content-Type": "application/json", + }); + xhr.open( + "GET", + "https://api.openrouteservice.org/v2/directions/" + + profile + + "?api_key=" + + apikey + + "&" + + "start=" + + from + + "&" + + "end=" + + to + ); + + xhr.timeout = 4000; + + xhr.ontimeout = function (e) {}; + + xhr.onload = function () { + if (xhr.status == 200) { + callback(JSON.parse(xhr.responseText)); + } + if (xhr.status == 403) { + console.log("access forbidden"); + } + // analyze HTTP status of the response + if (xhr.status != 200) { + console.log(xhr.status); + helper.side_toaster("the route could not be loaded.", 2000); + } + }; + + xhr.onerror = function (err) { + console.log(err); + }; + xhr.send(null); + }; + + let addPoint = function (type, action, latlng) { + if (action == "add") { + if (type == "start") { + routing.start = latlng.lng + "," + latlng.lat; + } + + if (type == "end") { + routing.end = latlng.lng + "," + latlng.lat; + } + } + }; + + return { + request, + addPoint, + }; +})(); diff --git a/application/assets/js/settings.js b/application/assets/js/settings.js index a6f61584..5ce55e28 100644 --- a/application/assets/js/settings.js +++ b/application/assets/js/settings.js @@ -6,6 +6,13 @@ const settings = ((_) => { document.getElementById("ipbase-key").value ); + localStorage.setItem( + "routing_profil", + document.getElementById("routing-profil").value + ); + + localStorage.setItem("ors-key", document.getElementById("ors-key").value); + localStorage.setItem( "cache-time", document.getElementById("cache-time").value @@ -50,13 +57,55 @@ const settings = ((_) => { }; let load_settings = function () { - document.getElementById("owm-key").value = setting.openweather_api; - document.getElementById("ipbase-key").value = setting.ipbase_api; - - document.getElementById("cache-time").value = setting.cache_time; - document.getElementById("cache-zoom").value = setting.cache_zoom; - document.getElementById("export-path").value = setting.export_path; - document.getElementById("osm-tag").value = setting.osm_tag; + setting = { + export_path: + localStorage.getItem("export-path") != null + ? localStorage.getItem("export-path") + : "", + osm_tag: localStorage.getItem("osm-tag"), + + cache_time: localStorage["cache-time"] || "10", + cache_zoom: localStorage["cache-zoom"] || "12", + openweather_api: localStorage.getItem("owm-key"), + ipbase_api: localStorage.getItem("ipbase-key"), + ors_api: localStorage.getItem("ors-key"), + routing_profil: localStorage.getItem("routing_profil") + ? localStorage.getItem("routing_profil") + : "foot-hiking", + + useOnlyCache: + localStorage.getItem("useOnlyCache") != null + ? JSON.parse(localStorage.getItem("useOnlyCache")) + : true, + + crosshair: + localStorage.getItem("crosshair") != null + ? JSON.parse(localStorage.getItem("crosshair")) + : true, + scale: + localStorage.getItem("scale") != null + ? JSON.parse(localStorage.getItem("scale")) + : true, + tracking_screenlock: + localStorage.getItem("tracking_screenlock") != null + ? JSON.parse(localStorage.getItem("tracking_screenlock")) + : true, + + measurement: + localStorage.getItem("measurement") != null + ? JSON.parse(localStorage.getItem("measurement")) + : true, + + wikipedia_view: + localStorage.getItem("wikipedia_view") != null + ? JSON.parse(localStorage.getItem("wikipedia_view")) + : true, + + tips_view: + localStorage.getItem("tips_view") != null + ? JSON.parse(localStorage.getItem("tips_view")) + : true, + }; setting.tracking_screenlock ? (document.getElementById("screenlock-ckb").checked = true) @@ -95,12 +144,7 @@ const settings = ((_) => { : (general.measurement_unit = "mil"); ///show / hidde scale - - if (setting.scale) { - scale.addTo(map); - } else { - scale.remove(); - } + setting.scale ? scale.addTo(map) : scale.remove(); if (setting.measurement) { document.querySelector("label[for='measurement-ckb']").innerText = @@ -109,6 +153,18 @@ const settings = ((_) => { document.querySelector("label[for='measurement-ckb']").innerText = "imperial"; } + + //set values in setting page + + document.getElementById("owm-key").value = setting.openweather_api; + document.getElementById("ipbase-key").value = setting.ipbase_api; + document.getElementById("ors-key").value = setting.ors_api; + document.getElementById("routing-profil").value = setting.routing_profil; + + document.getElementById("cache-time").value = setting.cache_time; + document.getElementById("cache-zoom").value = setting.cache_zoom; + document.getElementById("export-path").value = setting.export_path; + document.getElementById("osm-tag").value = setting.osm_tag; }; let load_settings_from_file = function () { diff --git a/application/index.html b/application/index.html index 8423bc63..d51006d0 100644 --- a/application/index.html +++ b/application/index.html @@ -116,7 +116,7 @@ -
+
save marker
set marker as target @@ -124,8 +124,18 @@
remove marker
-
- set as startup marker + +

Routing

+
+ set as start point +
+ +
+ set as end point +
+ +
+ start routing
@@ -136,18 +146,16 @@
-
+
upload gpx file to osm
-
+
delete file
-
+
rename file
-
- download file -
+
download file