mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-24 00:54:03 +02:00
Merge pull request #5583 from quincylvania/field-prerequisite-tags
Mechanism for displaying fields conditionally based on tags
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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"},
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
{
|
||||
"key": "denomination",
|
||||
"type": "combo",
|
||||
"label": "Denomination"
|
||||
}
|
||||
"label": "Denomination",
|
||||
"prerequisiteTag": {
|
||||
"key": "religion"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
{
|
||||
"key": "internet_access:fee",
|
||||
"type": "check",
|
||||
"label": "Internet Access Fee"
|
||||
"label": "Internet Access Fee",
|
||||
"prerequisiteTag": {
|
||||
"key": "internet_access",
|
||||
"valueNot": "no"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
{
|
||||
"key": "internet_access:ssid",
|
||||
"type": "text",
|
||||
"label": "SSID (Network Name)"
|
||||
"label": "SSID (Network Name)",
|
||||
"prerequisiteTag": {
|
||||
"key": "internet_access",
|
||||
"valueNot": "no"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Vendored
+6
-56
@@ -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"
|
||||
"text": "© OpenStreetMap contributors"
|
||||
},
|
||||
"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"
|
||||
},
|
||||
"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"
|
||||
|
||||
+34
-4
@@ -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) {
|
||||
|
||||
@@ -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]);
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user