Refine Way#isArea

Closed ways that are multipolygon inners shouldn't be
rendered as areas just because they have a source=* tag,
for example.
This commit is contained in:
John Firebaugh
2013-02-13 16:44:26 -08:00
parent c0b8cd74de
commit e3d9d3a4c4
2 changed files with 19 additions and 13 deletions
+12 -6
View File
@@ -47,12 +47,14 @@ _.extend(iD.Way.prototype, {
// - doesn't have area=no
// - doesn't have highway tag
isArea: function() {
return this.tags.area === 'yes' ||
(this.isClosed() &&
!_.isEmpty(this.tags) &&
this.tags.area !== 'no' &&
!this.tags.highway &&
!this.tags.barrier);
if (this.tags.area === 'yes')
return true;
if (!this.isClosed() || this.tags.area === 'no')
return false;
for (var key in this.tags)
if (key in iD.Way.areaKeys)
return true;
return false;
},
isDegenerate: function() {
@@ -138,3 +140,7 @@ _.extend(iD.Way.prototype, {
}
}
});
iD.Way.areaKeys = iD.util.trueObj(['area', 'building', 'leisure', 'tourism', 'ruins',
'historic', 'landuse', 'military', 'natural', 'amenity', 'shop', 'man_made',
'public_transport']);
+7 -7
View File
@@ -99,16 +99,16 @@ describe('iD.Way', function() {
expect(iD.Way({nodes: ['n1', 'n1']}).isArea()).to.equal(false);
});
it('returns true if the way is closed and has tags', function() {
expect(iD.Way({nodes: ['n1', 'n1'], tags: {a: 'b'}}).isArea()).to.equal(true);
it('returns true if the way is closed and has a key in iD.Way.areaKeys', function() {
expect(iD.Way({nodes: ['n1', 'n1'], tags: {building: 'yes'}}).isArea()).to.equal(true);
});
it('returns false if the way is closed and has no keys in iD.Way.areaKeys', function() {
expect(iD.Way({nodes: ['n1', 'n1'], tags: {a: 'b'}}).isArea()).to.equal(false);
});
it('returns false if the way is closed and has tag area=no', function() {
expect(iD.Way({tags: { area: 'no' }, nodes: ['n1', 'n1']}).isArea()).to.equal(false);
});
it('returns false if the way is closed and has highway tag', function() {
expect(iD.Way({tags: { highway: 'residential' }, nodes: ['n1', 'n1']}).isArea()).to.equal(false);
expect(iD.Way({nodes: ['n1', 'n1'], tags: {area: 'no', building: 'yes'}}).isArea()).to.equal(false);
});
});