htdocs: Link streets, cities, rivers, oceans, ... to the wiki

This commit is contained in:
Markus Koch 2021-12-27 11:54:29 +01:00
parent b5fd6aab1f
commit 66e80778a9

View File

@ -214,6 +214,7 @@ function load_tiles(name, id) {
var current_location = ""; var current_location = "";
var current_feature = null; var current_feature = null;
var current_layer = null;
function load_geojson(name, url, geotype, iconcolor, active=1, style={}) { function load_geojson(name, url, geotype, iconcolor, active=1, style={}) {
var xhttp_ps = new XMLHttpRequest(); var xhttp_ps = new XMLHttpRequest();
xhttp_ps.onreadystatechange = function() { xhttp_ps.onreadystatechange = function() {
@ -232,6 +233,7 @@ function load_geojson(name, url, geotype, iconcolor, active=1, style={}) {
if (geotype == "train") if (geotype == "train")
layer.no_search = true layer.no_search = true
layer.on("click", function (e) { layer.on("click", function (e) {
current_layer = layer;
current_feature = feature; current_feature = feature;
}); });
}; };
@ -684,19 +686,29 @@ var baseballIcon = L.AwesomeMarkers.icon({
markerColor: 'red' markerColor: 'red'
}); });
function escapeHtml(text) {
return text
.replace(/&/g, "&")
.replace(/</g, "&lt;")
.replace(/>/g, "&gt;")
.replace(/"/g, "&quot;")
.replace(/'/g, "&#039;");
}
function onMapClick(e) { function onMapClick(e) {
var addinfo = ""; var addinfo = "";
pos = resolve_latlng(e.latlng); pos = resolve_latlng(e.latlng);
route_links = '<br><a href="#" onclick="latLng2 = L.latLng(' + pos.lng + ',' + pos.lat + '); set_route_start(latLng2); return false;">[route from here]</a>'; route_links = '<br><a href="#" onclick="latLng2 = L.latLng(' + pos.lng + ',' + pos.lat + '); set_route_start(latLng2); return false;">[route from here]</a>';
route_links += ' <a href="#" onclick="latLng2 = L.latLng(' + pos.lng + ',' + pos.lat + '); set_route_destination(latLng2); return false;">[route to here]</a>'; route_links += ' <a href="#" onclick="latLng2 = L.latLng(' + pos.lng + ',' + pos.lat + '); set_route_destination(latLng2); return false;">[route to here]</a>';
if (current_location != "") if (current_location != "")
addinfo = " (part of <a target=\"_blank\" href='" + wikiurl_base + current_location + "'>" + current_location + "</a>)"; addinfo = " (part of <a target=\"_blank\" href=\"" + wikiurl_base + encodeURIComponent(current_location) + "\">" + escapeHtml(current_location) + "</a>)";
if (current_feature) { if (current_feature) {
popup.setLatLng(e.latlng).setContent("This is " + current_feature.properties.name + addinfo + route_links).openOn(mymap); popup.setLatLng(e.latlng).setContent("This is <a target=\"_blank\" href=\"" + wikiurl_base + current_layer.myName + ":" + encodeURIComponent(current_feature.properties.name) + "\">" + escapeHtml(current_feature.properties.name) + "</a>" + addinfo + route_links).openOn(mymap);
} else { } else {
popup.setLatLng(e.latlng).setContent("You clicked the map at " + pos.lng + "," + pos.lat + addinfo + route_links).openOn(mymap); popup.setLatLng(e.latlng).setContent("You clicked the map at " + pos.lng + "," + pos.lat + addinfo + route_links).openOn(mymap);
} }
current_feature = null; current_feature = null;
current_layer = null;
current_location = ""; current_location = "";
} }