Skip to content

Commit

Permalink
openrouteservice
Browse files Browse the repository at this point in the history
  • Loading branch information
strukturart committed Aug 6, 2022
1 parent 27885f6 commit 9b6d01b
Show file tree
Hide file tree
Showing 9 changed files with 337 additions and 131 deletions.
6 changes: 1 addition & 5 deletions application/assets/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
74 changes: 31 additions & 43 deletions application/assets/js/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
61 changes: 61 additions & 0 deletions application/assets/js/route-service.js
Original file line number Diff line number Diff line change
@@ -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,
};
})();
82 changes: 69 additions & 13 deletions application/assets/js/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 =
Expand All @@ -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 () {
Expand Down
Loading

0 comments on commit 9b6d01b

Please sign in to comment.