Compare commits

..

2 Commits

Author SHA1 Message Date
5b5ce97a1a Fix search behavior
Before, it was always searching for the current term without
the last entered (or with the last deleted) character. This
behavior is fixed now. Also, an empty query will now match
(hopefully) nothing instead of everything.
2020-04-25 17:34:33 +02:00
d229044ebf Fix coordinate order on popover, clean up resolve_latlng 2020-04-25 17:21:38 +02:00
2 changed files with 22 additions and 17 deletions

View File

@ -242,20 +242,28 @@ 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) {
jump_to(e.target.getLatLng());
@ -284,7 +292,7 @@ function toggle_search() {
search_element.style.overflow = "scroll";
search_element.style.padding = "6px";
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..." onkeypress="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..." oninput="search(event)"><div id="search_results"></div>' ;
}
td = document.getElementById('windowtr').insertCell(0);
@ -294,7 +302,7 @@ function toggle_search() {
td.id = "searchbar";
td.appendChild(search_element);
document.getElementById('search_query').focus();
document.getElementById('search_query').select();
}
function htmlEntities(str) {
@ -313,7 +321,9 @@ var default_street_color = "#3388ff";
function search(e) {
var query = document.getElementById("search_query").value;
document.getElementById('search_results').innerHTML = "";
if (query.length > 0 || e.key == "Enter") {
if (true) {
if (query.length == 0)
query = "!@#$%^&"; // Cheap workaround to (hopefully) match nothing
results = document.createElement("ul");
for (var i = 0; i < layers._layers.length; i++) {
if (!layers._layers[i].layer._layers)
@ -351,8 +361,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 +432,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