Add quick fix for connecting the endpoints of a line where tags suggest area if it won't create self-intersection

This commit is contained in:
Quincy Morgan
2019-02-05 12:16:46 -05:00
parent a80aaf65db
commit 7dd337383a
3 changed files with 46 additions and 19 deletions
+37 -17
View File
@@ -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
}));
}