Add Entity#geometry, use in inspector

Fixes the icon for areas, but breaks it for vertices.
Needs a big-vertex sprite.
This commit is contained in:
John Firebaugh
2013-01-02 21:53:51 -08:00
parent 2a6145ef10
commit 62efa1948e
5 changed files with 31 additions and 8 deletions

View File

@@ -3,5 +3,9 @@ iD.Node = iD.Entity.extend({
extent: function() {
return [this.loc, this.loc];
},
geometry: function() {
return this._poi ? 'point' : 'vertex';
}
});

View File

@@ -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';
}
});

View File

@@ -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')

View File

@@ -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');
});
});
});

View File

@@ -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');
});
});
});