diff --git a/js/id/ui/preset.js b/js/id/ui/preset.js index 7120a390a..ebb2505c6 100644 --- a/js/id/ui/preset.js +++ b/js/id/ui/preset.js @@ -3,6 +3,7 @@ iD.ui.preset = function() { taginfo = iD.taginfo(), context, entity, + type, hidden, sections, exttags, @@ -42,13 +43,14 @@ iD.ui.preset = function() { // generate form fields for a given field. function input(d) { - var i, wrap; + var i, wrap, + default_ = d['default'] && d['default'][type]; switch (d.type) { case 'text': i = this.append('input') .attr('type', 'text') .attr('id', 'input-' + d.key) - .attr('placeholder', d['default'] || ''); + .attr('placeholder', default_ || ''); break; case 'tel': i = this.append('input') @@ -73,7 +75,7 @@ iD.ui.preset = function() { .attr('type', 'checkbox') .attr('id', 'input-' + d.key) .each(function() { - if (d['default']) { + if (default_) { this.attr('checked', 'checked'); } }); @@ -87,6 +89,7 @@ iD.ui.preset = function() { value: d }; }))); + if (default_) i.property('value', default_); break; case 'combo': var combobox = d3.combobox(); @@ -173,6 +176,7 @@ iD.ui.preset = function() { presets.entity = function(_) { if (!arguments.length) return entity; entity = _; + type = entity.type === 'node' ? entity.type : entity.geometry(); return presets; }; diff --git a/js/id/ui/tageditor.js b/js/id/ui/tageditor.js index b520855ae..4613d83a1 100644 --- a/js/id/ui/tageditor.js +++ b/js/id/ui/tageditor.js @@ -15,10 +15,24 @@ iD.ui.TagEditor = function() { function tageditor(selection, preset) { entity = selection.datum(); + var type = entity.type === 'node' ? entity.type : entity.geometry(); if (preset) { - if (presetMatch) tags = _.omit(tags, _.keys(presetMatch.match.tags)); - tags = _.extend(_.omit(tags), preset.match.tags); + if (presetMatch) { + // Strip preset's match tags + tags = _.omit(tags, _.keys(presetMatch.match.tags)); + + // Strip preset's default tags + for (var i in presetMatch.form) { + var field = presetMatch.form[i]; + if (field['default'] && field['default'][type] == tags[field.key]) { + delete tags[field.key]; + } + } + } + + // Add new preset's match tags + tags = _.extend(tags, preset.match.tags); } presetMatch = preset || presetMatch || presetData.matchTags(entity); @@ -115,8 +129,6 @@ iD.ui.TagEditor = function() { } function drawHead(selection) { - var entity = selection.datum(); - var h2 = selection.append('h2'); h2.append('span') diff --git a/presets/presets.json b/presets/presets.json index 28bdada10..2fffd021c 100644 --- a/presets/presets.json +++ b/presets/presets.json @@ -10,6 +10,15 @@ }, "icon": "cafe", "form": [ + { + "key": "building", + "type": "select", + "options": ["yes", "no"], + "default": { + "area": "yes", + "node": "no" + } + }, { "key": "internet_access", "title": "Internet Access",