diff --git a/data/presets.yaml b/data/presets.yaml index 6674583ae..724357399 100644 --- a/data/presets.yaml +++ b/data/presets.yaml @@ -1640,7 +1640,7 @@ en: label: Type shop: # shop=* - label: Shop Type + label: Type siren/purpose: # 'siren:purpose=*' label: Purpose diff --git a/data/presets/README.md b/data/presets/README.md index b6eda793c..0a07f602f 100644 --- a/data/presets/README.md +++ b/data/presets/README.md @@ -88,6 +88,9 @@ If `fields` or `moreFields` are not defined, the values of the preset's "parent" preset are used. For example, `shop/convenience` automatically uses the same fields as `shop`. +In both explicit and implicit inheritance, fields for keys that define the +preset are not inherited. E.g. the `shop` field is not inherited by `shop/…` presets. + ##### `searchable` Deprecated or generic presets can include the property `"searchable": false`. diff --git a/data/presets/fields.json b/data/presets/fields.json index ea1d4671d..312dcd093 100644 --- a/data/presets/fields.json +++ b/data/presets/fields.json @@ -281,7 +281,7 @@ "service/vehicle": {"key": "service:vehicle:", "type": "multiCombo", "label": "Services"}, "shelter_type": {"key": "shelter_type", "type": "combo", "label": "Type"}, "shelter": {"key": "shelter", "type": "check", "label": "Shelter"}, - "shop": {"key": "shop", "type": "typeCombo", "label": "Shop Type"}, + "shop": {"key": "shop", "type": "typeCombo", "label": "Type"}, "siren/purpose": {"key": "siren:purpose", "type": "combo", "label": "Purpose"}, "siren/type": {"key": "siren:type", "type": "combo", "label": "Type", "strings": {"options": {"pneumatic": "Pneumatic", "electronic": "Electronic", "other": "Other"}}}, "site_type": {"key": "site_type", "type": "combo", "label": "Site Type"}, diff --git a/data/presets/fields/shop.json b/data/presets/fields/shop.json index 82fdd78fb..0579b7bcb 100644 --- a/data/presets/fields/shop.json +++ b/data/presets/fields/shop.json @@ -1,5 +1,5 @@ { "key": "shop", "type": "typeCombo", - "label": "Shop Type" + "label": "Type" } diff --git a/data/taginfo.json b/data/taginfo.json index 406f97e4c..b272099da 100644 --- a/data/taginfo.json +++ b/data/taginfo.json @@ -5403,7 +5403,7 @@ }, { "key": "shop", - "description": "🄿 Shop, 🄵 Shop Type", + "description": "🄿 Shop, 🄵 Type", "object_types": ["node", "area"], "icon_url": "https://raw.githubusercontent.com/mapbox/maki/master/icons/shop-15.svg?sanitize=true" }, diff --git a/dist/locales/en.json b/dist/locales/en.json index a17eb5d1d..00450bb1c 100644 --- a/dist/locales/en.json +++ b/dist/locales/en.json @@ -3194,7 +3194,7 @@ "label": "Shelter" }, "shop": { - "label": "Shop Type" + "label": "Type" }, "siren/purpose": { "label": "Purpose" diff --git a/modules/presets/preset.js b/modules/presets/preset.js index 595b280c3..a81bfb2ee 100644 --- a/modules/presets/preset.js +++ b/modules/presets/preset.js @@ -23,6 +23,18 @@ export function presetPreset(id, preset, fields, visible, rawPresets) { // For a preset without fields, use the fields of the parent preset. // Replace {preset} placeholders with the fields of the specified presets. function resolveFieldInheritance() { + + function filterTargetFields(targetFieldIDs) { + // only inherit `fields` that don't define this preset + return _filter(targetFieldIDs, function(targetFieldID) { + var targetField = fields[targetFieldID]; + if (targetField.key) { + return preset.tags[targetField.key] === undefined; + } + return true; + }); + } + var betweenBracketsRegex = /([^{]*?)(?=\})/; // the keys for properties that contain arrays of field ids var fieldKeys = ['fields', 'moreFields']; @@ -33,10 +45,13 @@ export function presetPreset(id, preset, fields, visible, rawPresets) { }); wrappedTargetPresets.forEach(function(wrappedTargetPresetID) { var targetPresetID = betweenBracketsRegex.exec(wrappedTargetPresetID)[0]; - var targetPreset = rawPresets[targetPresetID]; + var targetFields = rawPresets[targetPresetID][fieldsKey]; + if (fieldsKey === 'fields') { + targetFields = filterTargetFields(targetFields); + } var targetIndex = preset[fieldsKey].indexOf(wrappedTargetPresetID); // replace the {preset} placeholder with the target preset's fields - preset[fieldsKey].splice.apply(preset[fieldsKey], [targetIndex, 1].concat(targetPreset[fieldsKey])); + preset[fieldsKey].splice.apply(preset[fieldsKey], [targetIndex, 1].concat(targetFields)); }); // remove duplicates preset[fieldsKey] = _union(preset[fieldsKey]); @@ -44,7 +59,11 @@ export function presetPreset(id, preset, fields, visible, rawPresets) { // there are no fields defined, so use the parent's if possible var parentPreset = rawPresets[preset.parentPresetID()]; if (parentPreset && parentPreset[fieldsKey]) { - preset[fieldsKey] = parentPreset[fieldsKey]; + var parentFields = parentPreset[fieldsKey]; + if (fieldsKey === 'fields') { + parentFields = filterTargetFields(parentFields); + } + preset[fieldsKey] = parentFields; } } // update the raw object to allow for multiple levels of inheritance