Skip to content

Commit

Permalink
Adds undo messages for connecting points to points, vertices, lines, …
Browse files Browse the repository at this point in the history
…and areas; and vertices to sibling and adjacent vertices

Closes openstreetmap#1252
  • Loading branch information
quincylvania committed Nov 6, 2018
1 parent dcc654f commit 50d0b98
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 12 deletions.
16 changes: 12 additions & 4 deletions data/core.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,18 @@ en:
annotation: Removed a member from a relation.
connect:
annotation:
point: Connected a way to a point.
vertex: Connected a way to another.
line: Connected a way to a line.
area: Connected a way to an area.
from_vertex:
to_point: Connected a way to a point.
to_vertex: Connected a way to another.
to_line: Connected a way to a line.
to_area: Connected a way to an area.
to_adjacent_vertex: Merged adjacent points in a way.
to_sibling_vertex: Connected a way to itself.
from_point:
to_point: Merged a point with another.
to_vertex: Merged a point with a point in a way.
to_line: Moved a point to a line.
to_area: Moved a point to an area.
relation: These features can't be connected because they have conflicting relation roles.
restriction: "These features can't be connected because it would damage a \"{relation}\" relation."
disconnect:
Expand Down
18 changes: 14 additions & 4 deletions dist/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,20 @@
},
"connect": {
"annotation": {
"point": "Connected a way to a point.",
"vertex": "Connected a way to another.",
"line": "Connected a way to a line.",
"area": "Connected a way to an area."
"from_vertex": {
"to_point": "Connected a way to a point.",
"to_vertex": "Connected a way to another.",
"to_line": "Connected a way to a line.",
"to_area": "Connected a way to an area.",
"to_adjacent_vertex": "Merged adjacent points in a way.",
"to_sibling_vertex": "Connected a way to itself."
},
"from_point": {
"to_point": "Merged a point with another.",
"to_vertex": "Merged a point with a point in a way.",
"to_line": "Moved a point to a line.",
"to_area": "Moved a point to an area."
}
},
"relation": "These features can't be connected because they have conflicting relation roles.",
"restriction": "These features can't be connected because it would damage a \"{relation}\" relation."
Expand Down
24 changes: 20 additions & 4 deletions modules/modes/drag_node.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import _find from 'lodash-es/find';
import _intersection from 'lodash-es/intersection';

import {
event as d3_event,
Expand Down Expand Up @@ -75,8 +76,23 @@ export function modeDragNode(context) {
}


function connectAnnotation(entity) {
return t('operations.connect.annotation.' + entity.geometry(context.graph()));
function connectAnnotation(nodeEntity, targetEntity) {
var nodeGeometry = nodeEntity.geometry(context.graph());
var targetGeometry = targetEntity.geometry(context.graph());
if (nodeGeometry === 'vertex' && targetGeometry === 'vertex') {
var nodeParentWayIDs = context.graph().parentWays(nodeEntity);
var targetParentWayIDs = context.graph().parentWays(targetEntity);
var sharedParentWays = _intersection(nodeParentWayIDs, targetParentWayIDs);
// if both vertices are part of the same way
if (sharedParentWays.length !== 0) {
// if the nodes are next to each other, they are merged
if (sharedParentWays[0].areAdjacent(nodeEntity.id, targetEntity.id)) {
return t('operations.connect.annotation.from_vertex.to_adjacent_vertex');
}
return t('operations.connect.annotation.from_vertex.to_sibling_vertex');
}
}
return t('operations.connect.annotation.from_' + nodeGeometry + '.to_' + targetGeometry);
}


Expand Down Expand Up @@ -359,13 +375,13 @@ export function modeDragNode(context) {
loc: choice.loc,
edge: [target.nodes[choice.index - 1], target.nodes[choice.index]]
}, entity),
connectAnnotation(target)
connectAnnotation(entity, target)
);

} else if (target && target.type === 'node') {
context.replace(
actionConnect([target.id, entity.id]),
connectAnnotation(target)
connectAnnotation(entity, target)
);

} else if (_wasMidpoint) {
Expand Down

0 comments on commit 50d0b98

Please sign in to comment.