Working
This commit is contained in:
parent
14a3555cf1
commit
7e92bf112e
34 changed files with 1214437 additions and 224 deletions
|
|
@ -8,6 +8,7 @@ import {
|
|||
ZOOM_TO_RESOLUTION_THRESHOLDS,
|
||||
TWEMOJI_BASE,
|
||||
BUFFER_MULTIPLIER,
|
||||
ENUM_PALETTE,
|
||||
} from './consts';
|
||||
|
||||
const ROAD_OPACITY = 0.4;
|
||||
|
|
@ -193,9 +194,16 @@ export function emojiToTwemojiUrl(emoji: string): string {
|
|||
return `${TWEMOJI_BASE}${hex}.png`;
|
||||
}
|
||||
|
||||
/** Look up a discrete color from the enum palette by index (wraps if > palette size). */
|
||||
export function enumIndexToColor(index: number): [number, number, number] {
|
||||
const i = Math.round(Math.max(0, index)) % ENUM_PALETTE.length;
|
||||
return ENUM_PALETTE[i];
|
||||
}
|
||||
|
||||
/**
|
||||
* Shared fill-color logic for hex and postcode layers.
|
||||
* When a viewFeature is active, normalizes by colorRange and applies the feature gradient.
|
||||
* For enum features (enumCount > 0), uses discrete palette colors instead of gradient.
|
||||
* Otherwise falls back to density-based coloring using countRange.
|
||||
*/
|
||||
export function getFeatureFillColor(
|
||||
|
|
@ -207,7 +215,8 @@ export function getFeatureFillColor(
|
|||
countNormalized: number,
|
||||
densityGradient: GradientStop[],
|
||||
isDark: boolean,
|
||||
alpha: number
|
||||
alpha: number,
|
||||
enumCount: number = 0
|
||||
): [number, number, number, number] {
|
||||
if (colorRange) {
|
||||
if (value == null)
|
||||
|
|
@ -222,6 +231,13 @@ export function getFeatureFillColor(
|
|||
];
|
||||
}
|
||||
}
|
||||
|
||||
// Discrete coloring for enum features
|
||||
if (enumCount > 0) {
|
||||
const rgb = enumIndexToColor(Math.round(value as number));
|
||||
return [...rgb, alpha] as [number, number, number, number];
|
||||
}
|
||||
|
||||
const range = colorRange[1] - colorRange[0];
|
||||
if (range === 0)
|
||||
return [...FEATURE_GRADIENT[0].color, alpha] as [number, number, number, number];
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue