Skip to content

Commit 377f726

Browse files
fix: continue shading while highlighting divisions
1 parent 74b3b06 commit 377f726

File tree

2 files changed

+72
-31
lines changed

2 files changed

+72
-31
lines changed

src/components/map/divisionHighlighting.js

Lines changed: 44 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,26 @@ export function highlightMatchedDivisions(map, divisions) {
99

1010
console.log('Highlighting divisions:', divisions)
1111

12-
// Reset all divisions to default style
13-
map.setPaintProperty('divisions-fill', 'fill-color', '#627BC1')
14-
map.setPaintProperty('divisions-fill', 'fill-opacity', 0.2)
1512
// Reset text styling to defaults
16-
map.setPaintProperty('divisions-labels', 'text-color', '#ffffff')
17-
map.setPaintProperty('divisions-labels', 'text-halo-color', '#ff474c')
18-
map.setPaintProperty('divisions-labels', 'text-halo-width', 2)
13+
map.setPaintProperty('divisions-labels', 'text-color', [
14+
'case',
15+
['any',
16+
['==', ['typeof', ['get', 'count']], 'null'],
17+
['<=', ['to-number', ['get', 'count']], 0]
18+
],
19+
'#666666', // Dark gray for zero/null values
20+
'#ffffff' // White for non-zero values
21+
])
22+
map.setPaintProperty('divisions-labels', 'text-halo-color', '#000000')
23+
map.setPaintProperty('divisions-labels', 'text-halo-width', 1)
24+
25+
// Reset line styling
26+
map.setPaintProperty('divisions-layer', 'line-color', '#627BC1')
27+
map.setPaintProperty('divisions-layer', 'line-width', 1)
1928

2029
if (!divisions || divisions.length === 0) {
30+
// Clear highlight effects
31+
map.setPaintProperty('divisions-highlight', 'fill-opacity', 0)
2132
return []
2233
}
2334

@@ -33,41 +44,57 @@ export function highlightMatchedDivisions(map, divisions) {
3344

3445
console.log('Applying match filter:', JSON.stringify(matchFilter))
3546

36-
// Highlight matched divisions
37-
map.setPaintProperty('divisions-fill', 'fill-color', [
47+
// Update highlight overlay for matched divisions
48+
map.setPaintProperty('divisions-highlight', 'fill-opacity', [
49+
'case',
50+
matchFilter,
51+
0.4, // Semi-transparent highlight for matches
52+
0 // Invisible for non-matches
53+
])
54+
55+
// Add a bright border for highlighted divisions
56+
map.setPaintProperty('divisions-layer', 'line-color', [
3857
'case',
3958
matchFilter,
40-
'#ff474c', // Highlight color for matches
41-
'#627BC1' // Default color
59+
'#ff474c', // Highlight color for matches
60+
'#627BC1' // Default color
4261
])
4362

44-
map.setPaintProperty('divisions-fill', 'fill-opacity', [
63+
map.setPaintProperty('divisions-layer', 'line-width', [
4564
'case',
4665
matchFilter,
47-
0.5, // Higher opacity for matches
48-
0.2 // Default opacity
66+
2.5, // Thicker line for matches
67+
1 // Default line width
4968
])
5069

5170
// Update text styling based on highlight state
5271
map.setPaintProperty('divisions-labels', 'text-color', [
5372
'case',
5473
matchFilter,
55-
'#333333', // Dark text for highlighted divisions
56-
'#ffffff' // White text for normal divisions
74+
'#000000', // Black text for highlighted divisions
75+
[
76+
'case',
77+
['any',
78+
['==', ['typeof', ['get', 'count']], 'null'],
79+
['<=', ['to-number', ['get', 'count']], 0]
80+
],
81+
'#666666', // Dark gray for zero/null values
82+
'#ffffff' // White for non-zero values
83+
]
5784
])
5885

5986
map.setPaintProperty('divisions-labels', 'text-halo-color', [
6087
'case',
6188
matchFilter,
6289
'#ffffff', // White halo for highlighted divisions
63-
'#ff474c' // Red halo for normal divisions
90+
'#000000' // Black halo for normal divisions
6491
])
6592

6693
map.setPaintProperty('divisions-labels', 'text-halo-width', [
6794
'case',
6895
matchFilter,
6996
2.5, // Wider halo for highlighted divisions
70-
2 // Normal halo width for others
97+
1 // Normal halo width for others
7198
])
7299

73100
return convertedDivisions

src/components/map/mapConfig.js

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export function addDivisionLayers(map, geojsonData) {
6464
data: geojsonData
6565
})
6666

67-
// Add fill layer first (below the line layer)
67+
// Add base fill layer for count-based coloring
6868
map.addLayer({
6969
id: 'divisions-fill',
7070
type: 'fill',
@@ -94,7 +94,33 @@ export function addDivisionLayers(map, geojsonData) {
9494
}
9595
})
9696

97-
// Add labels layer
97+
// Add highlight layer above the base fill
98+
map.addLayer({
99+
id: 'divisions-highlight',
100+
type: 'fill',
101+
source: 'divisions',
102+
paint: {
103+
'fill-color': '#ff474c',
104+
'fill-opacity': 0,
105+
'fill-opacity-transition': {
106+
duration: 200
107+
}
108+
}
109+
})
110+
111+
// Add hover effect layer
112+
map.addLayer({
113+
id: 'divisions-hover',
114+
type: 'line',
115+
source: 'divisions',
116+
paint: {
117+
'line-color': '#000000',
118+
'line-width': 2
119+
},
120+
filter: ['==', ['get', 'division'], '']
121+
})
122+
123+
// Add labels layer last so they're always on top
98124
map.addLayer({
99125
id: 'divisions-labels',
100126
type: 'symbol',
@@ -122,18 +148,6 @@ export function addDivisionLayers(map, geojsonData) {
122148
'text-halo-width': 1
123149
}
124150
})
125-
126-
// Add hover effect layer
127-
map.addLayer({
128-
id: 'divisions-hover',
129-
type: 'line',
130-
source: 'divisions',
131-
paint: {
132-
'line-color': '#000000',
133-
'line-width': 2
134-
},
135-
filter: ['==', ['get', 'division'], '']
136-
})
137151
}
138152

139153
export function updateFillColors(map, divisionStats) {

0 commit comments

Comments
 (0)