From 7b9af48c4d42927620952548665d2f3bf57381f9 Mon Sep 17 00:00:00 2001 From: Bryan Housel Date: Tue, 19 Sep 2017 16:55:18 -0400 Subject: [PATCH] If any part of an address is present, allow fallback to "Address" preset (closes #4353) --- data/presets.yaml | 2 +- data/presets/presets.json | 19 +++++++++++-------- data/presets/presets/address.json | 7 +++++-- data/taginfo.json | 2 +- modules/presets/index.js | 13 ++++++++++++- modules/ui/entity_editor.js | 14 +++++++++++--- 6 files changed, 41 insertions(+), 16 deletions(-) diff --git a/data/presets.yaml b/data/presets.yaml index acbbb1f15..215976f12 100644 --- a/data/presets.yaml +++ b/data/presets.yaml @@ -1465,7 +1465,7 @@ en: label: Wikipedia presets: address: - # 'addr:housenumber=*' + # 'addr:*=*' name: Address terms: '' advertising/billboard: diff --git a/data/presets/presets.json b/data/presets/presets.json index ec74f4c7d..bdb0857d4 100644 --- a/data/presets/presets.json +++ b/data/presets/presets.json @@ -158,12 +158,15 @@ "area" ], "tags": { - "addr:housenumber": "*" + "addr:*": "*" }, "addTags": {}, "removeTags": {}, + "reference": { + "key": "addr" + }, "name": "Address", - "matchScore": 0.3 + "matchScore": 0.15 }, "advertising/billboard": { "fields": [ @@ -12109,16 +12112,16 @@ "name": "Tram" }, "relation": { - "name": "Relation", "icon": "relation", - "tags": {}, - "geometry": [ - "relation" - ], "fields": [ "name", "relation" - ] + ], + "geometry": [ + "relation" + ], + "tags": {}, + "name": "Relation" }, "route/ferry": { "icon": "ferry-line", diff --git a/data/presets/presets/address.json b/data/presets/presets/address.json index f65894b55..5b1c09e04 100644 --- a/data/presets/presets/address.json +++ b/data/presets/presets/address.json @@ -8,10 +8,13 @@ "area" ], "tags": { - "addr:housenumber": "*" + "addr:*": "*" }, "addTags": {}, "removeTags": {}, + "reference": { + "key": "addr" + }, "name": "Address", - "matchScore": 0.3 + "matchScore": 0.15 } diff --git a/data/taginfo.json b/data/taginfo.json index 10fc1205e..4b32bc5ae 100644 --- a/data/taginfo.json +++ b/data/taginfo.json @@ -41,7 +41,7 @@ "key": "waterway" }, { - "key": "addr:housenumber" + "key": "addr:*" }, { "key": "advertising", diff --git a/modules/presets/index.js b/modules/presets/index.js index 16ca78c9c..c9ed73abf 100644 --- a/modules/presets/index.js +++ b/modules/presets/index.js @@ -32,8 +32,9 @@ export function presetIndex() { all.match = function(entity, resolver) { var geometry = entity.geometry(resolver); + var address; - // Treat entities on addr:interpolation lines as points, not vertices (#3241) + // Treat entities on addr:interpolation lines as points, not vertices - #3241 if (geometry === 'vertex' && entity.isOnAddressLine(resolver)) { geometry = 'point'; } @@ -43,6 +44,12 @@ export function presetIndex() { match; for (var k in entity.tags) { + // If any part of an address is present, + // allow fallback to "Address" preset - #4353 + if (k.match(/^addr:/) !== null && geometryMatches['addr:*']) { + address = geometryMatches['addr:*'][0]; + } + var keyMatches = geometryMatches[k]; if (!keyMatches) continue; @@ -55,6 +62,10 @@ export function presetIndex() { } } + if (address && (!match || match.isFallback())) { + match = address; + } + return match || all.item(geometry); }; diff --git a/modules/ui/entity_editor.js b/modules/ui/entity_editor.js index cb642fe8e..9bd0a4296 100644 --- a/modules/ui/entity_editor.js +++ b/modules/ui/entity_editor.js @@ -183,11 +183,19 @@ export function uiEntityEditor(context) { function historyChanged() { if (state === 'hide') return; - var entity = context.hasEntity(entityId), - graph = context.graph(); + var entity = context.hasEntity(entityId); + var graph = context.graph(); if (!entity) return; - entityEditor.preset(context.presets().match(entity, graph)); + var match = context.presets().match(entity, graph); + var activePreset = entityEditor.preset(); + var weakPreset = activePreset && _.isEmpty(activePreset.addTags); + + // A "weak" preset doesn't set any tags. (e.g. "Address") + // Don't replace a weak preset with a fallback preset (e.g. "Point") + if (!(weakPreset && match.isFallback())) { + entityEditor.preset(match); + } entityEditor.modified(base !== graph); entityEditor(selection); }