Fallback Area preset should preserve the area=yes tag

(closes #4424)
This commit is contained in:
Bryan Housel
2017-10-10 20:54:41 -04:00
parent d82a34ed83
commit 8abc39461b
2 changed files with 23 additions and 17 deletions

View File

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

View File

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