diff --git a/htdocs/mapscript.js b/htdocs/mapscript.js index cf45304..cf7066a 100644 --- a/htdocs/mapscript.js +++ b/htdocs/mapscript.js @@ -214,6 +214,7 @@ function load_tiles(name, id) { var current_location = ""; var current_feature = null; +var current_layer = null; function load_geojson(name, url, geotype, iconcolor, active=1, style={}) { var xhttp_ps = new XMLHttpRequest(); xhttp_ps.onreadystatechange = function() { @@ -232,6 +233,7 @@ function load_geojson(name, url, geotype, iconcolor, active=1, style={}) { if (geotype == "train") layer.no_search = true layer.on("click", function (e) { + current_layer = layer; current_feature = feature; }); }; @@ -684,19 +686,29 @@ var baseballIcon = L.AwesomeMarkers.icon({ markerColor: 'red' }); +function escapeHtml(text) { + return text + .replace(/&/g, "&") + .replace(//g, ">") + .replace(/"/g, """) + .replace(/'/g, "'"); +} + function onMapClick(e) { var addinfo = ""; pos = resolve_latlng(e.latlng); route_links = '
[route from here]'; route_links += ' [route to here]'; if (current_location != "") - addinfo = " (part of " + current_location + ")"; + addinfo = " (part of " + escapeHtml(current_location) + ")"; 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 " + escapeHtml(current_feature.properties.name) + "" + addinfo + route_links).openOn(mymap); } else { popup.setLatLng(e.latlng).setContent("You clicked the map at " + pos.lng + "," + pos.lat + addinfo + route_links).openOn(mymap); } current_feature = null; + current_layer = null; current_location = ""; }