diff options
Diffstat (limited to 'htdocs/mapscript.js')
-rw-r--r-- | htdocs/mapscript.js | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/htdocs/mapscript.js b/htdocs/mapscript.js index abba88c..65f7ade 100644 --- a/htdocs/mapscript.js +++ b/htdocs/mapscript.js @@ -232,6 +232,14 @@ function toggle_search() { function htmlEntities(str) { return String(str).replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"'); } + +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; function search(e) { var query = htmlEntities(document.getElementById("search_query").value); @@ -253,6 +261,15 @@ function search(e) { results.appendChild(el); } 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: break; } |