Use iD's area tag logic for the tag_suggests_area validation

This commit is contained in:
Quincy Morgan
2019-02-05 13:55:59 -05:00
parent 4f68e71094
commit bfefea422b
4 changed files with 42 additions and 49 deletions
+13 -31
View File
@@ -1,4 +1,3 @@
import _isEmpty from 'lodash-es/isEmpty';
import _clone from 'lodash-es/clone';
import { t } from '../util/locale';
import {
@@ -17,40 +16,23 @@ import {
import { geoHasSelfIntersections, geoSphericalDistance } from '../geo';
// https://github.com/openstreetmap/josm/blob/mirror/src/org/
// openstreetmap/josm/data/validation/tests/UnclosedWays.java#L80
export function validationTagSuggestsArea() {
function tagSuggestsArea(tags) {
if (_isEmpty(tags)) return false;
var areaKeys = ['area', 'building', 'landuse', 'shop', 'tourism'];
for (var i = 0; i < areaKeys.length; i++) {
var key = areaKeys[i];
if (tags[key] !== undefined && tags[key] !== 'no') {
if (key === 'tourism' && tags[key] === 'artwork') {
continue; // exception for tourism=artwork - #5206
} else {
var returnTags = {};
returnTags[key] = tags[key];
return returnTags;
}
}
}
return false;
}
var type = 'tag_suggests_area';
var validation = function(entity, context) {
if (entity.type !== 'way') {
return [];
}
var issues = [];
var graph = context.graph();
var geometry = entity.geometry(graph);
var suggestingTags = (geometry === 'line' ? tagSuggestsArea(entity.tags) : undefined);
var tagSuggestingArea = entity.tagSuggestingArea();
var tagSuggestsArea = !entity.isClosed() && tagSuggestingArea;
if (suggestingTags) {
var tagText = utilTagText({ tags: suggestingTags });
if (tagSuggestsArea) {
var tagText = utilTagText({ tags: tagSuggestingArea });
var fixes = [];
var nodes = graph.childNodes(entity), testNodes;
@@ -96,16 +78,16 @@ export function validationTagSuggestsArea() {
}));
}
fixes.push(new validationIssueFix({
title: t('issues.fix.remove_tags.title'),
title: t('issues.fix.remove_tag.title'),
onClick: function() {
var entity = this.issue.entities[0];
var tags = _clone(entity.tags);
for (var key in suggestingTags) {
for (var key in tagSuggestingArea) {
delete tags[key];
}
context.perform(
actionChangeTags(entity.id, tags),
t('issues.fix.remove_tags.undo_redo')
t('issues.fix.remove_tag.undo_redo')
);
}
}));
@@ -113,7 +95,7 @@ export function validationTagSuggestsArea() {
issues.push(new validationIssue({
type: type,
severity: 'warning',
message: t('issues.tag_suggests_area.message', { feature: featureLabel, tags: tagText }),
message: t('issues.tag_suggests_area.message', { feature: featureLabel, tag: tagText }),
tooltip: t('issues.tag_suggests_area.tip'),
entities: [entity],
fixes: fixes