Don't allow adding point-only features as vertices

This commit is contained in:
Quincy Morgan
2019-03-04 17:04:35 -05:00
parent 5e02523396
commit b828ada0e2
9 changed files with 30 additions and 30 deletions

View File

@@ -185,7 +185,7 @@
]
},
"category-water": {
"icon": "iD-category-water",
"icon": "maki-water",
"name": "Water Features",
"members": [
"natural/water/lake",

View File

@@ -1,5 +1,5 @@
{
"icon": "iD-category-water",
"icon": "maki-water",
"name": "Water Features",
"members": [
"natural/water/lake",

View File

@@ -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()
);

View File

@@ -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);

View File

@@ -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'))

View File

@@ -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'))

View File

@@ -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'))

View File

@@ -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;

View File

@@ -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