mirror of https://github.com/espruino/BangleApps
[mylocation] fix saving without lon; center map on marker
parent
0662aa0234
commit
f28847ab4d
|
@ -76,6 +76,8 @@
|
||||||
map.removeLayer(marker);
|
map.removeLayer(marker);
|
||||||
}
|
}
|
||||||
marker = new L.marker(latlon).addTo(map);
|
marker = new L.marker(latlon).addTo(map);
|
||||||
|
map.setView(latlon); // center on the marker
|
||||||
|
|
||||||
document.getElementById("select-hint").style.display="none";
|
document.getElementById("select-hint").style.display="none";
|
||||||
document.getElementById("select").style.display="";
|
document.getElementById("select").style.display="";
|
||||||
}
|
}
|
||||||
|
@ -84,10 +86,16 @@
|
||||||
setPosition(e.latlng);
|
setPosition(e.latlng);
|
||||||
});
|
});
|
||||||
|
|
||||||
document.getElementById("select").addEventListener("click", function() {
|
function convertMapToFile(map) {
|
||||||
let settings = {}; // {"lat":48.8566,"lon":2.3522,"location":"Paris"}
|
return {lat: map.lat, lon: map.lng};
|
||||||
settings.lat = latlon.lat;
|
}
|
||||||
settings.lon = latlon.lng;
|
|
||||||
|
function convertFileToMap(file) {
|
||||||
|
return {lat: file.lat, lng: file.lon};
|
||||||
|
}
|
||||||
|
|
||||||
|
document.getElementById("select").addEventListener("click", function(e) {
|
||||||
|
let settings = convertMapToFile(latlon); // {"lat":48.8566,"lon":2.3522,"location":"Paris"}
|
||||||
settings.location = "custom";
|
settings.location = "custom";
|
||||||
Util.showModal("Saving...");
|
Util.showModal("Saving...");
|
||||||
Util.writeStorage("mylocation.json", JSON.stringify(settings), ()=>{
|
Util.writeStorage("mylocation.json", JSON.stringify(settings), ()=>{
|
||||||
|
@ -101,7 +109,7 @@
|
||||||
Util.readStorageJSON("mylocation.json", function(data) {
|
Util.readStorageJSON("mylocation.json", function(data) {
|
||||||
if (data===undefined) return; // no file
|
if (data===undefined) return; // no file
|
||||||
try {
|
try {
|
||||||
setPosition(data);
|
setPosition(convertFileToMap(data));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue