meshviewer/lib/infobox/location.js

72 lines
2.5 KiB
JavaScript
Raw Normal View History

define(['helper'], function (helper) {
'use strict';
2016-05-27 21:59:01 +00:00
return function (config, el, router, d) {
var sidebarTitle = document.createElement('h2');
2017-04-20 22:43:39 +00:00
sidebarTitle.textContent = _.t('location.location');
el.appendChild(sidebarTitle);
2017-01-28 14:33:13 +00:00
helper.getJSON(config.reverseGeocodingApi + '?format=json&lat=' + d.lat + '&lon=' + d.lng + '&zoom=18&addressdetails=0&accept-language=' + _.locale())
.then(function (result) {
if (result.display_name) {
2017-04-20 22:43:39 +00:00
sidebarTitle.outerHTML += '<p>' + result.display_name + '</p>';
}
});
var editLat = document.createElement('input');
2017-10-21 00:06:42 +00:00
editLat.setAttribute('aria-label', _.t('location.latitude'));
editLat.type = 'text';
editLat.value = d.lat.toFixed(9);
2017-01-28 14:33:13 +00:00
el.appendChild(createBox('lat', _.t('location.latitude'), editLat));
var editLng = document.createElement('input');
2017-10-21 00:06:42 +00:00
editLng.setAttribute('aria-label', _.t('location.longitude'));
editLng.type = 'text';
editLng.value = d.lng.toFixed(9);
2017-01-28 14:33:13 +00:00
el.appendChild(createBox('lng', _.t('location.longitude'), editLng));
var editUci = document.createElement('textarea');
2017-10-21 00:06:42 +00:00
editUci.setAttribute('aria-label', 'Uci');
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) + "';" +
'uci commit gluon-node-info';
el.appendChild(createBox('uci', 'Uci', editUci));
function createBox(name, title, inputElem) {
var box = document.createElement('div');
var heading = document.createElement('h3');
heading.textContent = title;
box.appendChild(heading);
var btn = document.createElement('button');
btn.classList.add('ion-clipboard');
2017-01-28 14:33:13 +00:00
btn.title = _.t('location.copy');
2017-10-21 00:06:42 +00:00
btn.setAttribute('aria-label', _.t('location.copy'));
btn.onclick = function onclick() {
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 20:03:33 +00:00
function copy2clip(id) {
var copyField = document.querySelector('#' + id);
copyField.select();
2016-02-25 20:03:33 +00:00
try {
document.execCommand('copy');
2016-02-25 20:03:33 +00:00
} catch (err) {
2016-05-26 16:37:24 +00:00
console.warn(err);
2016-02-25 20:03:33 +00:00
}
}
};
});