mirror of
https://github.com/FoggedLens/iD.git
synced 2026-02-12 16:52:50 +00:00
handle cycleway:both=* (#9587)
this works for any `directionalCombo` field, including `sidewalk:both`
This commit is contained in:
@@ -70,7 +70,9 @@ export function uiField(context, presetField, entityIDs, options) {
|
||||
if (field.type === 'directionalCombo' && field.key) {
|
||||
// directionalCombo fields can have an additional key describing the for
|
||||
// cases where both directions share a "common" value.
|
||||
keys = keys.concat(field.key);
|
||||
// The field also support *:both. The preset decides which field to write to.
|
||||
const baseKey = field.key.replace(/:both$/, '');
|
||||
keys = keys.concat(baseKey, `${baseKey}:both`);
|
||||
}
|
||||
return keys;
|
||||
}
|
||||
|
||||
@@ -85,19 +85,26 @@ export function uiFieldDirectionalCombo(field, context) {
|
||||
|
||||
function change(key, newValue) {
|
||||
const commonKey = field.key;
|
||||
/** if commonKey ends with :both, this is the key without :both. and vice-verca */
|
||||
const otherCommonKey = field.key.endsWith(':both')
|
||||
? field.key.replace(/:both$/, '')
|
||||
: `${field.key}:both`;
|
||||
|
||||
const otherKey = key === field.keys[0] ? field.keys[1] : field.keys[0];
|
||||
|
||||
dispatch.call('change', this, tags => {
|
||||
const otherValue = tags[otherKey] || tags[commonKey];
|
||||
const otherValue = tags[otherKey] || tags[commonKey] || tags[otherCommonKey];
|
||||
if (newValue === otherValue) {
|
||||
// both tags match, use the common tag to tag both sides the same way
|
||||
tags[commonKey] = newValue;
|
||||
delete tags[key];
|
||||
delete tags[otherKey];
|
||||
delete tags[otherCommonKey];
|
||||
} else {
|
||||
// Always set both left and right as changing one can affect the other
|
||||
tags[key] = newValue;
|
||||
delete tags[commonKey];
|
||||
delete tags[otherCommonKey];
|
||||
tags[otherKey] = otherValue;
|
||||
}
|
||||
return tags;
|
||||
@@ -108,10 +115,11 @@ export function uiFieldDirectionalCombo(field, context) {
|
||||
directionalCombo.tags = function(tags) {
|
||||
_tags = tags;
|
||||
|
||||
const commonKey = field.key;
|
||||
const commonKey = field.key.replace(/:both$/, '');
|
||||
for (let key in _combos) {
|
||||
const uniqueValues = [... new Set([]
|
||||
.concat(_tags[commonKey])
|
||||
.concat(_tags[`${commonKey}:both`])
|
||||
.concat(_tags[key])
|
||||
.filter(Boolean))];
|
||||
_combos[key].tags({ [key]: uniqueValues.length > 1 ? uniqueValues : uniqueValues[0] });
|
||||
|
||||
Reference in New Issue
Block a user