From 10f7ef2704fe4aa4c361230ce8b9b4fd61338151 Mon Sep 17 00:00:00 2001 From: Quincy Morgan Date: Fri, 6 Mar 2020 15:36:48 -0800 Subject: [PATCH] Add error feedback text when attempting to draw self-intersecting ways --- data/core.yaml | 4 ++++ dist/locales/en.json | 6 ++++++ modules/behavior/draw_way.js | 10 +++++++++- modules/modes/draw_area.js | 7 ++++++- modules/modes/draw_line.js | 7 ++++++- 5 files changed, 31 insertions(+), 3 deletions(-) diff --git a/data/core.yaml b/data/core.yaml index 354c40771..1472f46a2 100644 --- a/data/core.yaml +++ b/data/core.yaml @@ -837,6 +837,10 @@ en: out: Zoom Out cannot_zoom: "Cannot zoom out further in current mode." full_screen: Toggle Full Screen + self_intersection: + error: + lines: Lines cannot cross over themselves. + areas: Areas cannot cross over themselves. QA: osmose: title: Osmose Issue diff --git a/dist/locales/en.json b/dist/locales/en.json index b8ce75455..7b82d6dc9 100644 --- a/dist/locales/en.json +++ b/dist/locales/en.json @@ -1047,6 +1047,12 @@ }, "cannot_zoom": "Cannot zoom out further in current mode.", "full_screen": "Toggle Full Screen", + "self_intersection": { + "error": { + "lines": "Lines cannot cross over themselves.", + "areas": "Areas cannot cross over themselves." + } + }, "QA": { "osmose": { "title": "Osmose Issue", diff --git a/modules/behavior/draw_way.js b/modules/behavior/draw_way.js index 8100d25c5..6f241de09 100644 --- a/modules/behavior/draw_way.js +++ b/modules/behavior/draw_way.js @@ -1,3 +1,5 @@ +import { dispatch as d3_dispatch } from 'd3-dispatch'; + import { event as d3_event, select as d3_select @@ -12,10 +14,13 @@ import { geoChooseEdge, geoHasSelfIntersections } from '../geo'; import { modeBrowse } from '../modes/browse'; import { modeSelect } from '../modes/select'; import { osmNode } from '../osm/node'; +import { utilRebind } from '../util/rebind'; import { utilKeybinding } from '../util'; export function behaviorDrawWay(context, wayID, index, mode, startGraph, baselineGraph) { + var dispatch = d3_dispatch('rejectedSelfIntersection'); + var _origWay = context.entity(wayID); var _annotation = t((_origWay.isDegenerate() ? @@ -281,6 +286,7 @@ export function behaviorDrawWay(context, wayID, index, mode, startGraph, baselin // Accept the current position of the drawing node and continue drawing. drawWay.add = function(loc, d) { if ((d && d.properties && d.properties.nope) || context.surface().classed('nope')) { + dispatch.call('rejectedSelfIntersection', this); return; // can't click here } @@ -308,6 +314,7 @@ export function behaviorDrawWay(context, wayID, index, mode, startGraph, baselin // Connect the way to an existing way. drawWay.addWay = function(loc, edge, d) { if ((d && d.properties && d.properties.nope) || context.surface().classed('nope')) { + dispatch.call('rejectedSelfIntersection', this); return; // can't click here } @@ -332,6 +339,7 @@ export function behaviorDrawWay(context, wayID, index, mode, startGraph, baselin // Connect the way to an existing node and continue drawing. drawWay.addNode = function(node, d) { if ((d && d.properties && d.properties.nope) || context.surface().classed('nope')) { + dispatch.call('rejectedSelfIntersection', this); return; // can't click here } @@ -417,5 +425,5 @@ export function behaviorDrawWay(context, wayID, index, mode, startGraph, baselin }; - return drawWay; + return utilRebind(drawWay, dispatch, 'on'); } diff --git a/modules/modes/draw_area.js b/modules/modes/draw_area.js index 2f061b900..d9602ff6a 100644 --- a/modules/modes/draw_area.js +++ b/modules/modes/draw_area.js @@ -1,5 +1,6 @@ import { t } from '../util/locale'; import { behaviorDrawWay } from '../behavior/draw_way'; +import { uiFlash } from '../ui/flash'; export function modeDrawArea(context, wayID, startGraph, baselineGraph, button) { @@ -16,7 +17,11 @@ export function modeDrawArea(context, wayID, startGraph, baselineGraph, button) var way = context.entity(wayID); behavior = behaviorDrawWay(context, wayID, undefined, mode, startGraph, baselineGraph) - .tail(t('modes.draw_area.tail')); + .tail(t('modes.draw_area.tail')) + .on('rejectedSelfIntersection.modeDrawArea', function() { + uiFlash() + .text(t('self_intersection.error.areas'))(); + }); var addNode = behavior.addNode; diff --git a/modules/modes/draw_line.js b/modules/modes/draw_line.js index 1d8d2ba00..356fe6a96 100644 --- a/modules/modes/draw_line.js +++ b/modules/modes/draw_line.js @@ -1,5 +1,6 @@ import { t } from '../util/locale'; import { behaviorDrawWay } from '../behavior/draw_way'; +import { uiFlash } from '../ui/flash'; export function modeDrawLine(context, wayID, startGraph, baselineGraph, button, affix, continuing) { @@ -20,7 +21,11 @@ export function modeDrawLine(context, wayID, startGraph, baselineGraph, button, var headID = (affix === 'prefix') ? way.first() : way.last(); behavior = behaviorDrawWay(context, wayID, index, mode, startGraph, baselineGraph) - .tail(t('modes.draw_line.tail')); + .tail(t('modes.draw_line.tail')) + .on('rejectedSelfIntersection.modeDrawLine', function() { + uiFlash() + .text(t('self_intersection.error.lines'))(); + }); var addNode = behavior.addNode; behavior.addNode = function(node, d) {