More map fixes (#982)

* Migrate map (again)

* Improve map navigation
This commit is contained in:
Tim Wilkinson 2023-12-06 12:17:39 -08:00 committed by GitHub
parent 205f6e4ad8
commit 44f7f43abb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 15 deletions

View File

@ -1,10 +1,11 @@
#!/bin/sh
#check for old default map tiles and change to the new map tiles if req'd
#will not change existing custom entries.
OLDTILES='http://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token=pk.eyJ1IjoiazVkbHEiLCJhIjoiY2lqMnlieTM4MDAyNXUwa3A2eHMxdXE3MiJ9.BRFvx4q2vi70z5Uu2zRYQw'
NEWTILES='http://stamen-tiles-{s}.a.ssl.fastly.net/terrain/{z}/{x}/{y}.jpg'
OLDTILES_1='http://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token=pk.eyJ1IjoiazVkbHEiLCJhIjoiY2lqMnlieTM4MDAyNXUwa3A2eHMxdXE3MiJ9.BRFvx4q2vi70z5Uu2zRYQw'
OLDTILES_2='http://stamen-tiles-{s}.a.ssl.fastly.net/terrain/{z}/{x}/{y}.jpg'
NEWTILES='http://tile.openstreetmap.org/{z}/{x}/{y}.png'
MAPTILESERVER=$(/sbin/uci -c /etc/config.mesh get aredn.@map[0].maptiles)
if [ "$MAPTILESERVER" = "$OLDTILES" ]; then
if [ "$MAPTILESERVER" = "$OLDTILES_1" -o "$MAPTILESERVER" = "$OLDTILES_2" ]; then
/sbin/uci -c /etc/config.mesh set aredn.@map[0].maptiles="$NEWTILES"
/sbin/uci -c /etc/config.mesh commit aredn
fi

View File

@ -844,24 +844,23 @@ function loadScript(url, callback) {
var map;
var marker;
var dotIcon;
var leafletLoad = function() {
map = L.map('map').setView([0.0, 0.0], 1);
var dotIcon = L.icon({iconUrl: '/dot.png'});
dotIcon = L.icon({iconUrl: '/dot.png'});
]])
html.print("L.tileLayer('" .. maptiles .. "',")
html.print([[
{
maxZoom: 18,
attribution: 'Map data &copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, ' +
'<a href="http://creativecommons.org/licenses/by/3.0/">CC BY 3.0</a>, ' +
'Imagery &copy;<a href="http://stamen.com">Stamen Design</a>',
id: 'mapbox.streets'
attribution: 'Map data and images &copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, ' +
'<a href="http://creativecommons.org/licenses/by/3.0/">CC BY 3.0</a>'
}).addTo(map);
]])
if tonumber(lat) and tonumber(lon) then
html.print("marker= new L.marker([" .. lat .. "," .. lon .. "],{draggable: true, icon: dotIcon});")
html.print("marker = new L.marker([" .. lat .. "," .. lon .. "],{draggable: true, icon: dotIcon});")
html.print("map.addLayer(marker);")
html.print("map.setView([" .. lat .. "," .. lon .. "],13);")
html.print("marker.on('drag', onMarkerDrag);")
@ -873,11 +872,15 @@ html.print([[
}
function onMapClick(e) {
marker= new L.marker(e.latlng.wrap(),{draggable: true, icon: dotIcon});
map.addLayer(marker);
if (marker) {
marker.setLatLng(e.latlng.wrap());
}
else {
marker = new L.marker(e.latlng.wrap(),{draggable: true, icon: dotIcon});
map.addLayer(marker);
}
document.getElementsByName('latitude')[0].value=e.latlng.wrap().lat.toFixed(6).toString();
document.getElementsByName('longitude')[0].value=e.latlng.wrap().lng.toFixed(6).toString();
map.off('click', onMapClick);
marker.on('drag', onMarkerDrag);
}
@ -908,7 +911,13 @@ function foundLocation(position) {
// try to update the map if Javascript libs have been loaded
if (typeof L != 'undefined') {
var latlng = L.latLng(jlat, jlon);
marker.setLatLng(latlng);
if (marker) {
marker.setLatLng(latlng);
}
else {
marker = new L.marker(latlng.wrap(),{draggable: true, icon: dotIcon});
map.addLayer(marker);
}
map.setView(latlng,13);
}
}
@ -919,11 +928,9 @@ function noLocation() {
try {
const json = JSON.parse(this.responseText);
foundLocation({ coords: { latitude: json.lat, longitude: json.lon }})
return;
}
catch (_) {
}
alert('Could not find location. Try pinning it on the map.');
});
req.open("GET", "http://ip-api.com/json");
req.send();