mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-21 15:56:56 +02:00
Add Way#affix
This commit is contained in:
@@ -32,6 +32,11 @@ _.extend(iD.Way.prototype, {
|
||||
return this.nodes.indexOf(node) >= 0;
|
||||
},
|
||||
|
||||
affix: function(node) {
|
||||
if (this.nodes[0] === node) return 'prefix';
|
||||
if (this.nodes[this.nodes.length - 1] === node) return 'suffix';
|
||||
},
|
||||
|
||||
isOneWay: function() {
|
||||
return this.tags.oneway === 'yes' ||
|
||||
this.tags.oneway === '1' ||
|
||||
|
||||
@@ -23,7 +23,7 @@ iD.modes.AddLine = function(context) {
|
||||
iD.actions.AddEntity(way),
|
||||
iD.actions.AddVertex(way.id, node.id));
|
||||
|
||||
context.enter(iD.modes.DrawLine(context, way.id, 'forward', graph));
|
||||
context.enter(iD.modes.DrawLine(context, way.id, graph));
|
||||
}
|
||||
|
||||
function startFromWay(loc, edge) {
|
||||
@@ -37,7 +37,7 @@ iD.modes.AddLine = function(context) {
|
||||
iD.actions.AddVertex(way.id, node.id),
|
||||
iD.actions.AddMidpoint({ loc: loc, edge: edge }, node));
|
||||
|
||||
context.enter(iD.modes.DrawLine(context, way.id, 'forward', graph));
|
||||
context.enter(iD.modes.DrawLine(context, way.id, graph));
|
||||
}
|
||||
|
||||
function startFromNode(node) {
|
||||
@@ -47,7 +47,7 @@ iD.modes.AddLine = function(context) {
|
||||
iD.actions.AddEntity(way),
|
||||
iD.actions.AddVertex(way.id, node.id));
|
||||
|
||||
context.enter(iD.modes.DrawLine(context, way.id, 'forward', context.graph()));
|
||||
context.enter(iD.modes.DrawLine(context, way.id, context.graph()));
|
||||
}
|
||||
|
||||
mode.enter = function() {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
iD.modes.DrawLine = function(context, wayId, direction, baseGraph) {
|
||||
iD.modes.DrawLine = function(context, wayId, baseGraph, affix) {
|
||||
var mode = {
|
||||
button: 'line',
|
||||
id: 'draw-line'
|
||||
@@ -8,8 +8,8 @@ iD.modes.DrawLine = function(context, wayId, direction, baseGraph) {
|
||||
|
||||
mode.enter = function() {
|
||||
var way = context.entity(wayId),
|
||||
index = (direction === 'forward') ? undefined : 0,
|
||||
headId = (direction === 'forward') ? way.last() : way.first();
|
||||
index = (affix === 'prefix') ? 0 : undefined,
|
||||
headId = (affix === 'prefix') ? way.first() : way.last();
|
||||
|
||||
behavior = iD.behavior.DrawWay(context, wayId, index, mode, baseGraph)
|
||||
.tail(t('modes.draw_line.tail'));
|
||||
|
||||
@@ -8,7 +8,7 @@ iD.operations.Continue = function(selectedIDs, context) {
|
||||
function candidateWays() {
|
||||
return graph.parentWays(vertex).filter(function(parent) {
|
||||
return parent.geometry(graph) === 'line' &&
|
||||
(parent.first() === vertex.id || parent.last() === vertex.id) &&
|
||||
parent.affix(vertex.id) &&
|
||||
(geometries.line.length === 0 || geometries.line[0] === parent);
|
||||
});
|
||||
}
|
||||
@@ -18,8 +18,8 @@ iD.operations.Continue = function(selectedIDs, context) {
|
||||
context.enter(iD.modes.DrawLine(
|
||||
context,
|
||||
candidate.id,
|
||||
candidate.first() === vertex.id ? 'backward' : 'forward',
|
||||
context.graph()));
|
||||
context.graph(),
|
||||
candidate.affix(vertex.id)));
|
||||
};
|
||||
|
||||
operation.available = function() {
|
||||
|
||||
@@ -48,6 +48,21 @@ describe('iD.Way', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe("#affix", function () {
|
||||
it("returns 'prefix' if the way starts with the given node", function () {
|
||||
expect(iD.Way({nodes: ['a', 'b', 'c']}).affix('a')).to.equal('prefix');
|
||||
});
|
||||
|
||||
it("returns 'suffix' if the way ends with the given node", function () {
|
||||
expect(iD.Way({nodes: ['a', 'b', 'c']}).affix('c')).to.equal('suffix');
|
||||
});
|
||||
|
||||
it("returns falsy if the way does not start or end with the given node", function () {
|
||||
expect(iD.Way({nodes: ['a', 'b', 'c']}).affix('b')).not.to.be.ok;
|
||||
expect(iD.Way({nodes: []}).affix('b')).not.to.be.ok;
|
||||
});
|
||||
});
|
||||
|
||||
describe("#extent", function () {
|
||||
it("returns the minimal extent containing all member nodes", function () {
|
||||
var node1 = iD.Node({loc: [0, 0]}),
|
||||
|
||||
Reference in New Issue
Block a user