From 7307beff215e74a037cac2ad4bd846804022b351 Mon Sep 17 00:00:00 2001 From: Quincy Morgan Date: Mon, 18 Feb 2019 12:51:50 -0500 Subject: [PATCH] Don't make connect endpoints fix for tag suggest area actionable if there aren't more than two nodes --- modules/validations/tag_suggests_area.js | 83 ++++++++++++------------ 1 file changed, 43 insertions(+), 40 deletions(-) diff --git a/modules/validations/tag_suggests_area.js b/modules/validations/tag_suggests_area.js index 1918af33d..709f314cd 100644 --- a/modules/validations/tag_suggests_area.js +++ b/modules/validations/tag_suggests_area.js @@ -22,51 +22,54 @@ export function validationTagSuggestsArea() { if (tagSuggestsArea) { var tagText = utilTagText({ tags: tagSuggestingArea }); var fixes = []; - var nodes = graph.childNodes(entity), testNodes; - var firstToLastDistanceMeters = geoSphericalDistance(nodes[0].loc, nodes[nodes.length-1].loc); + var connectEndpointsOnClick; - // if the distance is very small, attempt to merge the endpoints - if (firstToLastDistanceMeters < 0.75) { - testNodes = _clone(nodes); - testNodes.pop(); - testNodes.push(testNodes[0]); - // make sure this will not create a self-intersection - if (!geoHasSelfIntersections(testNodes, testNodes[0].id)) { - connectEndpointsOnClick = function() { - var way = this.issue.entities[0]; - context.perform( - actionMergeNodes([way.nodes[0], way.nodes[way.nodes.length-1]], nodes[0].loc), - t('issues.fix.connect_endpoints.annotation') - ); - }; + // must have at least three nodes to close this automatically + if (entity.nodes.length >= 3) { + var nodes = graph.childNodes(entity), testNodes; + var firstToLastDistanceMeters = geoSphericalDistance(nodes[0].loc, nodes[nodes.length-1].loc); + + // if the distance is very small, attempt to merge the endpoints + if (firstToLastDistanceMeters < 0.75) { + testNodes = _clone(nodes); + testNodes.pop(); + testNodes.push(testNodes[0]); + // make sure this will not create a self-intersection + if (!geoHasSelfIntersections(testNodes, testNodes[0].id)) { + connectEndpointsOnClick = function() { + var way = this.issue.entities[0]; + context.perform( + actionMergeNodes([way.nodes[0], way.nodes[way.nodes.length-1]], nodes[0].loc), + t('issues.fix.connect_endpoints.annotation') + ); + }; + } + } + + if (!connectEndpointsOnClick) { + // if the points were not merged, attempt to close the way + testNodes = _clone(nodes); + testNodes.push(testNodes[0]); + // make sure this will not create a self-intersection + if (!geoHasSelfIntersections(testNodes, testNodes[0].id)) { + connectEndpointsOnClick = 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.annotation') + ); + }; + } } } - if (!connectEndpointsOnClick) { - // if the points were not merged, attempt to close the way - testNodes = _clone(nodes); - testNodes.push(testNodes[0]); - // make sure this will not create a self-intersection - if (!geoHasSelfIntersections(testNodes, testNodes[0].id)) { - connectEndpointsOnClick = 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.annotation') - ); - }; - } - } - - if (connectEndpointsOnClick) { - fixes.push(new validationIssueFix({ - title: t('issues.fix.connect_endpoints.title'), - onClick: connectEndpointsOnClick - })); - } + fixes.push(new validationIssueFix({ + title: t('issues.fix.connect_endpoints.title'), + onClick: connectEndpointsOnClick + })); fixes.push(new validationIssueFix({ icon: 'iD-operation-delete',