2017-03-18 15:33:49 +01:00
|
|
|
define(["helper"], function (helper) {
|
2016-05-27 23:59:01 +02:00
|
|
|
"use strict";
|
|
|
|
|
2016-02-25 15:47:07 +01:00
|
|
|
return function (config, el, router, d) {
|
2017-03-17 03:14:57 +01:00
|
|
|
var sidebarTitle = document.createElement("h2");
|
|
|
|
sidebarTitle.textContent = "Location: " + d.toString();
|
|
|
|
el.appendChild(sidebarTitle);
|
2016-02-25 15:47:07 +01:00
|
|
|
|
2017-03-18 15:33:49 +01:00
|
|
|
helper.getJSON("https://nominatim.openstreetmap.org/reverse?format=json&lat=" + d.lat + "&lon=" + d.lng + "&zoom=18&addressdetails=0")
|
2017-03-17 03:14:57 +01:00
|
|
|
.then(function (result) {
|
|
|
|
if (result.display_name) {
|
|
|
|
sidebarTitle.textContent = result.display_name;
|
|
|
|
}
|
|
|
|
});
|
2016-02-25 15:47:07 +01:00
|
|
|
|
2017-03-17 03:14:57 +01:00
|
|
|
var editLat = document.createElement("input");
|
|
|
|
editLat.type = "text";
|
|
|
|
editLat.value = d.lat.toFixed(9);
|
|
|
|
el.appendChild(createBox("lat", "Breitengrad", editLat));
|
2016-02-25 15:47:07 +01:00
|
|
|
|
2017-03-17 03:14:57 +01:00
|
|
|
var editLng = document.createElement("input");
|
|
|
|
editLng.type = "text";
|
|
|
|
editLng.value = d.lng.toFixed(9);
|
|
|
|
el.appendChild(createBox("lng", "Längengrad", editLng));
|
2016-02-25 15:47:07 +01:00
|
|
|
|
2017-03-17 03:14:57 +01:00
|
|
|
var editUci = document.createElement("textarea");
|
2016-04-02 22:47:57 +02:00
|
|
|
editUci.value =
|
|
|
|
"uci set gluon-node-info.@location[0]='location'; " +
|
|
|
|
"uci set gluon-node-info.@location[0].share_location='1';" +
|
|
|
|
"uci set gluon-node-info.@location[0].latitude='" + d.lat.toFixed(9) + "';" +
|
|
|
|
"uci set gluon-node-info.@location[0].longitude='" + d.lng.toFixed(9) + "';" +
|
2017-03-17 03:14:57 +01:00
|
|
|
"uci commit gluon-node-info";
|
2016-04-02 22:47:57 +02:00
|
|
|
|
2016-05-27 01:34:42 +02:00
|
|
|
el.appendChild(createBox("uci", "Uci", editUci));
|
2016-04-02 22:47:57 +02:00
|
|
|
|
2017-03-17 03:14:57 +01:00
|
|
|
var linkPlain = document.createElement("a");
|
|
|
|
linkPlain.textContent = "plain";
|
|
|
|
linkPlain.onclick = function () {
|
|
|
|
switch2plain();
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
linkPlain.href = "#";
|
2016-04-02 22:47:57 +02:00
|
|
|
|
2017-03-17 03:14:57 +01:00
|
|
|
var linkUci = document.createElement("a");
|
|
|
|
linkUci.textContent = "uci";
|
|
|
|
linkUci.onclick = function () {
|
|
|
|
switch2uci();
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
linkUci.href = "#";
|
2016-02-25 15:47:07 +01:00
|
|
|
|
2016-05-27 01:34:42 +02:00
|
|
|
function createBox(name, title, inputElem) {
|
2017-03-17 03:14:57 +01:00
|
|
|
var box = document.createElement("div");
|
|
|
|
var heading = document.createElement("h3");
|
|
|
|
heading.textContent = title;
|
|
|
|
box.appendChild(heading);
|
|
|
|
var btn = document.createElement("button");
|
2016-05-27 01:34:42 +02:00
|
|
|
btn.classList.add("ion-ios-copy");
|
2017-03-17 03:14:57 +01:00
|
|
|
btn.title = "Kopieren";
|
|
|
|
btn.onclick = function () {
|
|
|
|
copy2clip(inputElem.id);
|
|
|
|
};
|
|
|
|
inputElem.id = "location-" + name;
|
|
|
|
inputElem.readOnly = true;
|
|
|
|
var line = document.createElement("p");
|
|
|
|
line.appendChild(inputElem);
|
|
|
|
line.appendChild(btn);
|
|
|
|
box.appendChild(line);
|
|
|
|
box.id = "box-" + name;
|
|
|
|
return box;
|
2016-02-25 15:47:07 +01:00
|
|
|
}
|
2016-02-25 21:03:33 +01:00
|
|
|
|
2016-02-25 15:47:07 +01:00
|
|
|
function copy2clip(id) {
|
2017-03-17 03:14:57 +01:00
|
|
|
var copyField = document.querySelector("#" + id);
|
|
|
|
copyField.select();
|
2016-02-25 21:03:33 +01:00
|
|
|
try {
|
2017-03-17 03:14:57 +01:00
|
|
|
document.execCommand("copy");
|
2016-02-25 21:03:33 +01:00
|
|
|
} catch (err) {
|
2017-03-18 15:33:49 +01:00
|
|
|
console.warn(err);
|
2016-02-25 21:03:33 +01:00
|
|
|
}
|
2016-02-25 15:47:07 +01:00
|
|
|
}
|
2016-02-25 21:03:33 +01:00
|
|
|
|
2017-03-17 03:14:57 +01:00
|
|
|
};
|
|
|
|
});
|