Skip to content

Commit d4bfbaa

Browse files
committed
Merge branch 'relation-colours' into develop
2 parents 41b9cb5 + 20b72a2 commit d4bfbaa

File tree

7 files changed

+80
-15
lines changed

7 files changed

+80
-15
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ _Breaking developer changes, which may affect downstream projects or sites that
3939

4040
#### :tada: New Features
4141
#### :sparkles: Usability & Accessibility
42+
* Show the color of (route) relations in the form of small colored circles in relation membership section and feature search results ([#9424])
4243
#### :scissors: Operations
4344
#### :camera: Street-Level
4445
#### :white_check_mark: Validation
@@ -48,6 +49,8 @@ _Breaking developer changes, which may affect downstream projects or sites that
4849
#### :mortar_board: Walkthrough / Help
4950
#### :hammer: Development
5051

52+
[#9424]: https://github.com/openstreetmap/iD/pull/9424
53+
5154

5255
# 2.27.3
5356
##### 2023-Nov-08

css/80_app.css

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1413,7 +1413,7 @@ a.hide-toggle {
14131413
.ideditor[dir='rtl'] .field-label .label-text {
14141414
padding: 5px 10px 4px 0;
14151415
}
1416-
.field-label .label-text span {
1416+
.field-label .label-text {
14171417
white-space: nowrap;
14181418
}
14191419

@@ -2835,12 +2835,39 @@ img.tag-reference-wiki-image {
28352835
font-weight: normal;
28362836
padding-left: 10px;
28372837
}
2838+
.section-raw-member-editor .member-row .member-entity-name.has-colour::before,
2839+
.section-raw-membership-editor .member-row .member-entity-name.has-colour::before,
2840+
.feature-list .entity-name.has-colour::before,
2841+
.combobox-parent-relation .has-colour::before {
2842+
display: inline-block;
2843+
content: '';
2844+
margin-left: -5px;
2845+
margin-right: 5px;
2846+
border-style: solid;
2847+
border-width: 4px;
2848+
border-radius: 4px;
2849+
border-color: inherit;
2850+
}
2851+
.combobox-parent-relation .has-colour::before {
2852+
margin-left: 2px;
2853+
}
28382854

28392855
.ideditor[dir='rtl'] .section-raw-member-editor .member-row .member-entity-name,
28402856
.ideditor[dir='rtl'] .section-raw-membership-editor .member-row .member-entity-name {
28412857
padding-left:0;
28422858
padding-right: 10px;
28432859
}
2860+
.ideditor[dir='rtl'] .section-raw-member-editor .member-row .member-entity-name.has-colour::before,
2861+
.ideditor[dir='rtl'] .section-raw-membership-editor .member-row .member-entity-name.has-colour::before,
2862+
.ideditor[dir='rtl'] .feature-list .entity-name.has-colour::before {
2863+
margin-left: 5px;
2864+
margin-right: -5px;
2865+
}
2866+
.ideditor[dir='rtl'] .combobox-parent-relation .has-colour::before {
2867+
margin-left: 5px;
2868+
margin-right: 2px;
2869+
}
2870+
28442871

28452872
.form-field-input-member > input.member-role {
28462873
border-radius: 0 0 4px 4px;

modules/osm/tags.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,3 +245,16 @@ export var osmFlowingWaterwayTagValues = {
245245

246246
// Tags which values should be considered case sensitive when offering tag suggestions
247247
export const allowUpperCaseTagValues = /network|taxon|genus|species|brand|grape_variety|royal_cypher|listed_status|booth|rating|stars|:output|_hours|_times|_ref|manufacturer|country|target|brewery|cai_scale|traffic_sign/;
248+
249+
// Returns whether a `colour` tag value looks like a valid color we can display
250+
export function isColourValid(value) {
251+
if (!value.match(/^(#([0-9a-fA-F]{3}){1,2}|\w+)$/)) {
252+
// OSM only supports hex or named colors
253+
return false;
254+
}
255+
if (!CSS.supports('color', value) || ['unset', 'inherit', 'initial', 'revert'].includes(value)) {
256+
// see https://stackoverflow.com/a/68217760/1627467
257+
return false;
258+
}
259+
return true;
260+
}

modules/ui/feature_list.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { geoSphericalDistance } from '../geo/geo';
1111
import { geoExtent } from '../geo';
1212
import { modeSelect } from '../modes/select';
1313
import { osmEntity } from '../osm/entity';
14+
import { isColourValid } from '../osm/tags';
1415
import { services } from '../services';
1516
import { svgIcon } from '../svg/icon';
1617
import { uiCmd } from './cmd';
@@ -310,6 +311,8 @@ export function uiFeatureList(context) {
310311
label
311312
.append('span')
312313
.attr('class', 'entity-name')
314+
.classed('has-colour', d => d.entity && d.entity.type === 'relation' && d.entity.tags.colour && isColourValid(d.entity.tags.colour))
315+
.style('border-color', d => d.entity && d.entity.type === 'relation' && d.entity.tags.colour)
313316
.text(function(d) { return d.name; });
314317

315318
enter

modules/ui/fields/input.js

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { t, localizer } from '../../core/localizer';
99
import { utilDetect, utilGetSetValue, utilNoAuto, utilRebind, utilTotalExtent } from '../../util';
1010
import { svgIcon } from '../../svg/icon';
1111
import { cardinal } from '../../osm/node';
12+
import { isColourValid } from '../../osm/tags';
1213
import { uiLengthIndicator } from '..';
1314
import { uiTooltip } from '../tooltip';
1415
import { isEqual } from 'lodash-es';
@@ -228,16 +229,6 @@ export function uiFieldText(field, context) {
228229

229230

230231
function updateColourPreview() {
231-
function isColourValid(colour) {
232-
if (!colour.match(/^(#([0-9a-fA-F]{3}){1,2}|\w+)$/)) {
233-
// OSM only supports hex or named colors
234-
return false;
235-
} else if (!CSS.supports('color', colour) || ['unset', 'inherit', 'initial', 'revert'].includes(colour)) {
236-
// see https://stackoverflow.com/a/68217760/1627467
237-
return false;
238-
}
239-
return true;
240-
}
241232
wrap.selectAll('.colour-preview')
242233
.remove();
243234

modules/ui/sections/raw_member_editor.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { actionMoveMember } from '../../actions/move_member';
1111
import { modeBrowse } from '../../modes/browse';
1212
import { modeSelect } from '../../modes/select';
1313
import { osmEntity } from '../../osm';
14+
import { isColourValid } from '../../osm/tags';
1415
import { svgIcon } from '../../svg/icon';
1516
import { services } from '../../services';
1617
import { uiCombobox } from '../combobox';
@@ -198,6 +199,8 @@ export function uiSectionRawMemberEditor(context) {
198199
labelLink
199200
.append('span')
200201
.attr('class', 'member-entity-name')
202+
.classed('has-colour', d => d.member.type === 'relation' && d.member.tags.colour && isColourValid(d.member.tags.colour))
203+
.style('border-color', d => d.member.type === 'relation' && d.member.tags.colour)
201204
.text(function(d) { return utilDisplayName(d.member); });
202205

203206
label

modules/ui/sections/raw_membership_editor.js

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { actionDeleteMembers } from '../../actions/delete_members';
1212

1313
import { modeSelect } from '../../modes/select';
1414
import { osmEntity, osmRelation } from '../../osm';
15+
import { isColourValid } from '../../osm/tags';
1516
import { services } from '../../services';
1617
import { svgIcon } from '../../svg/icon';
1718
import { uiCombobox } from '../combobox';
@@ -239,31 +240,53 @@ export function uiSectionRawMembershipEditor(context) {
239240

240241
var graph = context.graph();
241242

242-
function baseDisplayLabel(entity) {
243+
function baseDisplayValue(entity) {
243244
var matched = presetManager.match(entity, graph);
244245
var presetName = (matched && matched.name()) || t('inspector.relation');
245246
var entityName = utilDisplayName(entity) || '';
246247

247248
return presetName + ' ' + entityName;
248249
}
249250

251+
function baseDisplayLabel(entity) {
252+
var matched = presetManager.match(entity, graph);
253+
var presetName = (matched && matched.name()) || t('inspector.relation');
254+
var entityName = utilDisplayName(entity) || '';
255+
256+
return selection => {
257+
selection
258+
.append('b')
259+
.text(presetName + ' ');
260+
selection
261+
.append('span')
262+
.classed('has-colour', entity.tags.colour && isColourValid(entity.tags.colour))
263+
.style('border-color', entity.tags.colour)
264+
.text(entityName);
265+
};
266+
}
267+
250268
var explicitRelation = q && context.hasEntity(q.toLowerCase());
251269
if (explicitRelation && explicitRelation.type === 'relation' && explicitRelation.id !== entityID) {
252270
// loaded relation is specified explicitly, only show that
253271

254272
result.push({
255273
relation: explicitRelation,
256-
value: baseDisplayLabel(explicitRelation) + ' ' + explicitRelation.id
274+
value: baseDisplayValue(explicitRelation) + ' ' + explicitRelation.id,
275+
display: baseDisplayLabel(explicitRelation)
257276
});
258277
} else {
259278

260279
context.history().intersects(context.map().extent()).forEach(function(entity) {
261280
if (entity.type !== 'relation' || entity.id === entityID) return;
262281

263-
var value = baseDisplayLabel(entity);
282+
var value = baseDisplayValue(entity);
264283
if (q && (value + ' ' + entity.id).toLowerCase().indexOf(q.toLowerCase()) === -1) return;
265284

266-
result.push({ relation: entity, value: value });
285+
result.push({
286+
relation: entity,
287+
value,
288+
display: baseDisplayLabel(entity)
289+
});
267290
});
268291

269292
result.sort(function(a, b) {
@@ -349,6 +372,8 @@ export function uiSectionRawMembershipEditor(context) {
349372
labelLink
350373
.append('span')
351374
.attr('class', 'member-entity-name')
375+
.classed('has-colour', d => d.relation.tags.colour && isColourValid(d.relation.tags.colour))
376+
.style('border-color', d => d.relation.tags.colour)
352377
.text(function(d) { return utilDisplayName(d.relation); });
353378

354379
labelEnter

0 commit comments

Comments
 (0)