Skip to content

Commit b09f071

Browse files
authored
Merge pull request #70 from napakalas/issue-#68
Update nerve cuff selection to be consistent with other selectable objects
2 parents abe3f72 + cd13cd8 commit b09f071

File tree

4 files changed

+59
-16
lines changed

4 files changed

+59
-16
lines changed

src/flatmap.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ export class FlatMap
245245
#taxonToFeatureIds: FeatureIdMap = new Map()
246246
#userInteractions: UserInteractions|null = null
247247
#uuid: string
248+
#nerveToFeatureIds: Map<GeoJSONId, GeoJSONId[]> = new Map()
248249

249250
constructor(container: string, mapServer: FlatMapServer, mapDescription: MapDescription)
250251
{
@@ -922,6 +923,21 @@ export class FlatMap
922923
return null
923924
}
924925

926+
/**
927+
* Get feature GeoJSON ids given a nerve id.
928+
*
929+
* @param {GeoJSONId} nerveId The nerve identifier
930+
* @return {GeoJSONId[]} The feature GeoJSON ids
931+
*/
932+
featureIdsByNerveId(nerveId: GeoJSONId): GeoJSONId[]
933+
//=================================================
934+
{
935+
if (this.#nerveToFeatureIds.has(nerveId)) {
936+
return this.#nerveToFeatureIds.get(nerveId) || []
937+
}
938+
return []
939+
}
940+
925941
/**
926942
* Flag the feature as having external annotation.
927943
*
@@ -1001,6 +1017,15 @@ export class FlatMap
10011017
}
10021018
this.#annIdToFeatureId.set(ann.id, featureId)
10031019

1020+
if ('nerveId' in ann && ann.nerveId && 'type' in ann && ann.type === 'nerve') {
1021+
const existingFeatureIds = this.#nerveToFeatureIds.get(ann.nerveId as GeoJSONId)
1022+
if (existingFeatureIds) {
1023+
existingFeatureIds.push(featureId)
1024+
} else {
1025+
this.#nerveToFeatureIds.set(ann.nerveId as GeoJSONId, [featureId])
1026+
}
1027+
}
1028+
10041029
// Pre-compute LineStrings of centrelines in centreline maps
10051030
if (this.options.style === FLATMAP_STYLE.CENTRELINE && ann.centreline) {
10061031
try {

src/interactions.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -816,6 +816,12 @@ export class UserInteractions
816816
if (!this.#activeFeatures.has(+feature.id!)) {
817817
this.#activeFeatures.set(+feature.id!, feature)
818818
}
819+
// If the feature is a nerve, activate its inner features too
820+
for (const innerFeatureId of this.#flatmap.featureIdsByNerveId(+feature.id!)) {
821+
if (+feature.id! !== innerFeatureId){
822+
this.activateFeature(this.mapFeature(+innerFeatureId))
823+
}
824+
}
819825
}
820826
}
821827

src/layers/styling.ts

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,30 +1110,34 @@ export class NervePolygonFill extends VectorStyleLayer
11101110
const dimmed = options.dimmed || false
11111111
const paintStyle: PaintSpecification = {
11121112
'fill-color': [
1113-
'let', 'active', ['to-number', ['feature-state', 'active'], 0],
1114-
[ 'case',
1115-
['all',
1116-
['==', ['var', 'active'], 0],
1117-
['==', ['get', 'type'], 'arrow'],
1118-
['boolean', ['feature-state', 'selected'], false]
1119-
], COLOUR_SELECTED,
1120-
['==', ['get', 'kind'], 'bezier-end'], 'red',
1121-
['==', ['get', 'kind'], 'bezier-control'], 'green',
1122-
// @ts-expect-error 2322
1123-
...PATH_STYLE_RULES, '#A5F160'
1124-
]
1113+
'case',
1114+
['boolean', ['feature-state', 'selected'], false], COLOUR_SELECTED,
1115+
['all',
1116+
['==', ['case', ['has', 'shape-type'], ['get', 'shape-type'], 'component'], 'component'],
1117+
['boolean', ['feature-state', 'active'], false]
1118+
], '#D88',
1119+
['has', 'colour'], ['get', 'colour'],
1120+
['==', ['get', 'kind'], 'bezier-end'], 'red',
1121+
['==', ['get', 'kind'], 'bezier-control'], 'green',
1122+
// @ts-expect-error 2322
1123+
...PATH_STYLE_RULES, '#00A0FF'
11251124
],
11261125
'fill-opacity': [
11271126
'case',
11281127
['boolean', ['feature-state', 'hidden'], false], 0.01,
1129-
['boolean', ['feature-state', 'selected'], false], 0.8,
1130-
['boolean', ['feature-state', 'active'], false], 0.9,
1131-
['==', ['get', 'type'], 'bezier'], 0.9,
1128+
['boolean', ['feature-state', 'selected'], false], 0.2,
1129+
['has', 'opacity'], ['get', 'opacity'],
1130+
['has', 'colour'], 1.0,
1131+
['==', ['get', 'kind'], 'proxy'], 1.0,
1132+
['all',
1133+
['==', ['case', ['has', 'shape-type'], ['get', 'shape-type'], 'component'], 'component'],
1134+
['boolean', ['feature-state', 'active'], false]
1135+
], 0.7,
11321136
['any',
11331137
['==', ['get', 'type'], 'arrow'],
11341138
['==', ['get', 'type'], 'junction']
11351139
], dimmed ? 0.1 : 0.5,
1136-
1.0
1140+
0.5
11371141
]
11381142
}
11391143
return super.changedPaintStyle(paintStyle, changes)

src/legend.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export type FlatmapLegendEntry = {
2323
colour: string
2424
style: 'circle' | 'exoid' | 'hexagon' |'rounded-square' | 'square' | 'star'
2525
border?: string
26+
borderStyle?: string
2627
}
2728

2829
export const FLATMAP_LEGEND: FlatmapLegendEntry[] = [
@@ -51,6 +52,13 @@ export const FLATMAP_LEGEND: FlatmapLegendEntry[] = [
5152
colour: '#FFFF09',
5253
style: 'star',
5354
border: 'black'
55+
},
56+
{
57+
prompt: 'Nerve',
58+
colour: '#00A0FF80',
59+
style: 'circle',
60+
border: 'grey',
61+
borderStyle: 'dashed'
5462
}
5563
]
5664

0 commit comments

Comments
 (0)