From 7dd337383a9599fb65144592a196cbd5ae8be8ef Mon Sep 17 00:00:00 2001 From: Quincy Morgan Date: Tue, 5 Feb 2019 12:16:46 -0500 Subject: [PATCH] Add quick fix for connecting the endpoints of a line where tags suggest area if it won't create self-intersection --- data/core.yaml | 5 ++- dist/locales/en.json | 6 ++- modules/validations/tag_suggests_area.js | 54 ++++++++++++++++-------- 3 files changed, 46 insertions(+), 19 deletions(-) diff --git a/data/core.yaml b/data/core.yaml index dd6c70be5..32b6d4644 100644 --- a/data/core.yaml +++ b/data/core.yaml @@ -1234,7 +1234,7 @@ en: message: "{multipolygon} has misplaced tags." tip: Multipolygons should be tagged on their relation, not their outer way. tag_suggests_area: - message: 'Feature is a line, but the tag "{tag}" suggests it should be an area.' + message: '{feature} should be an area based on the tags: {tags}' tip: Areas must have connected endpoints. fix: add_connection_vertex: @@ -1247,6 +1247,9 @@ en: title: Continue this feature delete_feature: title: Delete this feature + connect_endpoints: + title: Connect the ends + undo_redo: Connected the endpoints of a way. move_tags: title: Move the tags undo_redo: Moved tags. diff --git a/dist/locales/en.json b/dist/locales/en.json index f37e3a27a..41d8ddf71 100644 --- a/dist/locales/en.json +++ b/dist/locales/en.json @@ -1511,7 +1511,7 @@ "tip": "Multipolygons should be tagged on their relation, not their outer way." }, "tag_suggests_area": { - "message": "Feature is a line, but the tag \"{tag}\" suggests it should be an area.", + "message": "{feature} should be an area based on the tags: {tags}", "tip": "Areas must have connected endpoints." }, "fix": { @@ -1529,6 +1529,10 @@ "delete_feature": { "title": "Delete this feature" }, + "connect_endpoints": { + "title": "Connect the ends", + "undo_redo": "Connected the endpoints of a way." + }, "move_tags": { "title": "Move the tags", "undo_redo": "Moved tags." diff --git a/modules/validations/tag_suggests_area.js b/modules/validations/tag_suggests_area.js index d442c2d6d..5ecdb3eb5 100644 --- a/modules/validations/tag_suggests_area.js +++ b/modules/validations/tag_suggests_area.js @@ -2,6 +2,7 @@ import _isEmpty from 'lodash-es/isEmpty'; import _clone from 'lodash-es/clone'; import { t } from '../util/locale'; import { + utilDisplayLabel, utilTagText } from '../util'; import { @@ -9,8 +10,10 @@ import { validationIssueFix } from '../core/validator'; import { + actionAddVertex, actionChangeTags } from '../actions'; +import { geoHasSelfIntersections } from '../geo'; // https://github.com/openstreetmap/josm/blob/mirror/src/org/ @@ -47,28 +50,45 @@ export function validationTagSuggestsArea() { if (suggestingTags) { var tagText = utilTagText({ tags: suggestingTags }); + var fixes = []; + var nodes = _clone(graph.childNodes(entity)); + nodes.push(nodes[0]); + if (!geoHasSelfIntersections(nodes, nodes[0].id)) { + fixes.push(new validationIssueFix({ + title: t('issues.fix.connect_endpoints.title'), + onClick: function() { + var way = this.issue.entities[0]; + var nodeId = way.nodes[0]; + var index = way.nodes.length; + context.perform( + actionAddVertex(way.id, nodeId, index), + t('issues.fix.connect_endpoints.undo_redo') + ); + } + })); + } + fixes.push(new validationIssueFix({ + title: t('issues.fix.remove_tags.title'), + onClick: function() { + var entity = this.issue.entities[0]; + var tags = _clone(entity.tags); + for (var key in suggestingTags) { + delete tags[key]; + } + context.perform( + actionChangeTags(entity.id, tags), + t('issues.fix.remove_tags.undo_redo') + ); + } + })); + var featureLabel = utilDisplayLabel(entity, context); issues.push(new validationIssue({ type: type, severity: 'warning', - message: t('issues.tag_suggests_area.message', { tag: tagText }), + message: t('issues.tag_suggests_area.message', { feature: featureLabel, tags: tagText }), tooltip: t('issues.tag_suggests_area.tip'), entities: [entity], - fixes: [ - new validationIssueFix({ - title: t('issues.fix.remove_tags.title'), - onClick: function() { - var entity = this.issue.entities[0]; - var tags = _clone(entity.tags); - for (var key in suggestingTags) { - delete tags[key]; - } - context.perform( - actionChangeTags(entity.id, tags), - t('issues.fix.remove_tags.undo_redo') - ); - } - }) - ] + fixes: fixes })); }