Skip to content

Commit

Permalink
iD.Way.isOneWay should return false if oneway=no #2220
Browse files Browse the repository at this point in the history
i.e. overrides implied oneway tag like `highway=motorway` or `junction=roundabout`
  • Loading branch information
bhousel committed May 20, 2014
1 parent af41940 commit b8501bc
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
12 changes: 8 additions & 4 deletions js/id/core/way.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,15 @@ _.extend(iD.Way.prototype, {
},

isOneWay: function() {
return this.tags.oneway === 'yes' ||
this.tags.oneway === '1' ||
this.tags.oneway === '-1' ||
this.tags.waterway === 'river' ||
// explicit oneway tag..
if (['yes', '1', '-1'].indexOf(this.tags.oneway) !== -1) { return true; }
if (['no', '0'].indexOf(this.tags.oneway) !== -1) { return false; }

// implied oneway tag..
return this.tags.waterway === 'river' ||
this.tags.waterway === 'stream' ||
this.tags.highway === 'motorway' ||
this.tags.highway === 'motorway_link' ||
this.tags.junction === 'roundabout';
},

Expand Down
23 changes: 15 additions & 8 deletions test/spec/core/way.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,24 +150,31 @@ describe('iD.Way', function() {

describe('#isOneWay', function() {
it('returns false when the way has no tags', function() {
expect(iD.Way().isOneWay()).to.eql(false);
expect(iD.Way().isOneWay()).to.be.false;
});

it('returns false when the way has tag oneway=no', function() {
expect(iD.Way({tags: { oneway: 'no' }}).isOneWay()).to.equal(false);
expect(iD.Way({tags: { oneway: 'no' }}).isOneWay()).to.be.false;
expect(iD.Way({tags: { oneway: '0' }}).isOneWay()).to.be.false;
});

it('returns true when the way has tag oneway=yes', function() {
expect(iD.Way({tags: { oneway: 'yes' }}).isOneWay()).to.equal(true);
expect(iD.Way({tags: { oneway: 'yes' }}).isOneWay()).to.be.true;
expect(iD.Way({tags: { oneway: '1' }}).isOneWay()).to.be.true;
expect(iD.Way({tags: { oneway: '-1' }}).isOneWay()).to.be.true;
});

it('returns true when the way has tag waterway=river or waterway=stream', function() {
expect(iD.Way({tags: { waterway: 'river' }}).isOneWay()).to.equal(true);
expect(iD.Way({tags: { waterway: 'stream' }}).isOneWay()).to.equal(true);
it('returns true when the way has implied oneway tag (waterway=river, waterway=stream, etc)', function() {
expect(iD.Way({tags: { waterway: 'river' }}).isOneWay()).to.be.true;
expect(iD.Way({tags: { waterway: 'stream' }}).isOneWay()).to.be.true;
expect(iD.Way({tags: { highway: 'motorway' }}).isOneWay()).to.be.true;
expect(iD.Way({tags: { highway: 'motorway_link' }}).isOneWay()).to.be.true;
expect(iD.Way({tags: { junction: 'roundabout' }}).isOneWay()).to.be.true;
});

it('returns true when the way has tag junction=roundabout', function() {
expect(iD.Way({tags: { junction: 'roundabout' }}).isOneWay()).to.equal(true);
it('returns false when oneway=no overrides implied oneway tag', function() {
expect(iD.Way({tags: { junction: 'roundabout', oneway: 'no' }}).isOneWay()).to.be.false;
expect(iD.Way({tags: { highway: 'motorway', oneway: 'no' }}).isOneWay()).to.be.false;
});
});

Expand Down

0 comments on commit b8501bc

Please sign in to comment.