From 62efa1948e17e8ec66da6763ad9cf57a7466add7 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Wed, 2 Jan 2013 21:53:51 -0800 Subject: [PATCH] Add Entity#geometry, use in inspector Fixes the icon for areas, but breaks it for vertices. Needs a big-vertex sprite. --- js/id/graph/node.js | 4 ++++ js/id/graph/way.js | 4 ++++ js/id/ui/inspector.js | 11 +++-------- test/spec/graph/node.js | 10 ++++++++++ test/spec/graph/way.js | 10 ++++++++++ 5 files changed, 31 insertions(+), 8 deletions(-) diff --git a/js/id/graph/node.js b/js/id/graph/node.js index 3a29cd8e6..9500991fa 100644 --- a/js/id/graph/node.js +++ b/js/id/graph/node.js @@ -3,5 +3,9 @@ iD.Node = iD.Entity.extend({ extent: function() { return [this.loc, this.loc]; + }, + + geometry: function() { + return this._poi ? 'point' : 'vertex'; } }); diff --git a/js/id/graph/way.js b/js/id/graph/way.js index a62afb8e1..77858d29a 100644 --- a/js/id/graph/way.js +++ b/js/id/graph/way.js @@ -36,5 +36,9 @@ iD.Way = iD.Entity.extend({ this.tags.area !== 'no' && !this.tags.highway && !this.tags.barrier); + }, + + geometry: function() { + return this.isArea() ? 'area' : 'line'; } }); diff --git a/js/id/ui/inspector.js b/js/id/ui/inspector.js index a4124d089..10ce265d0 100644 --- a/js/id/ui/inspector.js +++ b/js/id/ui/inspector.js @@ -61,18 +61,13 @@ iD.Inspector = function() { var h2 = selection.append('h2'); h2.append('span') - .attr('class', function(d) { - var icons = { way: 'line', node: 'point' }; - return 'icon big icon-pre-text big-' + icons[d.type]; - }); + .attr('class', 'icon big icon-pre-text big-' + entity.geometry()); h2.append('span') .text(entity.friendlyName()); selection.append('a') - .attr('href', function() { - return 'http://www.openstreetmap.org/browse/' + entity.type + '/' + entity.osmId(); - }) + .attr('href', 'http://www.openstreetmap.org/browse/' + entity.type + '/' + entity.osmId()) .text('View on OSM'); if (entity.type === 'way') { @@ -82,7 +77,7 @@ iD.Inspector = function() { .on('click', function() { event.changeWayDirection(entity); }); } - if (entity.type === 'node' && !entity._poi) { + if (entity.geometry() === 'vertex') { selection.append('a') .attr('href', '#') .text('Split Way') diff --git a/test/spec/graph/node.js b/test/spec/graph/node.js index c7ce0c406..929946b04 100644 --- a/test/spec/graph/node.js +++ b/test/spec/graph/node.js @@ -36,4 +36,14 @@ describe('iD.Node', function () { expect(iD.Node({loc: [0, 0]}).intersects([[100, 90], [180, -90]])).to.equal(false); }); }); + + describe("#geometry", function () { + it("returns 'vertex' if the node is not a point", function () { + expect(iD.Node().geometry()).to.equal('vertex'); + }); + + it("returns 'point' if the node is a point", function () { + expect(iD.Node({_poi: true}).geometry()).to.equal('point'); + }); + }); }); diff --git a/test/spec/graph/way.js b/test/spec/graph/way.js index 4f64fac67..3aa8045fb 100644 --- a/test/spec/graph/way.js +++ b/test/spec/graph/way.js @@ -110,4 +110,14 @@ describe('iD.Way', function() { expect(iD.Way({tags: { highway: 'residential' }, nodes: ['n1', 'n1']}).isArea()).to.equal(false); }); }); + + describe("#geometry", function() { + it("returns 'line' when the way is not an area", function () { + expect(iD.Way().geometry()).to.equal('line'); + }); + + it("returns 'area' when the way is an area", function () { + expect(iD.Way({tags: { area: 'yes' }}).geometry()).to.equal('area'); + }); + }); });