diff --git a/data/presets/README.md b/data/presets/README.md index cecdbfa5d7..7bb11ee191 100644 --- a/data/presets/README.md +++ b/data/presets/README.md @@ -233,6 +233,26 @@ For number fields, the lowest valid value. There is no default. For number fields, the greatest valid value. There is no default. +##### `prerequisiteTag` + +An object defining the tags the feature needs before this field will be displayed. It must have this property: + +- `key`: The key for the required tag. + +And may optionally have one of these properties: + +- `value`: The value that the key must have. +- `valueNot`: The value that the key must not have. + +For example, this is how we show the Internet Access Fee field only if the feature has an `internet_access` tag not equal to `no`. + +```js +"prerequisiteTag": { + "key": "internet_access", + "valueNot": "no" +} +``` + ## Icons You can use any of the following open source map icon sets as preset icons. diff --git a/data/presets/fields.json b/data/presets/fields.json index 2a857aa1b9..ef9748a485 100644 --- a/data/presets/fields.json +++ b/data/presets/fields.json @@ -77,7 +77,7 @@ "dance/style": {"key": "dance:style", "type": "semiCombo", "label": "Dance Styles"}, "date": {"key": "date", "type": "check", "label": "Date"}, "delivery": {"key": "delivery", "type": "check", "label": "Delivery"}, - "denomination": {"key": "denomination", "type": "combo", "label": "Denomination"}, + "denomination": {"key": "denomination", "type": "combo", "label": "Denomination", "prerequisiteTag": {"key": "religion"}}, "denotation": {"key": "denotation", "type": "combo", "label": "Denotation"}, "description": {"key": "description", "type": "textarea", "label": "Description", "universal": true}, "design": {"key": "design", "type": "combo", "label": "Design"}, @@ -154,8 +154,8 @@ "intermittent_yes": {"key": "intermittent", "type": "check", "label": "Intermittent", "default": "yes"}, "intermittent": {"key": "intermittent", "type": "check", "label": "Intermittent"}, "internet_access": {"key": "internet_access", "type": "combo", "label": "Internet Access", "strings": {"options": {"yes": "Yes", "no": "No", "wlan": "Wifi", "wired": "Wired", "terminal": "Terminal"}}}, - "internet_access/fee": {"key": "internet_access:fee", "type": "check", "label": "Internet Access Fee"}, - "internet_access/ssid": {"key": "internet_access:ssid", "type": "text", "label": "SSID (Network Name)"}, + "internet_access/fee": {"key": "internet_access:fee", "type": "check", "label": "Internet Access Fee", "prerequisiteTag": {"key": "internet_access", "valueNot": "no"}}, + "internet_access/ssid": {"key": "internet_access:ssid", "type": "text", "label": "SSID (Network Name)", "prerequisiteTag": {"key": "internet_access", "valueNot": "no"}}, "kerb": {"key": "kerb", "type": "combo", "label": "Curb"}, "label": {"key": "label", "type": "textarea", "label": "Label"}, "lamp_type": {"key": "lamp_type", "type": "combo", "label": "Type"}, diff --git a/data/presets/fields/denomination.json b/data/presets/fields/denomination.json index a4a24ca9d3..71d664d98f 100644 --- a/data/presets/fields/denomination.json +++ b/data/presets/fields/denomination.json @@ -1,5 +1,8 @@ { "key": "denomination", "type": "combo", - "label": "Denomination" -} \ No newline at end of file + "label": "Denomination", + "prerequisiteTag": { + "key": "religion" + } +} diff --git a/data/presets/fields/internet_access/fee.json b/data/presets/fields/internet_access/fee.json index 9b2e407d4b..2ca48b4ba7 100644 --- a/data/presets/fields/internet_access/fee.json +++ b/data/presets/fields/internet_access/fee.json @@ -1,5 +1,9 @@ { "key": "internet_access:fee", "type": "check", - "label": "Internet Access Fee" + "label": "Internet Access Fee", + "prerequisiteTag": { + "key": "internet_access", + "valueNot": "no" + } } diff --git a/data/presets/fields/internet_access/ssid.json b/data/presets/fields/internet_access/ssid.json index 5f6b4b56f6..2309c2b380 100644 --- a/data/presets/fields/internet_access/ssid.json +++ b/data/presets/fields/internet_access/ssid.json @@ -1,5 +1,9 @@ { "key": "internet_access:ssid", "type": "text", - "label": "SSID (Network Name)" + "label": "SSID (Network Name)", + "prerequisiteTag": { + "key": "internet_access", + "valueNot": "no" + } } diff --git a/data/presets/schema/field.json b/data/presets/schema/field.json index b77a28413b..41f8f7de17 100644 --- a/data/presets/schema/field.json +++ b/data/presets/schema/field.json @@ -129,6 +129,28 @@ "maxValue": { "description": "Maximum field value (number fields only)", "type": "integer" + }, + "prerequisiteTag": { + "description": "Tagging constraint for showing this field in the editor", + "type": { + "type": "object", + "properties": { + "key": { + "description": "The key of the required tag", + "type": "string", + "required": true + }, + "value": { + "description": "The value that the tag must have. (alternative to 'valueNot')", + "type": "string" + }, + "valueNot": { + "description": "The value that the tag cannot have. (alternative to 'value')", + "type": "string" + } + }, + "additionalProperties": false + } } }, "additionalProperties": false diff --git a/dist/locales/en.json b/dist/locales/en.json index fd7663ea9c..da3671d750 100644 --- a/dist/locales/en.json +++ b/dist/locales/en.json @@ -7568,6 +7568,9 @@ "SPW_PICC": { "name": "SPW(allonie) PICC numerical imagery" }, + "US-TIGER-Roads-2012": { + "name": "TIGER Roads 2012" + }, "US-TIGER-Roads-2014": { "description": "At zoom level 16+, public domain map data from the US Census. At lower zooms, only changes since 2006 minus changes already incorporated into OpenStreetMap", "name": "TIGER Roads 2014" @@ -7576,10 +7579,6 @@ "description": "Yellow = Public domain map data from the US Census. Red = Data not found in OpenStreetMap", "name": "TIGER Roads 2017" }, - "US-TIGER-Roads-2018": { - "description": "Yellow = Public domain map data from the US Census. Red = Data not found in OpenStreetMap", - "name": "TIGER Roads 2018" - }, "US_Forest_Service_roads_overlay": { "description": "Highway: Green casing = unclassified. Brown casing = track. Surface: gravel = light brown fill, Asphalt = black, paved = gray, ground =white, concrete = blue, grass = green. Seasonal = white bars", "name": "U.S. Forest Roads Overlay" @@ -7596,12 +7595,6 @@ }, "name": "UrbIS-Ortho 2017" }, - "UrbISOrtho2018": { - "attribution": { - "text": "Realized by means of Brussels UrbIS®© - Distribution & Copyright CIRB" - }, - "name": "UrbIS-Ortho 2018" - }, "UrbisAdmFR": { "attribution": { "text": "Realized by means of Brussels UrbIS®© - Distribution & Copyright CIRB" @@ -7686,33 +7679,11 @@ "description": "Japan GSI Standard Map. Widely covered.", "name": "Japan GSI Standard Map" }, - "helsingborg-orto": { + "hike_n_bike": { "attribution": { - "text": "© Helsingborg municipality" - }, - "description": "Orthophotos from the municipality of Helsingborg 2016, public domain", - "name": "Helsingborg Orthophoto" - }, - "kalmar-orto-2014": { - "attribution": { - "text": "© Kalmar municipality" - }, - "description": "Orthophotos for the north coast of the municipality of Kalmar 2014", - "name": "Kalmar North Orthophoto 2014" - }, - "kalmar-orto-2016": { - "attribution": { - "text": "© Kalmar municipality" - }, - "description": "Orthophotos for the south coast of the municipality of Kalmar 2016", - "name": "Kalmar South Orthophoto 2016" - }, - "kalmar-orto-2018": { - "attribution": { - "text": "© Kalmar municipality" + "text": "© OpenStreetMap contributors" }, - "description": "Orthophotos for urban areas of the municipality of Kalmar 2018", - "name": "Kalmar Urban Orthophoto 2018" + "name": "Hike & Bike" }, "kelkkareitit": { "attribution": { @@ -7735,20 +7706,6 @@ "description": "Mosaic of Swedish orthophotos from the period 1970–1980. Is under construction.", "name": "Lantmäteriet Historic Orthophoto 1975" }, - "lantmateriet-topowebb": { - "attribution": { - "text": "© Lantmäteriet, CC0" - }, - "description": "Topographic map of Sweden 1:50 000", - "name": "Lantmäteriet Topographic Map" - }, - "linkoping-orto": { - "attribution": { - "text": "© Linköping municipality" - }, - "description": "Orthophotos from the municipality of Linköping 2010, open data", - "name": "Linköping Orthophoto" - }, "mapbox_locator_overlay": { "attribution": { "text": "Terms & Feedback" @@ -7813,13 +7770,6 @@ }, "name": "Stamen Terrain" }, - "stockholm-orto": { - "attribution": { - "text": "© Stockholm municipality, CC0" - }, - "description": "Orthophotos from the municipality of Stockholm 2015, CC0 license", - "name": "Stockholm Orthophoto" - }, "tf-cycle": { "attribution": { "text": "Maps © Thunderforest, Data © OpenStreetMap contributors" diff --git a/modules/ui/field.js b/modules/ui/field.js index 27649d1053..0d48513aed 100644 --- a/modules/ui/field.js +++ b/modules/ui/field.js @@ -48,10 +48,12 @@ export function uiField(context, presetField, entity, options) { dispatch.call('change', field, t, onInput); }); - // if this field cares about the entity, pass it along - if (entity && field.impl.entity) { + if (entity) { field.entityID = entity.id; - field.impl.entity(entity); + // if this field cares about the entity, pass it along + if (field.impl.entity) { + field.impl.entity(entity); + } } } @@ -229,11 +231,39 @@ export function uiField(context, presetField, entity, options) { } }; - + // A shown field has a visible UI, a non-shown field is in the 'Add field' dropdown field.isShown = function() { return _show || isPresent(); }; + // An allowed field can appear in the UI or in the 'Add field' dropdown. + // A non-allowed field is hidden from the user altogether + field.isAllowed = function() { + + if (isPresent()) { + // always allow a field with a value to display + return true; + } + + var prerequisiteTag = field.prerequisiteTag; + if (prerequisiteTag && field.entityID) { + if (prerequisiteTag.key) { + var value = context.graph().entity(field.entityID).tags[prerequisiteTag.key]; + if (value) { + if (prerequisiteTag.valueNot) { + return prerequisiteTag.valueNot !== value; + } + if (prerequisiteTag.value) { + return prerequisiteTag.value === value; + } + return true; + } else { + return false; + } + } + } + return true; + }; field.focus = function() { if (field.impl) { diff --git a/modules/ui/form_fields.js b/modules/ui/form_fields.js index 51984aac83..08a7e2afbe 100644 --- a/modules/ui/form_fields.js +++ b/modules/ui/form_fields.js @@ -16,9 +16,18 @@ export function uiFormFields(context) { } + formFields.tagsChanged = function() {}; + function render(selection, klass) { - var shown = _fieldsArr.filter(function(field) { return field.isShown(); }); - var notShown = _fieldsArr.filter(function(field) { return !field.isShown(); }); + + formFields.tagsChanged = function() { + render(selection, klass); + }; + + var allowedFields = _fieldsArr.filter(function(field) { return field.isAllowed(); }); + + var shown = allowedFields.filter(function(field) { return field.isShown(); }); + var notShown = allowedFields.filter(function(field) { return !field.isShown(); }); var container = selection.selectAll('.form-fields-container') .data([0]); diff --git a/modules/ui/preset_editor.js b/modules/ui/preset_editor.js index e688962db3..0c3d46ce62 100644 --- a/modules/ui/preset_editor.js +++ b/modules/ui/preset_editor.js @@ -120,6 +120,7 @@ export function uiPresetEditor(context) { presetEditor.tags = function(val) { if (!arguments.length) return _tags; _tags = val; + formFields.tagsChanged(); // Don't reset _fieldsArr here. return presetEditor; };