Skip to content

Commit

Permalink
initial update to draw modes and hover behavior
Browse files Browse the repository at this point in the history
ref #5811
  • Loading branch information
maxgrossman committed Feb 1, 2019
1 parent fc7fcd1 commit 58e31bc
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 7 deletions.
8 changes: 6 additions & 2 deletions modules/behavior/draw.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { behaviorTail } from './tail';
import { geoChooseEdge, geoVecLength } from '../geo';
import { utilKeybinding, utilRebind } from '../util';

import _isEmpty from 'lodash-es/isEmpty';

var _usedTails = {};
var _disableSpace = false;
Expand All @@ -26,7 +27,7 @@ export function behaviorDraw(context) {

var keybinding = utilKeybinding('draw');

var hover = behaviorHover(context).altDisables(true)
var hover = behaviorHover(context).altDisables(true).ignoreVertex(true)
.on('hover', context.ui().sidebar.hover);
var tail = behaviorTail();
var edit = behaviorEdit(context);
Expand Down Expand Up @@ -116,6 +117,9 @@ export function behaviorDraw(context) {
_mouseLeave = true;
}

function allowsVertex(d) {
return _isEmpty(d.tags) || context.presets().allowsVertex(d, context.graph());
}

// related code
// - `mode/drag_node.js` `doMode()`
Expand All @@ -125,7 +129,7 @@ export function behaviorDraw(context) {
var d = datum();
var target = d && d.properties && d.properties.entity;

if (target && target.type === 'node') { // Snap to a node
if (target && target.type === 'node' && allowsVertex(target)) { // Snap to a node
dispatch.call('clickNode', this, target, d);
return;

Expand Down
6 changes: 5 additions & 1 deletion modules/behavior/draw_way.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { modeBrowse, modeSelect } from '../modes';
import { osmNode } from '../osm';
import { utilKeybinding } from '../util';

import _isEmpty from 'lodash-es/isEmpty';

export function behaviorDrawWay(context, wayId, index, mode, startGraph) {
var origWay = context.entity(wayId);
Expand Down Expand Up @@ -65,6 +66,9 @@ export function behaviorDrawWay(context, wayId, index, mode, startGraph) {
}
}

function allowsVertex(d) {
return _isEmpty(d.tags) || context.presets().allowsVertex(d, context.graph());
}

// related code
// - `mode/drag_node.js` `doMode()`
Expand All @@ -73,7 +77,7 @@ export function behaviorDrawWay(context, wayId, index, mode, startGraph) {
function move(datum) {
context.surface().classed('nope-disabled', d3_event.altKey);

var targetLoc = datum && datum.properties && datum.properties.entity && datum.properties.entity.loc;
var targetLoc = datum && datum.properties && datum.properties.entity && allowsVertex(datum.properties.entity) && datum.properties.entity.loc;
var targetNodes = datum && datum.properties && datum.properties.nodes;
var loc = context.map().mouseCoordinates();

Expand Down
13 changes: 11 additions & 2 deletions modules/behavior/hover.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
import { osmEntity, osmNote, krError } from '../osm';
import { utilKeybinding, utilRebind } from '../util';

import _isEmpty from 'lodash-es/isEmpty';

/*
The hover behavior adds the `.hover` class on mouseover to all elements to which
Expand All @@ -24,6 +25,7 @@ export function behaviorHover(context) {
var _newId = null;
var _buttonDown;
var _altDisables;
var _vertex;
var _target;


Expand Down Expand Up @@ -96,6 +98,9 @@ export function behaviorHover(context) {
.on('mouseup.hover', null, true);
}

function allowsVertex(d) {
return _isEmpty(d.tags) || context.presets().allowsVertex(d, context.graph());
}

function enter(datum) {
if (datum === _target) return;
Expand Down Expand Up @@ -126,7 +131,6 @@ export function behaviorHover(context) {
if (entity.type === 'relation') {
entity.members.forEach(function(member) { selector += ', .' + member.id; });
}

} else if (datum && datum.properties && (datum.properties.entity instanceof osmEntity)) {
entity = datum.properties.entity;
selector = '.' + entity.id;
Expand All @@ -144,7 +148,7 @@ export function behaviorHover(context) {
return;
}

var suppressed = _altDisables && d3_event && d3_event.altKey;
var suppressed = (_altDisables && d3_event && d3_event.altKey) || (_vertex && !allowsVertex(entity, context.graph()));
_selection.selectAll(selector)
.classed(suppressed ? 'hover-suppressed' : 'hover', true);

Expand Down Expand Up @@ -182,6 +186,11 @@ export function behaviorHover(context) {
return behavior;
};

behavior.ignoreVertex = function(val) {
if (!arguments.length) return _vertex;
_vertex = val;
return behavior;
};

return utilRebind(behavior, dispatch, 'on');
}
1 change: 0 additions & 1 deletion modules/modes/drag_node.js
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,6 @@ export function modeDragNode(context) {
}
}


function end(entity) {
if (_isCancelled) return;

Expand Down
33 changes: 32 additions & 1 deletion modules/presets/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export function presetIndex() {
for (var k in entity.tags) {
// If any part of an address is present,
// allow fallback to "Address" preset - #4353
if (k.match(/^addr:/) !== null && geometryMatches['addr:*']) {
if (/^addr:/.test(k) && geometryMatches['addr:*']) {
address = geometryMatches['addr:*'][0];
}

Expand All @@ -67,6 +67,7 @@ export function presetIndex() {
match = keyMatches[i];
}
}

}

if (address && (!match || match.isFallback())) {
Expand All @@ -76,6 +77,36 @@ export function presetIndex() {
});
};

all.allowsVertex = function(entity, resolver) {
return resolver.transient(entity, 'vertexMatch', function() {
var vertexPresets = _index.vertex;
var match;

for (var k in entity.tags) {
var keyMatches = vertexPresets[k];
if (!keyMatches) continue;
for (var i = 0; i < keyMatches.length; i++) {
var preset = keyMatches[i];
if (preset.searchable !== false) {
if (preset.matchScore(entity) > -1) {
match = preset;
break;
}
}
}

if (!match && /^addr:/.test(k) && vertexPresets['addr:*']) {
match = true;
}

if (match) break;

}

return match;
});
};


// Because of the open nature of tagging, iD will never have a complete
// list of tags used in OSM, so we want it to have logic like "assume
Expand Down

0 comments on commit 58e31bc

Please sign in to comment.