From 5ce8eb139c79572fd716e93ced28b082d876cfc5 Mon Sep 17 00:00:00 2001 From: Martin Raifer Date: Mon, 20 Jun 2022 19:03:50 +0200 Subject: [PATCH] add fallback values for access field for barriers --- CHANGELOG.md | 1 + modules/ui/fields/access.js | 278 +++++++++++++++++++++--------------- 2 files changed, 166 insertions(+), 113 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4fa13f378..07a535371 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -56,6 +56,7 @@ _Breaking developer changes, which may affect downstream projects or sites that * Disable taginfo suggestions for the `via` field ([#9140], thanks [@k-yle]) * Treat `surface=chipseal` as a paved surface ([#9139], thanks [@k-yle]) * Better fallback icons for untagged points, vertices, lines and areas ([#9157]) +* Add fallback values for access field for barrier presets #### :hammer: Development diff --git a/modules/ui/fields/access.js b/modules/ui/fields/access.js index 28bba6665..9ec529578 100644 --- a/modules/ui/fields/access.js +++ b/modules/ui/fields/access.js @@ -107,109 +107,154 @@ export function uiFieldAccess(field, context) { }; - var placeholdersByHighway = { - footway: { - foot: 'designated', - motor_vehicle: 'no' + const placeholdersByTag = { + highway: { + footway: { + foot: 'designated', + motor_vehicle: 'no' + }, + steps: { + foot: 'yes', + motor_vehicle: 'no', + bicycle: 'no', + horse: 'no' + }, + pedestrian: { + foot: 'yes', + motor_vehicle: 'no' + }, + cycleway: { + motor_vehicle: 'no', + bicycle: 'designated' + }, + bridleway: { + motor_vehicle: 'no', + horse: 'designated' + }, + path: { + foot: 'yes', + motor_vehicle: 'no', + bicycle: 'yes', + horse: 'yes' + }, + motorway: { + foot: 'no', + motor_vehicle: 'yes', + bicycle: 'no', + horse: 'no' + }, + trunk: { + motor_vehicle: 'yes' + }, + primary: { + foot: 'yes', + motor_vehicle: 'yes', + bicycle: 'yes', + horse: 'yes' + }, + secondary: { + foot: 'yes', + motor_vehicle: 'yes', + bicycle: 'yes', + horse: 'yes' + }, + tertiary: { + foot: 'yes', + motor_vehicle: 'yes', + bicycle: 'yes', + horse: 'yes' + }, + residential: { + foot: 'yes', + motor_vehicle: 'yes', + bicycle: 'yes', + horse: 'yes' + }, + unclassified: { + foot: 'yes', + motor_vehicle: 'yes', + bicycle: 'yes', + horse: 'yes' + }, + service: { + foot: 'yes', + motor_vehicle: 'yes', + bicycle: 'yes', + horse: 'yes' + }, + motorway_link: { + foot: 'no', + motor_vehicle: 'yes', + bicycle: 'no', + horse: 'no' + }, + trunk_link: { + motor_vehicle: 'yes' + }, + primary_link: { + foot: 'yes', + motor_vehicle: 'yes', + bicycle: 'yes', + horse: 'yes' + }, + secondary_link: { + foot: 'yes', + motor_vehicle: 'yes', + bicycle: 'yes', + horse: 'yes' + }, + tertiary_link: { + foot: 'yes', + motor_vehicle: 'yes', + bicycle: 'yes', + horse: 'yes' + }, + construction: { + access: 'no' + } }, - steps: { - foot: 'yes', - motor_vehicle: 'no', - bicycle: 'no', - horse: 'no' - }, - pedestrian: { - foot: 'yes', - motor_vehicle: 'no' - }, - cycleway: { - motor_vehicle: 'no', - bicycle: 'designated' - }, - bridleway: { - motor_vehicle: 'no', - horse: 'designated' - }, - path: { - foot: 'yes', - motor_vehicle: 'no', - bicycle: 'yes', - horse: 'yes' - }, - motorway: { - foot: 'no', - motor_vehicle: 'yes', - bicycle: 'no', - horse: 'no' - }, - trunk: { - motor_vehicle: 'yes' - }, - primary: { - foot: 'yes', - motor_vehicle: 'yes', - bicycle: 'yes', - horse: 'yes' - }, - secondary: { - foot: 'yes', - motor_vehicle: 'yes', - bicycle: 'yes', - horse: 'yes' - }, - tertiary: { - foot: 'yes', - motor_vehicle: 'yes', - bicycle: 'yes', - horse: 'yes' - }, - residential: { - foot: 'yes', - motor_vehicle: 'yes', - bicycle: 'yes', - horse: 'yes' - }, - unclassified: { - foot: 'yes', - motor_vehicle: 'yes', - bicycle: 'yes', - horse: 'yes' - }, - service: { - foot: 'yes', - motor_vehicle: 'yes', - bicycle: 'yes', - horse: 'yes' - }, - motorway_link: { - foot: 'no', - motor_vehicle: 'yes', - bicycle: 'no', - horse: 'no' - }, - trunk_link: { - motor_vehicle: 'yes' - }, - primary_link: { - foot: 'yes', - motor_vehicle: 'yes', - bicycle: 'yes', - horse: 'yes' - }, - secondary_link: { - foot: 'yes', - motor_vehicle: 'yes', - bicycle: 'yes', - horse: 'yes' - }, - tertiary_link: { - foot: 'yes', - motor_vehicle: 'yes', - bicycle: 'yes', - horse: 'yes' - }, - construction: { - access: 'no' + barrier: { + bollard: { + access: 'no', + bicycle: 'yes', + foot: 'yes' + }, + bus_trap: { + motor_vehicle: 'no', + psv: 'yes', + foot: 'yes', + bicycle: 'yes' + }, + city_wall: { + access: 'no' + }, + coupure: { + access: 'yes' + }, + cycle_barrier: { + motor_vehicle: 'no' + }, + ditch: { + access: 'no' + }, + entrance: { + access: 'yes' + }, + fence: { + access: 'no' + }, + hedge: { + access: 'no' + }, + jersey_barrier: { + access: 'no' + }, + motorcycle_barrier: { + motor_vehicle: 'no' + }, + rail_guard: { + access: 'no' + } } }; @@ -238,26 +283,33 @@ export function uiFieldAccess(field, context) { if (tags.access && typeof tags.access === 'string') { return tags.access; } - if (tags.highway) { - if (typeof tags.highway === 'string') { - if (placeholdersByHighway[tags.highway] && - placeholdersByHighway[tags.highway][d]) { - - return placeholdersByHighway[tags.highway][d]; + function getPlaceholdersByTag(key, placeholdersByKey) { + if (typeof tags[key] === 'string') { + if (placeholdersByKey[tags[key]] && + placeholdersByKey[tags[key]][d]) { + return placeholdersByKey[tags[key]][d]; } } else { - var impliedAccesses = tags.highway.filter(Boolean).map(function(highwayVal) { - return placeholdersByHighway[highwayVal] && placeholdersByHighway[highwayVal][d]; + var impliedAccesses = tags[key].filter(Boolean).map(function(val) { + return placeholdersByKey[val] && placeholdersByKey[val][d]; }).filter(Boolean); - if (impliedAccesses.length === tags.highway.length && + if (impliedAccesses.length === tags[key].length && new Set(impliedAccesses).size === 1) { - // if all the highway values have the same implied access for this type then use that + // if all the barrier values have the same implied access for this type then use that return impliedAccesses[0]; } } } - if (d === 'access') { + for (const key in placeholdersByTag) { + if (tags[key]) { + const impliedAccess = getPlaceholdersByTag(key, placeholdersByTag[key]); + if (impliedAccess) { + return impliedAccess; + } + } + } + if (d === 'access' && !tags.barrier) { return 'yes'; } return field.placeholder();