Smal
This commit is contained in:
parent
d34478e13c
commit
1934a38677
5 changed files with 66 additions and 9 deletions
|
|
@ -48,7 +48,7 @@ import {
|
|||
type PoiFilterName,
|
||||
} from './poi-distance-filter';
|
||||
import { dedupeTravelTimeEntries } from './travel-params';
|
||||
import { isOverlayId, type OverlayId } from './overlays';
|
||||
import { isOverlayId, DEFAULT_OVERLAY_IDS, type OverlayId } from './overlays';
|
||||
import { CRIME_TYPES, isCrimeTypeValue } from './crime-types';
|
||||
import { isBasemapId, type BasemapId } from './basemaps';
|
||||
import {
|
||||
|
|
@ -59,6 +59,7 @@ import {
|
|||
|
||||
const POI_NONE_PARAM = '__none';
|
||||
const CRIME_TYPES_NONE_PARAM = '__none';
|
||||
const OVERLAY_NONE_PARAM = '__none';
|
||||
const CRIME_OVERLAY_ID: OverlayId = 'crime-hotspots';
|
||||
|
||||
export interface UrlState {
|
||||
|
|
@ -227,7 +228,7 @@ export function parseUrlState(): UrlState {
|
|||
hasExplicitView: false,
|
||||
filters: parseFilters(params),
|
||||
poiCategories: new Set(),
|
||||
overlays: new Set(),
|
||||
overlays: new Set(DEFAULT_OVERLAY_IDS),
|
||||
basemap: 'standard',
|
||||
colorOpacity: DEFAULT_COLOR_OPACITY,
|
||||
tab: 'area',
|
||||
|
|
@ -266,9 +267,14 @@ export function parseUrlState(): UrlState {
|
|||
}
|
||||
}
|
||||
|
||||
// Overlays default to DEFAULT_OVERLAY_IDS on a fresh visit; explicit `overlay`
|
||||
// params override that, and the `__none` sentinel records "all off" so it
|
||||
// survives a reload instead of silently restoring the defaults.
|
||||
const overlayParams = params.getAll('overlay');
|
||||
if (overlayParams.length > 0) {
|
||||
result.overlays = new Set(overlayParams.filter(isOverlayId));
|
||||
result.overlays = overlayParams.includes(OVERLAY_NONE_PARAM)
|
||||
? new Set()
|
||||
: new Set(overlayParams.filter(isOverlayId));
|
||||
}
|
||||
|
||||
// Crime-type filter: repeated `crimeType` params, or the `__none` sentinel.
|
||||
|
|
@ -451,8 +457,14 @@ export function stateToParams(
|
|||
}
|
||||
|
||||
if (selectedOverlays) {
|
||||
for (const overlay of selectedOverlays) {
|
||||
params.append('overlay', overlay);
|
||||
if (selectedOverlays.size === 0) {
|
||||
// Distinguish a deliberate "all overlays off" from a fresh visit, which
|
||||
// would otherwise re-apply the defaults on reload.
|
||||
params.append('overlay', OVERLAY_NONE_PARAM);
|
||||
} else {
|
||||
for (const overlay of selectedOverlays) {
|
||||
params.append('overlay', overlay);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue