From 2b8d8960d39ffab7af52e371bc76ba39c3e4858b Mon Sep 17 00:00:00 2001 From: Quincy Morgan <2046746+quincylvania@users.noreply.github.com> Date: Mon, 28 Sep 2020 17:49:51 -0400 Subject: [PATCH] Enable downgrade operation to remove all tags from vertices (close #6756) --- data/core.yaml | 1 + dist/locales/en.json | 3 ++- modules/operations/downgrade.js | 46 +++++++++++++++++++-------------- 3 files changed, 30 insertions(+), 20 deletions(-) diff --git a/data/core.yaml b/data/core.yaml index c93b25873..89357b7fa 100644 --- a/data/core.yaml +++ b/data/core.yaml @@ -227,6 +227,7 @@ en: building_address: Remove all non-address and non-building tags. building: Remove all non-building tags. address: Remove all non-address tags. + generic: Remove tags. annotation: building: one: Downgraded a feature to a basic building. diff --git a/dist/locales/en.json b/dist/locales/en.json index a439359d6..85e994b07 100644 --- a/dist/locales/en.json +++ b/dist/locales/en.json @@ -300,7 +300,8 @@ "description": { "building_address": "Remove all non-address and non-building tags.", "building": "Remove all non-building tags.", - "address": "Remove all non-address tags." + "address": "Remove all non-address tags.", + "generic": "Remove tags." }, "annotation": { "building": { diff --git a/modules/operations/downgrade.js b/modules/operations/downgrade.js index c0789069d..a37ee0927 100644 --- a/modules/operations/downgrade.js +++ b/modules/operations/downgrade.js @@ -6,26 +6,31 @@ import { uiCmd } from '../ui/cmd'; import { presetManager } from '../presets'; export function operationDowngrade(context, selectedIDs) { - var affectedFeatureCount = 0; - var downgradeType; + var _affectedFeatureCount = 0; + var _downgradeType = downgradeTypeForEntityIDs(selectedIDs); - setDowngradeTypeForEntityIDs(); + var _multi = _affectedFeatureCount === 1 ? 'single' : 'multiple'; - var multi = affectedFeatureCount === 1 ? 'single' : 'multiple'; - - function setDowngradeTypeForEntityIDs() { - for (var i in selectedIDs) { - var entityID = selectedIDs[i]; + function downgradeTypeForEntityIDs(entityIds) { + var downgradeType; + _affectedFeatureCount = 0; + for (var i in entityIds) { + var entityID = entityIds[i]; var type = downgradeTypeForEntityID(entityID); if (type) { - affectedFeatureCount += 1; + _affectedFeatureCount += 1; if (downgradeType && type !== downgradeType) { - downgradeType = 'building_address'; + if (downgradeType !== 'generic' && type !== 'generic') { + downgradeType = 'building_address'; + } else { + downgradeType = 'generic'; + } } else { downgradeType = type; } } } + return downgradeType; } function downgradeTypeForEntityID(entityID) { @@ -43,12 +48,16 @@ export function operationDowngrade(context, selectedIDs) { return 'address'; } - if (entity.geometry(graph) === 'area' && + var geometry = entity.geometry(graph); + if (geometry === 'area' && entity.tags.building && !preset.tags.building) { return 'building'; } + if (geometry === 'vertex' && Object.keys(entity.tags).length) { + return 'generic'; + } return null; } @@ -72,8 +81,7 @@ export function operationDowngrade(context, selectedIDs) { key.match(/^building:.{1,}/) || key.match(/^roof:.{1,}/)) continue; } - // keep address tags for buildings too - if (key.match(/^addr:.{1,}/)) continue; + if (type !== 'generic' && key.match(/^addr:.{1,}/)) continue; delete tags[key]; } @@ -90,7 +98,7 @@ export function operationDowngrade(context, selectedIDs) { operation.available = function () { - return downgradeType; + return _downgradeType; }; @@ -110,19 +118,19 @@ export function operationDowngrade(context, selectedIDs) { operation.tooltip = function () { var disable = operation.disabled(); return disable ? - t('operations.downgrade.' + disable + '.' + multi) : - t('operations.downgrade.description.' + downgradeType); + t('operations.downgrade.' + disable + '.' + _multi) : + t('operations.downgrade.description.' + _downgradeType); }; operation.annotation = function () { var suffix; - if (downgradeType === 'building_address') { + if (_downgradeType === 'building_address') { suffix = 'generic'; } else { - suffix = downgradeType; + suffix = _downgradeType; } - return t('operations.downgrade.annotation.' + suffix, { n: affectedFeatureCount}); + return t('operations.downgrade.annotation.' + suffix, { n: _affectedFeatureCount}); };