diff --git a/htdocs/mapscript.js b/htdocs/mapscript.js index abe85a6..ff1d22e 100644 --- a/htdocs/mapscript.js +++ b/htdocs/mapscript.js @@ -242,19 +242,27 @@ load_geojson("Streets", "./geojson/streets.json", "street", "blue", 0); L.control.scale().addTo(mymap); +function resolve_latlng(latlng, recenter = 0) { + latlng.lng = Math.round(latlng.lng); + latlng.lat = Math.round(latlng.lat); + return latlng; +} + function get_current_location_str() { - var latlng = mymap.getCenter(); - return Math.round(latlng.lng) + "," + Math.round(latlng.lat) + "," + mymap.getZoom(); + var latlng = resolve_latlng(mymap.getCenter()); + return latlng.lng + "," + latlng.lat + "," + mymap.getZoom(); } /* Important: Do not use mymap.setView, use this function instead */ function jump_to(latlng, zoom = -1) { if (zoom == -1) zoom = mymap.getZoom(); - if (!editor_mode) - document.location.hash = "#" + Math.round(latlng.lng) + "," + Math.round(latlng.lat) + "," + zoom; - else + if (!editor_mode) { + pos = resolve_latlng(latlng); + document.location.hash = "#" + pos.lng + "," + pos.lat + "," + zoom; + } else { mymap.setView(latlng, zoom); + } } function jump_to_marker(e) { @@ -351,8 +359,8 @@ function search(e) { if (item.feature.properties.name.match(regex)) { el = document.createElement("li"); - zpos = layers._layers[i].layer._layers[item._leaflet_id].getCenter(); - el.innerHTML = "[" + layers._layers[i].name + "] " + '' + htmlEntities(item.feature.properties.name) + ""; + zpos = resolve_latlng(layers._layers[i].layer._layers[item._leaflet_id].getCenter()); + el.innerHTML = "[" + layers._layers[i].name + "] " + '' + htmlEntities(item.feature.properties.name) + ""; results.appendChild(el); } break; @@ -422,7 +430,8 @@ function onMapClick(e) { if (current_feature) { popup.setLatLng(e.latlng).setContent("This is " + current_feature.properties.name + addinfo).openOn(mymap); } else { - popup.setLatLng(e.latlng).setContent("You clicked the map at " + e.latlng.toString() + addinfo).openOn(mymap); + pos = resolve_latlng(e.latlng); + popup.setLatLng(e.latlng).setContent("You clicked the map at " + pos.lng + "," + pos.lat + addinfo).openOn(mymap); } current_feature = null; current_location = ""; diff --git a/htdocs/streeteditor.js b/htdocs/streeteditor.js index 76d5732..6c20e23 100644 --- a/htdocs/streeteditor.js +++ b/htdocs/streeteditor.js @@ -10,12 +10,6 @@ if (editor_mode) { var edit_active = 0; - function resolve_latlng(latlng, recenter = 0) { - latlng.lng = Math.round(latlng.lng); - latlng.lat = Math.round(latlng.lat); - return latlng; - } - function start_editing(dir = 1) { // TODO: Check whether we already are in edit mode // TODO: Detect whether we are cloner to the tail or the head, and issue Fwd or Bwd accordingly