Add street names to search

This commit is contained in:
Markus Koch 2020-04-19 23:09:26 +02:00
parent 9c703b50aa
commit bfaacd813b
2 changed files with 18 additions and 2 deletions

View File

@ -232,6 +232,14 @@ function toggle_search() {
function htmlEntities(str) { function htmlEntities(str) {
return String(str).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;'); return String(str).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
} }
function polyline_get_middle_coords(coords) {
var ret = [2];
ret[0] = coords[0][0] + (coords[coords.length - 1][0] - coords[0][0]) / 2;
ret[1] = coords[0][1] + (coords[coords.length - 1][1] - coords[0][1]) / 2;
return ret;
}
var regex; var regex;
function search(e) { function search(e) {
var query = htmlEntities(document.getElementById("search_query").value); var query = htmlEntities(document.getElementById("search_query").value);
@ -253,6 +261,15 @@ function search(e) {
results.appendChild(el); results.appendChild(el);
} }
break; break;
case "LineString":
regex = new RegExp(query, 'i');
if (item.feature.properties.name.match(regex)) {
el = document.createElement("li");
zpos = polyline_get_middle_coords(item.feature.geometry.coordinates);
el.innerHTML = "[" + layers._layers[i].name + "] " + '<a href="#" onclick="latLng2 = L.latLng(' + zpos[1] + ',' + zpos[0] + '); jump_to(latLng2); return false;">' + item.feature.properties.name + "</a>";
results.appendChild(el);
}
break;
default: default:
break; break;
} }

View File

@ -78,8 +78,7 @@ if (editor_mode) {
polyline.enableEdit(); polyline.enableEdit();
if (interactive) { if (interactive) {
console.log(coords); console.log(coords);
latlng = L.latLng(coords[0][0] + (coords[coords.length - 1][0] - coords[0][0]) / 2, latlng = L.latLng(polyline_get_middle_coords(coords));
coords[0][1] + (coords[coords.length - 1][1] - coords[0][1]) / 2);
console.log("NEW=" + latlng); console.log("NEW=" + latlng);
jump_to(latlng, 8); jump_to(latlng, 8);
} }