From e3d9d3a4c439572008c6976e23338ecac90cee93 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Wed, 13 Feb 2013 16:44:26 -0800 Subject: [PATCH] Refine Way#isArea Closed ways that are multipolygon inners shouldn't be rendered as areas just because they have a source=* tag, for example. --- js/id/core/way.js | 18 ++++++++++++------ test/spec/core/way.js | 14 +++++++------- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/js/id/core/way.js b/js/id/core/way.js index e9fb7b71d..51590350b 100644 --- a/js/id/core/way.js +++ b/js/id/core/way.js @@ -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']); diff --git a/test/spec/core/way.js b/test/spec/core/way.js index 05864d5c3..2201b7fc4 100644 --- a/test/spec/core/way.js +++ b/test/spec/core/way.js @@ -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); }); });