mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-14 13:18:15 +02:00
Add some utility methods to Way
This commit is contained in:
+13
-1
@@ -14,12 +14,24 @@ iD.Way = iD.Entity.extend({
|
||||
});
|
||||
},
|
||||
|
||||
first: function() {
|
||||
return this.nodes[0];
|
||||
},
|
||||
|
||||
last: function() {
|
||||
return this.nodes[this.nodes.length - 1];
|
||||
},
|
||||
|
||||
contains: function(node) {
|
||||
return this.nodes.indexOf(node) >= 0;
|
||||
},
|
||||
|
||||
isOneWay: function() {
|
||||
return this.tags.oneway === 'yes';
|
||||
},
|
||||
|
||||
isClosed: function() {
|
||||
return this.nodes.length > 0 && this.nodes[this.nodes.length - 1] === this.nodes[0];
|
||||
return this.nodes.length > 0 && this.first() === this.last();
|
||||
},
|
||||
|
||||
// a way is an area if:
|
||||
|
||||
@@ -13,7 +13,7 @@ iD.modes.DrawArea = function(wayId) {
|
||||
headId = (way.nodes.length == 1) ?
|
||||
way.nodes[0] :
|
||||
way.nodes[way.nodes.length - 2],
|
||||
tailId = _.first(way.nodes),
|
||||
tailId = way.first(),
|
||||
node = iD.Node({loc: map.mouseCoordinates()});
|
||||
|
||||
map.dblclickEnable(false)
|
||||
|
||||
@@ -12,8 +12,8 @@ iD.modes.DrawLine = function(wayId, direction) {
|
||||
way = history.graph().entity(wayId),
|
||||
node = iD.Node({loc: map.mouseCoordinates()}),
|
||||
index = (direction === 'forward') ? undefined : 0,
|
||||
headId = (direction === 'forward') ? _.last(way.nodes) : _.first(way.nodes),
|
||||
tailId = (direction === 'forward') ? _.first(way.nodes) : _.last(way.nodes);
|
||||
headId = (direction === 'forward') ? way.last() : way.first(),
|
||||
tailId = (direction === 'forward') ? way.first() : way.last();
|
||||
|
||||
iD.behavior.Hover()(surface);
|
||||
|
||||
|
||||
@@ -35,6 +35,28 @@ describe('iD.Way', function() {
|
||||
expect(iD.Way({tags: {foo: 'bar'}}).tags).to.eql({foo: 'bar'});
|
||||
});
|
||||
|
||||
describe("#first", function () {
|
||||
it("returns the first node", function () {
|
||||
expect(iD.Way({nodes: ['a', 'b', 'c']}).first()).to.equal('a');
|
||||
});
|
||||
});
|
||||
|
||||
describe("#last", function () {
|
||||
it("returns the last node", function () {
|
||||
expect(iD.Way({nodes: ['a', 'b', 'c']}).last()).to.equal('c');
|
||||
});
|
||||
});
|
||||
|
||||
describe("#contains", function () {
|
||||
it("returns true if the way contains the given node", function () {
|
||||
expect(iD.Way({nodes: ['a', 'b', 'c']}).contains('b')).to.be.true;
|
||||
});
|
||||
|
||||
it("returns false if the way does not contain the given node", function () {
|
||||
expect(iD.Way({nodes: ['a', 'b', 'c']}).contains('d')).to.be.false;
|
||||
});
|
||||
});
|
||||
|
||||
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