Skip to content

Commit dba6794

Browse files
committed
Show (route) relation colours in lists and comboboxes
re: #1219 re: openstreetmap/iD#9424
1 parent 975bea9 commit dba6794

File tree

5 files changed

+74
-12
lines changed

5 files changed

+74
-12
lines changed

css/80_app.css

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1385,13 +1385,11 @@ a.hide-toggle {
13851385
text-overflow: ellipsis;
13861386
flex: 1 1 auto;
13871387
padding: 5px 0 4px 10px;
1388+
white-space: nowrap;
13881389
}
13891390
.ideditor[dir='rtl'] .field-label .label-text {
13901391
padding: 5px 10px 4px 0;
13911392
}
1392-
.field-label .label-text span {
1393-
white-space: nowrap;
1394-
}
13951393

13961394
.label-text .label-textannotation svg.icon {
13971395
margin: 0 8px;
@@ -2619,12 +2617,40 @@ img.tag-reference-wiki-image {
26192617
padding-left: 10px;
26202618
}
26212619

2620+
.section-raw-member-editor .member-row .member-entity-name.has-color::before,
2621+
.section-raw-membership-editor .member-row .member-entity-name.has-color::before,
2622+
.feature-list .entity-name.has-color::before,
2623+
.combobox-parent-relation .has-color::before {
2624+
display: inline-block;
2625+
content: '';
2626+
margin-left: -5px;
2627+
margin-right: 5px;
2628+
border-style: solid;
2629+
border-width: 4px;
2630+
border-radius: 4px;
2631+
border-color: inherit;
2632+
}
2633+
.combobox-parent-relation .has-color::before {
2634+
margin-left: 2px;
2635+
}
2636+
26222637
.ideditor[dir='rtl'] .section-raw-member-editor .member-row .member-entity-name,
26232638
.ideditor[dir='rtl'] .section-raw-membership-editor .member-row .member-entity-name {
26242639
padding-left:0;
26252640
padding-right: 10px;
26262641
}
26272642

2643+
.ideditor[dir='rtl'] .section-raw-member-editor .member-row .member-entity-name.has-color::before,
2644+
.ideditor[dir='rtl'] .section-raw-membership-editor .member-row .member-entity-name.has-color::before,
2645+
.ideditor[dir='rtl'] .feature-list .entity-name.has-color::before {
2646+
margin-left: 5px;
2647+
margin-right: -5px;
2648+
}
2649+
.ideditor[dir='rtl'] .combobox-parent-relation .has-color::before {
2650+
margin-left: 5px;
2651+
margin-right: 2px;
2652+
}
2653+
26282654
.form-field-input-member > input.member-role {
26292655
border-radius: 0 0 4px 4px;
26302656
}

modules/ui/combobox.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { utilGetSetValue, utilRebind, utilTriggerEvent } from '../util';
77
// It is keyed on the `value` of the entry. Data should be an array of objects like:
88
// [{
99
// value: 'string value', // required
10-
// display: 'label html' // optional
10+
// display: 'label html' // optional html value or function
1111
// title: 'hover text' // optional
1212
// terms: ['search terms'] // optional
1313
// }, ...]
@@ -384,7 +384,16 @@ export function uiCombobox(context, klass) {
384384
return 'combobox-option ' + (d.klass || '');
385385
})
386386
.attr('title', function(d) { return d.title; })
387-
.html(function(d) { return d.display || d.value; })
387+
.each(function(d, i, nodes) {
388+
const selection = d3_select(nodes[i]);
389+
if (typeof d.display === 'function') { // display function
390+
selection.call(d.display);
391+
} else if (d.display) { // display html value
392+
selection.html(d.display);
393+
} else { // text value
394+
selection.text(d.value);
395+
}
396+
})
388397
.on('mouseenter', _mouseEnterHandler)
389398
.on('mouseleave', _mouseLeaveHandler)
390399
.merge(options)

modules/ui/feature_list.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,8 @@ export function uiFeatureList(context) {
303303
label
304304
.append('span')
305305
.attr('class', 'entity-name')
306+
.classed('has-color', d => d.entity && d.entity.type === 'relation' && d.entity.tags.colour)
307+
.style('border-color', d => d.entity && d.entity.type === 'relation' && d.entity.tags.colour)
306308
.text(d => d.name);
307309

308310
enter

modules/ui/sections/raw_member_editor.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,9 @@ export function uiSectionRawMemberEditor(context) {
194194
labelLink
195195
.append('span')
196196
.attr('class', 'member-entity-name')
197-
.html(d => (d.member ? l10n.displayName(d.member.tags) : ''));
197+
.classed('has-color', d => d.member.type === 'relation' && d.member.tags.colour)
198+
.style('border-color', d => d.member.type === 'relation' && d.member.tags.colour)
199+
.text(d => (d.member ? l10n.displayName(d.member.tags) : ''));
198200

199201
label
200202
.append('button')

modules/ui/sections/raw_membership_editor.js

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -234,30 +234,51 @@ export function uiSectionRawMembershipEditor(context) {
234234
var result = [];
235235
var graph = editor.staging.graph;
236236

237+
function baseDisplayValue(entity) {
238+
var matched = presets.match(entity, graph);
239+
var presetName = (matched && matched.name()) || l10n.t('inspector.relation');
240+
var entityName = l10n.displayName(entity.tags) || '';
241+
return presetName + ' ' + entityName;
242+
}
243+
237244
function baseDisplayLabel(entity) {
238245
var matched = presets.match(entity, graph);
239246
var presetName = (matched && matched.name()) || l10n.t('inspector.relation');
240247
var entityName = l10n.displayName(entity.tags) || '';
241248

242-
return presetName + ' ' + entityName;
249+
return selection => {
250+
selection
251+
.append('b')
252+
.text(presetName + ' ');
253+
selection
254+
.append('span')
255+
.classed('has-color', entity.tags.colour)
256+
.style('border-color', entity.tags.colour)
257+
.text(entityName);
258+
};
243259
}
244260

245261
var explicitRelation = q && graph.hasEntity(q.toLowerCase());
246262
if (explicitRelation && explicitRelation.type === 'relation' && explicitRelation.id !== entityID) {
247263
// loaded relation is specified explicitly, only show that
248264
result.push({
249265
relation: explicitRelation,
250-
value: baseDisplayLabel(explicitRelation) + ' ' + explicitRelation.id
266+
value: baseDisplayValue(explicitRelation) + ' ' + explicitRelation.id,
267+
display: baseDisplayLabel(explicitRelation)
251268
});
252269

253270
} else {
254271
editor.intersects(map.extent()).forEach(function(entity) {
255272
if (entity.type !== 'relation' || entity.id === entityID) return;
256273

257-
var value = baseDisplayLabel(entity);
274+
var value = baseDisplayValue(entity);
258275
if (q && (value + ' ' + entity.id).toLowerCase().indexOf(q.toLowerCase()) === -1) return;
259276

260-
result.push({ relation: entity, value: value });
277+
result.push({
278+
relation: entity,
279+
value: value,
280+
display: baseDisplayLabel(entity)
281+
});
261282
});
262283

263284
result.sort(function(a, b) {
@@ -334,14 +355,16 @@ export function uiSectionRawMembershipEditor(context) {
334355
.append('span')
335356
.attr('class', 'member-entity-type')
336357
.html(function(d) {
337-
var matched = presets.match(d.relation, editor.staging.graph);
358+
const matched = presets.match(d.relation, editor.staging.graph);
338359
return (matched && matched.name()) || l10n.t('inspector.relation');
339360
});
340361

341362
labelLink
342363
.append('span')
343364
.attr('class', 'member-entity-name')
344-
.html(function(d) {
365+
.classed('has-color', d => d.relation.tags.colour)
366+
.style('border-color', d => d.relation.tags.colour)
367+
.text(function(d) {
345368
const matched = presets.match(d.relation, editor.staging.graph);
346369
// hide the network from the name if there is NSI match
347370
return l10n.displayName(d.relation.tags, matched.suggestion);

0 commit comments

Comments
 (0)