diff --git a/index.html b/index.html index 9f1ae8e82..b2b53e6c9 100644 --- a/index.html +++ b/index.html @@ -45,7 +45,6 @@ - diff --git a/js/id/graph/entity.js b/js/id/graph/entity.js index 3c7749411..e484458c0 100644 --- a/js/id/graph/entity.js +++ b/js/id/graph/entity.js @@ -34,11 +34,23 @@ iD.Entity.prototype = { }; iD.Node = function(attrs) { - return iD.Entity(_.extend({}, attrs || {}, {type: 'node'})); + return iD.Entity(_.extend({}, attrs || {}, {type: 'node', tags: {}})); }; iD.Way = function(attrs) { - return iD.Entity(_.extend({}, attrs || {}, {type: 'way', nodes: []})); + return iD.Entity(_.extend({}, attrs || {}, {type: 'way', nodes: [], tags: {}})); +}; + +iD.Way.isOneWay = function(d) { + return !!(d.tags.oneway && d.tags.oneway === 'yes'); +}; + +iD.Way.isClosed = function(d) { + return (!d.nodes.length) || d.nodes[d.nodes.length - 1].id === d.nodes[0].id; +}; + +iD.Way.isArea = function(d) { + return iD.Way.isClosed(d) || (d.tags.area && d.tags.area === 'yes'); }; iD.Relation = function(attrs) { diff --git a/js/id/graph/way.js b/js/id/graph/way.js deleted file mode 100644 index 81590be45..000000000 --- a/js/id/graph/way.js +++ /dev/null @@ -1,12 +0,0 @@ -// Way -// wiki: http://wiki.openstreetmap.org/wiki/Way -// -// Ways can either be open or closed. A closed way is such that the -// last node is the first node. -// -// If a a way is _closed_, it is assumed to be an area unless it has a -// `highway` or `barrier` tag and is not also tagged `area`. - -iD.Way.isClosed = function(w) { - return (!w.nodes.length) || w.nodes[w.nodes.length - 1].id === w.nodes[0].id; -}; diff --git a/js/id/renderer/map.js b/js/id/renderer/map.js index cacf85f02..4c5dc0ea8 100644 --- a/js/id/renderer/map.js +++ b/js/id/renderer/map.js @@ -133,10 +133,6 @@ iD.Map = function() { function classActive(d) { return d.id === selection; } - function isArea(a) { - return iD.Way.isClosed(a) || (a.tags.area && a.tags.area === 'yes'); - } - function drawVector(only) { if (surface.style(transformProp) != 'none') return; var all = [], ways = [], areas = [], points = [], waynodes = [], @@ -160,7 +156,7 @@ iD.Map = function() { var a = all[i]; if (a.type === 'way') { a._line = nodeline(a); - if (isArea(a)) areas.push(a); + if (iD.Way.isArea(a)) areas.push(a); else ways.push(a); } else if (a._poi) { points.push(a); @@ -256,7 +252,6 @@ iD.Map = function() { markers.select('image').attr('xlink:href', iD.Style.markerimage); } - function isOneWay(d) { return d.tags.oneway && d.tags.oneway === 'yes'; } function drawStrokes(ways, filter) { var strokes = g.stroke.selectAll('path') .filter(filter) @@ -273,7 +268,7 @@ iD.Map = function() { // Determine the lengths of oneway paths var lengths = {}, - oneways = strokes.filter(isOneWay).each(function(d) { + oneways = strokes.filter(iD.Way.isOneWay).each(function(d) { lengths[d.id] = Math.floor(this.getTotalLength() / alength); }).data(); diff --git a/test/index.html b/test/index.html index 6441b0eba..cba65727f 100644 --- a/test/index.html +++ b/test/index.html @@ -52,7 +52,6 @@ - diff --git a/test/spec/graph/way.js b/test/spec/graph/way.js index 099de038d..13f9f5d49 100644 --- a/test/spec/graph/way.js +++ b/test/spec/graph/way.js @@ -1,14 +1,24 @@ describe('Way', function() { - var way; + describe('#isClosed', function() { + it('is not closed with two distinct nodes', function() { + var open_way = { type: 'way', nodes: [{id: 'n1'}, {id: 'n2'}] }; + expect(iD.Way.isClosed(open_way)).to.equal(false); + }); + it('is not closed with a node loop', function() { + var closed_way = { type: 'way', nodes: [{id: 'n1'}, {id: 'n2'}, {id: 'n1'}] }; + expect(iD.Way.isClosed(closed_way)).to.equal(true); + }); + }); - beforeEach(function() { - way = { type: 'way', nodes: [{id: 'n1'}, {id: 'n2'}] }; - }); - - - describe('#isClosed', function() { - it('is not closed with two distinct nodes ', function() { - expect(iD.Way.isClosed(way)).to.equal(false); - }); - }); + describe('#isOneWay', function() { + it('is not oneway without any tags', function() { + expect(iD.Way.isOneWay(iD.Way())).to.eql(false); + }); + it('is not oneway oneway=no', function() { + expect(iD.Way.isOneWay(iD.Way({ tags: { oneway: 'no' } }))).to.eql(false); + }); + it('is oneway oneway=yes', function() { + expect(iD.Way.isOneWay(iD.Way({ tags: { oneway: 'yes' } }))).to.eql(false); + }); + }); });