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) {
var span_id = osm.identifier.replace("/", "_");
nearby_lookup[span_id] = osm;
osm_html += `<span class="osm-candidate" id="${span_id}"> ${osm.distance.toFixed(
1
)}m ${osm.name || "no name"}</span><br>`;
osm_html += `<span class="osm-candidate" id="${span_id}"> ${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 += "</span><br>";
}
candidates.innerHTML = osm_html;
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 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<int:item_id>/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