Skip to content

Commit

Permalink
Fallback Area preset should preserve the area=yes tag
Browse files Browse the repository at this point in the history
(closes #4424)
  • Loading branch information
bhousel committed Oct 11, 2017
1 parent d82a34e commit 8abc394
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 17 deletions.
28 changes: 15 additions & 13 deletions modules/presets/preset.js
Expand Up @@ -94,7 +94,7 @@ export function presetPreset(id, preset, fields) {
};


var removeTags = preset.removeTags || preset.tags;
var removeTags = preset.removeTags || preset.tags || {};
preset.removeTags = function(tags, geometry) {
tags = _omit(tags, _keys(removeTags));

Expand All @@ -110,7 +110,7 @@ export function presetPreset(id, preset, fields) {
};


var applyTags = preset.addTags || preset.tags;
var applyTags = preset.addTags || preset.tags || {};
preset.applyTags = function(tags, geometry) {
var k;

Expand All @@ -128,19 +128,21 @@ export function presetPreset(id, preset, fields) {
// This is necessary if the geometry is already an area (e.g. user drew an area) AND any of:
// 1. chosen preset could be either an area or a line (`barrier=city_wall`)
// 2. chosen preset doesn't have a key in areaKeys (`railway=station`)
delete tags.area;
if (geometry === 'area') {
var needsAreaTag = true;
if (preset.geometry.indexOf('line') === -1) {
for (k in applyTags) {
if (k in areaKeys) {
needsAreaTag = false;
break;
if (!applyTags.hasOwnProperty('area')) {
delete tags.area;
if (geometry === 'area') {
var needsAreaTag = true;
if (preset.geometry.indexOf('line') === -1) {
for (k in applyTags) {
if (k in areaKeys) {
needsAreaTag = false;
break;
}
}
}
}
if (needsAreaTag) {
tags.area = 'yes';
if (needsAreaTag) {
tags.area = 'yes';
}
}
}

Expand Down
12 changes: 8 additions & 4 deletions test/spec/presets/preset.js
Expand Up @@ -97,7 +97,7 @@ describe('iD.presetPreset', function() {
expect(preset.applyTags({}, 'point')).to.eql({});
});

context('for a preset with no tag in areaKeys', function() {
describe('for a preset with no tag in areaKeys', function() {
var preset = iD.presetPreset('test', {geometry: ['line', 'area'], tags: {name: 'testname', highway: 'pedestrian'}});

it('doesn\'t add area=yes to non-areas', function() {
Expand All @@ -109,11 +109,15 @@ describe('iD.presetPreset', function() {
});
});

context('for a preset with a tag in areaKeys', function() {
var preset = iD.presetPreset('test', {geometry: ['area'], tags: {name: 'testname', natural: 'water'}});
it('doesn\'t add area=yes', function() {
describe('for a preset with a tag in areaKeys', function() {
it('doesn\'t add area=yes automatically', function() {
var preset = iD.presetPreset('test', {geometry: ['area'], tags: {name: 'testname', natural: 'water'}});
expect(preset.applyTags({}, 'area')).to.eql({name: 'testname', natural: 'water'});
});
it('does add area=yes if asked to', function() {
var preset = iD.presetPreset('test', {geometry: ['area'], tags: {name: 'testname', area: 'yes'}});
expect(preset.applyTags({}, 'area')).to.eql({name: 'testname', area: 'yes'});
});
});
});

Expand Down

0 comments on commit 8abc394

Please sign in to comment.