Enable downgrade operation to remove all tags from vertices (close #6756)

This commit is contained in:
Quincy Morgan
2020-09-28 17:49:51 -04:00
parent 61e2d20348
commit 2b8d8960d3
3 changed files with 30 additions and 20 deletions
+1
View File
@@ -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.
+2 -1
View File
@@ -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": {
+27 -19
View File
@@ -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});
};