Fix coordinate order on popover, clean up resolve_latlng

This commit is contained in:
Markus Koch 2020-04-25 17:21:38 +02:00
parent 6a779db77b
commit d229044ebf
2 changed files with 17 additions and 14 deletions

View File

@ -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 + "] " + '<a href="#" onclick="latLng2 = L.latLng(' + Math.round(zpos.lat) + ',' + Math.round(zpos.lng) + '); jump_to(latLng2, ' + polyconf_show_cities + '); return false;">' + htmlEntities(item.feature.properties.name) + "</a>";
zpos = resolve_latlng(layers._layers[i].layer._layers[item._leaflet_id].getCenter());
el.innerHTML = "[" + layers._layers[i].name + "] " + '<a href="#" onclick="latLng2 = L.latLng(' + zpos.lat + ',' + zpos.lng + '); jump_to(latLng2, ' + polyconf_show_cities + '); return false;">' + htmlEntities(item.feature.properties.name) + "</a>";
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 = "";

View File

@ -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