From 47ec58e5fcee0c5d29101fbabab9a3fca85f3a5a Mon Sep 17 00:00:00 2001 From: Quincy Morgan Date: Mon, 11 Feb 2019 11:29:34 -0500 Subject: [PATCH] Don't zoom to the end vertex when continuing a disconnected highway if it is already visible Add separate fixes for continuing a disconnected highway from the start and end vertices Highlight the vertex that will be continued --- data/core.yaml | 8 +++-- dist/locales/en.json | 7 ++-- modules/core/validator.js | 3 ++ modules/ui/entity_issues.js | 10 ++++++ modules/validations/disconnected_way.js | 47 ++++++++++++++----------- 5 files changed, 50 insertions(+), 25 deletions(-) diff --git a/data/core.yaml b/data/core.yaml index 251057a27..975e7e1dd 100644 --- a/data/core.yaml +++ b/data/core.yaml @@ -1249,8 +1249,10 @@ en: connect_almost_junction: title: Connect the features undo_redo: Connected very close features. - continue_feature: - title: Continue this feature + continue_from_start: + title: Continue drawing from start + continue_from_end: + title: Continue drawing from end delete_feature: title: Delete this feature connect_endpoints: @@ -1642,4 +1644,4 @@ en: wikidata: identifier: "Identifier" label: "Label" - description: "Description" \ No newline at end of file + description: "Description" diff --git a/dist/locales/en.json b/dist/locales/en.json index 403a833a3..0dddd321e 100644 --- a/dist/locales/en.json +++ b/dist/locales/en.json @@ -1532,8 +1532,11 @@ "title": "Connect the features", "undo_redo": "Connected very close features." }, - "continue_feature": { - "title": "Continue this feature" + "continue_from_start": { + "title": "Continue drawing from start" + }, + "continue_from_end": { + "title": "Continue drawing from end" }, "delete_feature": { "title": "Delete this feature" diff --git a/modules/core/validator.js b/modules/core/validator.js index b1312969d..c0ea3049e 100644 --- a/modules/core/validator.js +++ b/modules/core/validator.js @@ -229,6 +229,9 @@ export function validationIssueFix(attrs) { this.title = attrs.title; this.onClick = attrs.onClick; + // IDs of fix-specific entities. Used for hover-higlighting. + this.entityIds = attrs.entityIds || []; + // the issue this fix is for this.issue = null; } diff --git a/modules/ui/entity_issues.js b/modules/ui/entity_issues.js index f908f65a9..88df13b84 100644 --- a/modules/ui/entity_issues.js +++ b/modules/ui/entity_issues.js @@ -147,6 +147,16 @@ export function uiEntityIssues(context) { }) .on('click', function(d) { d.onClick(); + }) + .on('mouseover.highlight', function(d) { + d.entityIds.forEach(function(entityId) { + utilHighlightEntity(entityId, true, context); + }); + }) + .on('mouseout.highlight', function(d) { + d.entityIds.forEach(function(entityId) { + utilHighlightEntity(entityId, false, context); + }); }); } }); diff --git a/modules/validations/disconnected_way.js b/modules/validations/disconnected_way.js index 0a8b3d0ae..ca567477f 100644 --- a/modules/validations/disconnected_way.js +++ b/modules/validations/disconnected_way.js @@ -45,28 +45,22 @@ export function validationDisconnectedWay() { entities: [entity], fixes: [ new validationIssueFix({ - title: t('issues.fix.continue_feature.title'), + title: t('issues.fix.continue_from_start.title'), onClick: function() { var way = this.issue.entities[0]; - var childNodes = context.graph().childNodes(way); - var endNodes = [childNodes[0], childNodes[childNodes.length-1]]; - var exclusiveEndNodes = endNodes.filter(function(vertex) { - return graph.parentWays(vertex).length === 1; - }); - var vertex; - if (exclusiveEndNodes.length === 1) { - // prefer an endpoint with no connecting ways - vertex = exclusiveEndNodes[0]; - } else { - // prefer the terminating node - vertex = endNodes[1]; - } - // make sure the vertex is actually visible - context.map().zoomToEase(vertex); - context.enter( - modeDrawLine(context, way.id, context.graph(), way.affix(vertex.id), true) - ); - } + var vertex = context.entity(way.nodes[0]); + continueDrawing(way, vertex, context); + }, + entityIds: [entity.nodes[0]] + }), + new validationIssueFix({ + title: t('issues.fix.continue_from_end.title'), + onClick: function() { + var way = this.issue.entities[0]; + var vertex = context.entity(way.nodes[way.nodes.length-1]); + continueDrawing(way, vertex, context); + }, + entityIds: [entity.nodes[entity.nodes.length-1]] }), new validationIssueFix({ title: t('issues.fix.delete_feature.title'), @@ -82,6 +76,19 @@ export function validationDisconnectedWay() { return issues; }; + function continueDrawing(way, vertex, context) { + + if (!context.map().editable() || + !context.map().extent().contains(vertex.loc)) { + // make sure the vertex is actually visible and editable + context.map().zoomToEase(vertex); + } + + context.enter( + modeDrawLine(context, way.id, context.graph(), way.affix(vertex.id), true) + ); + } + validation.type = type; return validation;