Add optional markers for direct location links

This commit is contained in:
Markus Koch 2020-04-26 17:55:32 +02:00
parent ff716d1036
commit 2e67f22044

View File

@ -528,18 +528,22 @@ mymap.on('moveend', update_hash_from_position);
mymap.on('dragstart', function () { is_user_drag = 1;});
mymap.on('keydown', function (e) { if (e.originalEvent.code.match(/Arrow.*/)) is_user_drag = 1;});
mymap.on('overlayadd', function (e) { update_street_width(); update_outline_visibility(); });
function onHashChange(e, hash=null) {
if (!hash)
hash = document.location.hash;
if (hash == "#" + get_current_location_str())
return; // We're already there
coordstr = hash.slice(1).replace(/%20/g, "").split(",");
coordstr = decodeURIComponent(hash.slice(1)).split(",");
if (coordstr.length < 2)
coordstr.push(0); // Default y
if (coordstr.length < 3)
coordstr.push(mymap.getZoom()); // Default zoom
var latlng = L.latLng(parseFloat(coordstr[1]), parseFloat(coordstr[0]));
mymap.setView(latlng, parseInt(coordstr[2]));
if (coordstr.length > 3) { /* Drop named marker */
foo = L.marker(latlng).bindPopup(htmlEntities(coordstr[3])).addTo(mymap).openPopup();
}
}
window.addEventListener("hashchange", onHashChange, false);