From b828ada0e2e366dd4668caec3a7efbfcdac105f9 Mon Sep 17 00:00:00 2001 From: Quincy Morgan Date: Mon, 4 Mar 2019 17:04:35 -0500 Subject: [PATCH] Don't allow adding point-only features as vertices --- data/presets/categories.json | 2 +- data/presets/categories/water.json | 2 +- modules/behavior/draw.js | 6 +++++- modules/behavior/hover.js | 18 +++++++++++++++--- modules/modes/add_area.js | 9 ++------- modules/modes/add_line.js | 9 ++------- modules/modes/add_point.js | 10 +++------- modules/ui/modes.js | 3 +-- modules/ui/search_add.js | 1 - 9 files changed, 30 insertions(+), 30 deletions(-) diff --git a/data/presets/categories.json b/data/presets/categories.json index e3e48b015..04b22f394 100644 --- a/data/presets/categories.json +++ b/data/presets/categories.json @@ -185,7 +185,7 @@ ] }, "category-water": { - "icon": "iD-category-water", + "icon": "maki-water", "name": "Water Features", "members": [ "natural/water/lake", diff --git a/data/presets/categories/water.json b/data/presets/categories/water.json index e45e89ce6..e34dd397a 100644 --- a/data/presets/categories/water.json +++ b/data/presets/categories/water.json @@ -1,5 +1,5 @@ { - "icon": "iD-category-water", + "icon": "maki-water", "name": "Water Features", "members": [ "natural/water/lake", diff --git a/modules/behavior/draw.js b/modules/behavior/draw.js index d12eaadd0..49a243905 100644 --- a/modules/behavior/draw.js +++ b/modules/behavior/draw.js @@ -127,11 +127,15 @@ export function behaviorDraw(context) { var d = datum(); var target = d && d.properties && d.properties.entity; + var mode = context.mode(); + + var allowsSnappingToWay = (mode.id !== 'add-point' || mode.preset.matchGeometry('vertex')); + if (target && target.type === 'node' && allowsVertex(target)) { // Snap to a node dispatch.call('clickNode', this, target, d); return; - } else if (target && target.type === 'way') { // Snap to a way + } else if (target && target.type === 'way' && allowsSnappingToWay) { // Snap to a way var choice = geoChooseEdge( context.childNodes(target), context.mouse(), context.projection, context.activeID() ); diff --git a/modules/behavior/hover.js b/modules/behavior/hover.js index 63b26751b..6cc286b93 100644 --- a/modules/behavior/hover.js +++ b/modules/behavior/hover.js @@ -107,6 +107,15 @@ export function behaviorHover(context) { return d.geometry(context.graph()) === 'vertex' || context.presets().allowsVertex(d, context.graph()); } + function modeAllowsHover(target) { + var mode = context.mode(); + if (mode.id === 'add-point') { + return mode.preset.matchGeometry('vertex') || + (target.type !== 'way' && target.geometry(context.graph()) !== 'vertex'); + } + return true; + } + function enter(datum) { if (datum === _target) return; _target = datum; @@ -144,17 +153,20 @@ export function behaviorHover(context) { } } + var mode = context.mode(); + // Update hover state and dispatch event if (entity && entity.id !== _newNodeId) { // If drawing a way, don't hover on a node that was just placed. #3974 - var mode = context.mode() && context.mode().id; - if ((mode === 'draw-line' || mode === 'draw-area') && !_newNodeId && entity.type === 'node') { + + if ((mode.id === 'draw-line' || mode.id === 'draw-area') && !_newNodeId && entity.type === 'node') { _newNodeId = entity.id; return; } var suppressed = (_altDisables && d3_event && d3_event.altKey) || - (entity.type === 'node' && _ignoreVertex && !allowsVertex(entity)); + (entity.type === 'node' && _ignoreVertex && !allowsVertex(entity)) || + !modeAllowsHover(entity); _selection.selectAll(selector) .classed(suppressed ? 'hover-suppressed' : 'hover', true); diff --git a/modules/modes/add_area.js b/modules/modes/add_area.js index 0be3637db..891cd0631 100644 --- a/modules/modes/add_area.js +++ b/modules/modes/add_area.js @@ -10,13 +10,8 @@ import { modeDrawArea } from './index'; import { osmNode, osmWay } from '../osm'; -export function modeAddArea(context, customMode) { - var mode = customMode || { - id: 'add-area', - button: 'area', - title: t('modes.add_area.title'), - description: t('modes.add_area.description') - }; +export function modeAddArea(context, mode) { + mode.id = 'add-area'; var behavior = behaviorAddWay(context) .tail(t('modes.add_area.tail')) diff --git a/modules/modes/add_line.js b/modules/modes/add_line.js index 032c96e3b..c4e6801f1 100644 --- a/modules/modes/add_line.js +++ b/modules/modes/add_line.js @@ -10,13 +10,8 @@ import { modeDrawLine } from './index'; import { osmNode, osmWay } from '../osm'; -export function modeAddLine(context, customMode) { - var mode = customMode || { - id: 'add-line', - button: 'line', - title: t('modes.add_line.title'), - description: t('modes.add_line.description') - }; +export function modeAddLine(context, mode) { + mode.id = 'add-line'; var behavior = behaviorAddWay(context) .tail(t('modes.add_line.tail')) diff --git a/modules/modes/add_point.js b/modules/modes/add_point.js index b9dbf7057..1b8b7792e 100644 --- a/modules/modes/add_point.js +++ b/modules/modes/add_point.js @@ -6,13 +6,9 @@ import { osmNode } from '../osm'; import { actionAddMidpoint } from '../actions'; -export function modeAddPoint(context, customMode) { - var mode = customMode || { - id: 'add-point', - button: 'point', - title: t('modes.add_point.title'), - description: t('modes.add_point.description') - }; +export function modeAddPoint(context, mode) { + + mode.id = 'add-point'; var behavior = behaviorDraw(context) .tail(t('modes.add_point.tail')) diff --git a/modules/ui/modes.js b/modules/ui/modes.js index f7728c6ae..15956cd44 100644 --- a/modules/ui/modes.js +++ b/modules/ui/modes.js @@ -89,7 +89,6 @@ export function uiModes(context) { tooltipTitleID = 'modes.add_preset.' + d.geom + '.title'; } var favoriteMode = { - id: markerClass, button: markerClass, title: presetName, description: t(tooltipTitleID, { feature: presetName }), @@ -121,7 +120,7 @@ export function uiModes(context) { var buttonsEnter = buttons.enter() .append('button') .attr('tabindex', -1) - .attr('class', function(d) { return d.id + ' add-button bar-button'; }) + .attr('class', function(d) { return d.button + ' add-button bar-button'; }) .on('click.mode-buttons', function(d) { if (!enabled(d)) return; diff --git a/modules/ui/search_add.js b/modules/ui/search_add.js index e481b1df4..a44ad7ced 100644 --- a/modules/ui/search_add.js +++ b/modules/ui/search_add.js @@ -396,7 +396,6 @@ export function uiSearchAdd(context) { var markerClass = 'add-preset add-' + geometry + ' add-preset-' + preset.name().replace(/\s+/g, '_') + '-' + geometry; var modeInfo = { - id: markerClass, button: markerClass, preset: preset, geometry: geometry