From 4cfeffd87886b7cdcb20d9d3d3f2a3bd7f612bc4 Mon Sep 17 00:00:00 2001 From: Edward Betts Date: Fri, 14 May 2021 11:07:32 +0200 Subject: [PATCH] Show OSM object type names from id-tagging-schema --- static/js/map.js | 15 ++++++++++++--- web_view.py | 19 +++++++++++++++++++ 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/static/js/map.js b/static/js/map.js index e0de728..5780a5a 100644 --- a/static/js/map.js +++ b/static/js/map.js @@ -421,9 +421,18 @@ function mouse_events(marker, qid) { for (const osm of nearby) { var span_id = osm.identifier.replace("/", "_"); nearby_lookup[span_id] = osm; - osm_html += ` ${osm.distance.toFixed( - 1 - )}m ${osm.name || "no name"}
`; + osm_html += ` ${osm.distance.toFixed(1)}m ` + osm_html += osm.presets.join(", "); + 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 += "
"; } candidates.innerHTML = osm_html; var span_list = document.getElementsByClassName("osm-candidate"); diff --git a/web_view.py b/web_view.py index 8b83ccf..f3c03d9 100755 --- a/web_view.py +++ b/web_view.py @@ -7,6 +7,8 @@ from matcher import nominatim, model, database, commons, wikidata, wikidata_api from collections import Counter from time import time from geoalchemy2 import Geography +import os +import json import GeoIP srid = 4326 @@ -775,6 +777,22 @@ def get_nearby(bbox, item, max_distance=200): 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/candidates") def api_find_osm_candidates(item_id): bounds = request.args.get("bounds") @@ -794,6 +812,7 @@ def api_find_osm_candidates(item_id): "name": name, "tags": tags, "geojson": osm.geojson(), + "presets": get_presets_from_tags(tags), } if hasattr(osm, 'area'): cur["area"] = osm.area