Skip to content

Commit

Permalink
County label enhancement (#236)
Browse files Browse the repository at this point in the history
  • Loading branch information
nofurtherinformation authored Jan 3, 2025
1 parent 580252c commit 47e777f
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 26 deletions.
26 changes: 22 additions & 4 deletions app/src/app/components/sidebar/Layers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,14 @@ export default function Layers() {
>
Show painted districts
</CheckboxGroup.Item>
<CheckboxGroup.Item value="2" onClick={() => setMapOptions({
showZoneNumbers: !mapOptions.showZoneNumbers
})}>
<CheckboxGroup.Item
value="2"
onClick={() =>
setMapOptions({
showZoneNumbers: !mapOptions.showZoneNumbers,
})
}
>
Show numbering for painted districts <i>(experimental)</i>
</CheckboxGroup.Item>
<CheckboxGroup.Item
Expand Down Expand Up @@ -102,11 +107,24 @@ export default function Layers() {
</Heading>
<CheckboxGroup.Root
name="contextualLayers"
value={COUNTY_LAYER_IDS.every(layerId => visibleLayerIds.includes(layerId)) ? ['1'] : []}
value={[
COUNTY_LAYER_IDS.every(layerId => visibleLayerIds.includes(layerId)) ? '1' : '',
mapOptions.prominentCountyNames ? 'prominentCountyNames' : '',
]}
>
<CheckboxGroup.Item value="1" onClick={() => toggleLayers(COUNTY_LAYER_IDS)}>
Show county boundaries
</CheckboxGroup.Item>
<CheckboxGroup.Item
value="prominentCountyNames"
onClick={() =>
setMapOptions({
prominentCountyNames: !mapOptions.prominentCountyNames,
})
}
>
Emphasize County Names
</CheckboxGroup.Item>
<CheckboxGroup.Item value="2" disabled>
Show tribes and communities
</CheckboxGroup.Item>
Expand Down
42 changes: 21 additions & 21 deletions app/src/app/constants/basemapLayers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1105,27 +1105,6 @@ export const BASEMAP_LAYERS: LayerSpecification[] = [
'line-width': ['interpolate', ['exponential', 1.6], ['zoom'], 6, .625, 9, 1.625, 18, 2.25],
},
},
{
id: 'counties_labels',
type: 'symbol',
source: 'counties',
'source-layer': 'tl_2023_us_county_label',
minzoom: 6,
layout: {
'text-field': ['get', 'NAME'],
'text-font': ['Barlow Regular'],
'text-size': 10,
'text-transform': 'uppercase',
'text-letter-spacing': 0.1,
'text-max-width': 9,
'text-padding': ['interpolate', ['linear'], ['zoom'], 5, 3, 8, 7, 12, 11],
},
paint: {
'text-color': '#666',
'text-halo-color': '#ffffff',
'text-halo-width': 2,
},
},
{
id: 'places_locality',
type: 'symbol',
Expand Down Expand Up @@ -1282,4 +1261,25 @@ export const BASEMAP_LAYERS: LayerSpecification[] = [
'text-color': '#b8b8b8',
},
},
{
id: 'counties_labels',
type: 'symbol',
source: 'counties',
'source-layer': 'tl_2023_us_county_label',
minzoom: 6,
layout: {
'text-field': ['get', 'NAME'],
'text-font': ['Barlow Bold'],
'text-size': ['interpolate', ['linear'], ['zoom'], 5, 8, 8, 12, 12, 16],
'text-transform': 'uppercase',
'text-letter-spacing': 0.1,
'text-max-width': 12,
'text-padding': ['interpolate', ['linear'], ['zoom'], 5, 3, 8, 7, 12, 11],
},
paint: {
'text-color': '#666',
'text-halo-color': '#ffffff',
'text-halo-width': 2,
}
},
];
15 changes: 14 additions & 1 deletion app/src/app/store/mapRenderSubs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,12 +318,25 @@ export const getRenderSubscriptions = (useMapStore: typeof _useMapStore, useHove
([stateFp, getMapRef]) => {
const mapRef = getMapRef()
if (!mapRef) return
const filterExpression = (stateFp ? ["==", ["slice", ["get", "GEOID"], 0, 2], stateFp] : true) as any
const filterExpression = ["==", ["slice", ["get", "GEOID"], 0, 2], stateFp ? stateFp : '--'] as any
COUNTY_LAYERS.forEach(layer => {
mapRef.getLayer(layer) && mapRef.setFilter(layer, ["any", filterExpression])
})
}
)
const countyEmphasisSub = useMapStore.subscribe(state => state.mapOptions.prominentCountyNames, (prominentCountyNames) => {
const mapRef = useMapStore.getState().getMapRef();
if (!mapRef) return;
const layers = mapRef.getStyle().layers;
const layerLength = layers.length;
if (prominentCountyNames) {
mapRef.moveLayer('counties_labels', layers[layerLength - 1].id); // move to top
mapRef.setLayoutProperty('counties_labels', 'text-font', ['Barlow Bold']);
} else {
mapRef.moveLayer('counties_labels', 'counties_boundary'); // move to other county labes
mapRef.setLayoutProperty('counties_labels', 'text-font', ['Barlow Regular']);
}
})

const _hoverMapSideEffectRender = useHoverStore.subscribe(
state => state.hoverFeatures,
Expand Down
1 change: 1 addition & 0 deletions app/src/app/store/mapStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,7 @@ export const useMapStore = create(
showBrokenDistricts: false,
mode: 'default',
lockPaintedAreas: false,
prominentCountyNames: true
},
setMapOptions: options => set({mapOptions: {...get().mapOptions, ...options}}),
toggleHighlightBrokenDistricts: (_ids, _higlighted) => {
Expand Down
1 change: 1 addition & 0 deletions app/src/app/store/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export type DistrictrMapOptions = {
paintByCounty?: boolean;
currentStateFp?: string;
showPopulationTooltip?: boolean;
prominentCountyNames?: boolean;
};

export type DistrictrChartOptions = {
Expand Down

0 comments on commit 47e777f

Please sign in to comment.