This commit is contained in:
Andras Schmelczer 2026-03-12 22:11:00 +00:00
parent 14a3555cf1
commit 7e92bf112e
34 changed files with 1214437 additions and 224 deletions

View file

@ -143,6 +143,13 @@ export function useDeckLayers({
const colorFeatureMetaRef = useRef(colorFeatureMeta);
colorFeatureMetaRef.current = colorFeatureMeta;
// Track enum value count for discrete coloring (0 = numeric/continuous)
const enumCountRef = useRef(0);
enumCountRef.current =
colorFeatureMeta?.type === 'enum' && colorFeatureMeta.values
? colorFeatureMeta.values.length
: 0;
// --- Count ranges ---
const countRange = useMemo(() => {
if (data.length === 0) return { min: 0, max: 1 };
@ -360,7 +367,8 @@ export function useDeckLayers({
0,
densityGradientRef.current,
dark,
255
255,
enumCountRef.current
);
}
}
@ -433,7 +441,8 @@ export function useDeckLayers({
0,
densityGradientRef.current,
dark,
180
180,
enumCountRef.current
);
}
const cr = postcodeCountRangeRef.current;

View file

@ -8,6 +8,15 @@ function looksLikePostcode(s: string) {
return POSTCODE_RE.test(s.trim());
}
/** Normalize a UK postcode: uppercase, strip spaces, insert canonical space before inward code. */
function normalizePostcode(s: string): string {
const stripped = s.replace(/\s+/g, '').toUpperCase();
if (stripped.length >= 5) {
return stripped.slice(0, -3) + ' ' + stripped.slice(-3);
}
return stripped;
}
export type SearchResult =
| { type: 'postcode'; label: string }
| { type: 'place'; name: string; slug: string; place_type: string; lat: number; lon: number; city?: string };
@ -35,7 +44,7 @@ export function useLocationSearch(mode?: string) {
}
if (!mode && looksLikePostcode(trimmed)) {
setResults([{ type: 'postcode', label: trimmed.toUpperCase() }]);
setResults([{ type: 'postcode', label: normalizePostcode(trimmed) }]);
setOpen(true);
return;
}
@ -97,7 +106,7 @@ export function useLocationSearch(mode?: string) {
if (activeIndex >= 0 && activeIndex < results.length) {
onSelect(results[activeIndex]);
} else if (looksLikePostcode(query)) {
onSelect({ type: 'postcode', label: query.trim().toUpperCase() });
onSelect({ type: 'postcode', label: normalizePostcode(query) });
}
} else if (e.key === 'Escape') {
setOpen(false);