From 0bcbae374b346c98acc9c1b96ea117673f20fb62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A2u=20Cao?= Date: Mon, 29 Jun 2026 17:28:00 +0200 Subject: [PATCH] Use "yes" tag values only as fallbacks if there isn't a more specific OSM key --- app/utils/osm.js | 11 ++++++++++- tests/unit/utils/osm-test.js | 6 ++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/app/utils/osm.js b/app/utils/osm.js index b16295c..e0a16b4 100644 --- a/app/utils/osm.js +++ b/app/utils/osm.js @@ -56,15 +56,24 @@ const PLACE_TYPE_KEYS = [ export function getPlaceType(tags) { if (!tags) return null; + let fallbackKey = null; + for (const key of PLACE_TYPE_KEYS) { const value = tags[key]; if (value) { if (value === 'yes') { - return humanizeOsmTag(key); + if (!fallbackKey) { + fallbackKey = key; + } + continue; } return humanizeOsmTag(value); } } + if (fallbackKey) { + return humanizeOsmTag(fallbackKey); + } + return null; } diff --git a/tests/unit/utils/osm-test.js b/tests/unit/utils/osm-test.js index 939937e..97acf83 100644 --- a/tests/unit/utils/osm-test.js +++ b/tests/unit/utils/osm-test.js @@ -89,6 +89,12 @@ module('Unit | Utility | osm', function (hooks) { assert.strictEqual(result, 'Building'); }); + test('getPlaceType ignores generic "yes" values if a more specific tag is present', function (assert) { + const tags = { historic: 'yes', building: 'tower' }; + const result = getPlaceType(tags); + assert.strictEqual(result, 'Tower'); + }); + test('getPlaceType prioritizes order (amenity > shop > building)', function (assert) { // If something is both a shop and a building, it should be a shop const tags = { building: 'yes', shop: 'supermarket' };