Compare commits

..

No commits in common. "5b5ce97a1a0a8e2bac0b875baddcd59fd8b54b67" and "6a779db77b5983afd955efa6456655c106b8cbaf" have entirely different histories.

2 changed files with 17 additions and 22 deletions

View File

@ -242,27 +242,19 @@ load_geojson("Streets", "./geojson/streets.json", "street", "blue", 0);
L.control.scale().addTo(mymap); 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() { function get_current_location_str() {
var latlng = resolve_latlng(mymap.getCenter()); var latlng = mymap.getCenter();
return latlng.lng + "," + latlng.lat + "," + mymap.getZoom(); return Math.round(latlng.lng) + "," + Math.round(latlng.lat) + "," + mymap.getZoom();
} }
/* Important: Do not use mymap.setView, use this function instead */ /* Important: Do not use mymap.setView, use this function instead */
function jump_to(latlng, zoom = -1) { function jump_to(latlng, zoom = -1) {
if (zoom == -1) if (zoom == -1)
zoom = mymap.getZoom(); zoom = mymap.getZoom();
if (!editor_mode) { if (!editor_mode)
pos = resolve_latlng(latlng); document.location.hash = "#" + Math.round(latlng.lng) + "," + Math.round(latlng.lat) + "," + zoom;
document.location.hash = "#" + pos.lng + "," + pos.lat + "," + zoom; else
} else {
mymap.setView(latlng, zoom); mymap.setView(latlng, zoom);
}
} }
function jump_to_marker(e) { function jump_to_marker(e) {
@ -292,7 +284,7 @@ function toggle_search() {
search_element.style.overflow = "scroll"; search_element.style.overflow = "scroll";
search_element.style.padding = "6px"; search_element.style.padding = "6px";
search_element.style.height = "100%"; search_element.style.height = "100%";
search_element.innerHTML = '<input style="width:100%;" id="search_query" name="lifo_map_search" type="search" placeholder="Start typing to search..." oninput="search(event)"><div id="search_results"></div>' ; search_element.innerHTML = '<input style="width:100%;" id="search_query" name="lifo_map_search" type="search" placeholder="Start typing to search..." onkeypress="search(event)"><div id="search_results"></div>' ;
} }
td = document.getElementById('windowtr').insertCell(0); td = document.getElementById('windowtr').insertCell(0);
@ -302,7 +294,7 @@ function toggle_search() {
td.id = "searchbar"; td.id = "searchbar";
td.appendChild(search_element); td.appendChild(search_element);
document.getElementById('search_query').select(); document.getElementById('search_query').focus();
} }
function htmlEntities(str) { function htmlEntities(str) {
@ -321,9 +313,7 @@ var default_street_color = "#3388ff";
function search(e) { function search(e) {
var query = document.getElementById("search_query").value; var query = document.getElementById("search_query").value;
document.getElementById('search_results').innerHTML = ""; document.getElementById('search_results').innerHTML = "";
if (true) { if (query.length > 0 || e.key == "Enter") {
if (query.length == 0)
query = "!@#$%^&"; // Cheap workaround to (hopefully) match nothing
results = document.createElement("ul"); results = document.createElement("ul");
for (var i = 0; i < layers._layers.length; i++) { for (var i = 0; i < layers._layers.length; i++) {
if (!layers._layers[i].layer._layers) if (!layers._layers[i].layer._layers)
@ -361,8 +351,8 @@ function search(e) {
if (item.feature.properties.name.match(regex)) { if (item.feature.properties.name.match(regex)) {
el = document.createElement("li"); el = document.createElement("li");
zpos = resolve_latlng(layers._layers[i].layer._layers[item._leaflet_id].getCenter()); zpos = 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>"; 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>";
results.appendChild(el); results.appendChild(el);
} }
break; break;
@ -432,8 +422,7 @@ function onMapClick(e) {
if (current_feature) { if (current_feature) {
popup.setLatLng(e.latlng).setContent("This is " + current_feature.properties.name + addinfo).openOn(mymap); popup.setLatLng(e.latlng).setContent("This is " + current_feature.properties.name + addinfo).openOn(mymap);
} else { } else {
pos = resolve_latlng(e.latlng); popup.setLatLng(e.latlng).setContent("You clicked the map at " + e.latlng.toString() + addinfo).openOn(mymap);
popup.setLatLng(e.latlng).setContent("You clicked the map at " + pos.lng + "," + pos.lat + addinfo).openOn(mymap);
} }
current_feature = null; current_feature = null;
current_location = ""; current_location = "";

View File

@ -10,6 +10,12 @@ if (editor_mode) {
var edit_active = 0; 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) { function start_editing(dir = 1) {
// TODO: Check whether we already are in edit mode // 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 // TODO: Detect whether we are cloner to the tail or the head, and issue Fwd or Bwd accordingly