Add area=yes when necessary

Example: highway=pedestrian areas.

Fixes #2069
This commit is contained in:
John Firebaugh
2014-01-03 12:46:50 -08:00
parent 5f8c02fddc
commit d381812f96
2 changed files with 23 additions and 2 deletions

View File

@@ -81,9 +81,11 @@ iD.presets.Preset = function(id, preset, fields) {
var applyTags = preset.addTags || preset.tags;
preset.applyTags = function(tags, geometry) {
var k;
tags = _.clone(tags);
for (var k in applyTags) {
for (k in applyTags) {
if (applyTags[k] === '*') {
tags[k] = 'yes';
} else {
@@ -91,6 +93,13 @@ iD.presets.Preset = function(id, preset, fields) {
}
}
// Add area=yes if necessary
for (k in applyTags) {
if (geometry === 'area' && !(k in iD.areaKeys))
tags['area'] = 'yes';
break;
}
for (var f in preset.fields) {
var field = preset.fields[f];
if (field.matchGeometry(geometry) && field.key && !tags[field.key] && field['default']) {

View File

@@ -61,7 +61,7 @@ describe('iD.presets.Preset', function() {
describe('#applyTags', function() {
it("adds match tags", function() {
var preset = iD.presets.Preset('test', {tags: {highway: 'residential'}});
expect(preset.applyTags({}, 'area')).to.eql({highway: 'residential'});
expect(preset.applyTags({}, 'line')).to.eql({highway: 'residential'});
});
it("adds wildcard tags with value 'yes'", function() {
@@ -85,6 +85,18 @@ describe('iD.presets.Preset', function() {
preset = iD.presets.Preset('test', {fields: ['field']}, {field: field});
expect(preset.applyTags({}, 'point')).to.eql({});
});
context("with an area preset whose primary tag is not in areaKeys", function() {
var preset = iD.presets.Preset('test', {geometry: ['line', 'area'], tags: {highway: 'pedestrian'}});
it("adds no area=yes to non-areas", function() {
expect(preset.applyTags({}, 'line')).to.eql({highway: 'pedestrian'});
});
it("adds area=yes to areas", function() {
expect(preset.applyTags({}, 'area')).to.eql({highway: 'pedestrian', area: 'yes'});
});
});
});
describe('#removeTags', function() {