Show OSM object type names from id-tagging-schema

This commit is contained in:
Edward Betts 2021-05-14 11:07:32 +02:00
parent ca3544126b
commit 4cfeffd878
2 changed files with 31 additions and 3 deletions

View file

@ -421,9 +421,18 @@ function mouse_events(marker, qid) {
for (const osm of nearby) { for (const osm of nearby) {
var span_id = osm.identifier.replace("/", "_"); var span_id = osm.identifier.replace("/", "_");
nearby_lookup[span_id] = osm; nearby_lookup[span_id] = osm;
osm_html += `<span class="osm-candidate" id="${span_id}"> ${osm.distance.toFixed( osm_html += `<span class="osm-candidate" id="${span_id}"> ${osm.distance.toFixed(1)}m `
1 osm_html += osm.presets.join(", ");
)}m ${osm.name || "no name"}</span><br>`; if (osm.presets.length && osm.name) {
osm_html += ": ";
}
if (osm.name) {
osm_html += osm.name;
}
if (!osm.presets.length && !osm.name) {
osm_html += "no name";
}
osm_html += "</span><br>";
} }
candidates.innerHTML = osm_html; candidates.innerHTML = osm_html;
var span_list = document.getElementsByClassName("osm-candidate"); var span_list = document.getElementsByClassName("osm-candidate");

View file

@ -7,6 +7,8 @@ from matcher import nominatim, model, database, commons, wikidata, wikidata_api
from collections import Counter from collections import Counter
from time import time from time import time
from geoalchemy2 import Geography from geoalchemy2 import Geography
import os
import json
import GeoIP import GeoIP
srid = 4326 srid = 4326
@ -775,6 +777,22 @@ def get_nearby(bbox, item, max_distance=200):
return nearby[:10] return nearby[:10]
def get_presets_from_tags(tags):
preset_dir = app.config["ID_PRESET_DIR"]
found = []
for k, v in tags.items():
filename = os.path.join(preset_dir, k, v + ".json")
if not os.path.exists(filename):
filename = os.path.join(preset_dir, k + ".json")
if not os.path.exists(filename):
continue
data = json.load(open(filename))
name = data["name"]
found.append(name)
return found
@app.route("/api/1/item/Q<int:item_id>/candidates") @app.route("/api/1/item/Q<int:item_id>/candidates")
def api_find_osm_candidates(item_id): def api_find_osm_candidates(item_id):
bounds = request.args.get("bounds") bounds = request.args.get("bounds")
@ -794,6 +812,7 @@ def api_find_osm_candidates(item_id):
"name": name, "name": name,
"tags": tags, "tags": tags,
"geojson": osm.geojson(), "geojson": osm.geojson(),
"presets": get_presets_from_tags(tags),
} }
if hasattr(osm, 'area'): if hasattr(osm, 'area'):
cur["area"] = osm.area cur["area"] = osm.area