These work

This commit is contained in:
Andras Schmelczer 2026-02-11 21:32:33 +00:00
parent 3599803589
commit 1588c01b19
19 changed files with 260 additions and 201 deletions

View file

@ -27,30 +27,6 @@ function parseFilters(params: URLSearchParams): FeatureFilters | undefined {
return Object.keys(filters).length > 0 ? filters : undefined;
}
/** Backward compat: parse old comma-packed `f` param */
function parseLegacyFilters(f: string): FeatureFilters | undefined {
const filters: FeatureFilters = {};
for (const segment of f.split(',')) {
const colonIdx = segment.indexOf(':');
if (colonIdx === -1) continue;
const name = segment.substring(0, colonIdx);
const rest = segment.substring(colonIdx + 1);
if (rest.includes(':')) {
const [minStr, maxStr] = rest.split(':');
const min = Number(minStr);
const max = Number(maxStr);
if (!isNaN(min) && !isNaN(max)) {
filters[name] = [min, max];
}
} else if (rest.includes('|')) {
filters[name] = rest.split('|');
} else {
filters[name] = [rest];
}
}
return Object.keys(filters).length > 0 ? filters : undefined;
}
export function parseUrlState(): {
viewState?: ViewState;
filters?: FeatureFilters;
@ -72,45 +48,21 @@ export function parseUrlState(): {
if (!isNaN(latN) && !isNaN(lonN) && !isNaN(zoomN)) {
result.viewState = { latitude: latN, longitude: lonN, zoom: zoomN, pitch: 0 };
}
} else {
// Backward compat: old packed `v=lat,lon,zoom`
const v = params.get('v');
if (v) {
const parts = v.split(',').map(Number);
if (parts.length === 3 && parts.every((n) => !isNaN(n))) {
result.viewState = { latitude: parts[0], longitude: parts[1], zoom: parts[2], pitch: 0 };
}
}
}
// Filters: repeated `filter` params
result.filters = parseFilters(params);
if (!result.filters) {
// Backward compat: old packed `f` param
const f = params.get('f');
if (f) result.filters = parseLegacyFilters(f);
}
// POI categories: repeated `poi` params
const poiParams = params.getAll('poi');
if (poiParams.length > 0) {
// Handle both new (repeated params) and old (comma-separated) formats
const categories = poiParams.flatMap((p) => p.split(',')).filter(Boolean);
if (categories.length > 0) {
result.poiCategories = new Set(categories);
}
result.poiCategories = new Set(poiParams.filter(Boolean));
}
// Tab: full name
const tab = params.get('tab');
if (tab === 'properties' || tab === 'pois' || tab === 'area') {
result.tab = tab;
} else if (tab === 'p') {
result.tab = 'properties'; // backward compat
} else if (tab === 'o') {
result.tab = 'pois';
} else if (tab === 'a') {
result.tab = 'area';
}
// Travel time
@ -121,7 +73,7 @@ export function parseUrlState(): {
const tt: TravelTimeInitial = {
destination: [parts[0], parts[1]],
destinationLabel: params.get('destLabel') || '',
mode: (params.get('tmode') as TransportMode) || 'transit',
mode: (params.get('tmode') as TransportMode) || 'car',
};
const ttRange = params.get('tt');
if (ttRange) {
@ -178,7 +130,7 @@ export function stateToParams(
if (travelTime.destinationLabel) {
params.set('destLabel', travelTime.destinationLabel);
}
if (travelTime.mode !== 'transit') {
if (travelTime.mode !== 'car') {
params.set('tmode', travelTime.mode);
}
if (travelTime.timeRange) {
@ -193,7 +145,6 @@ export function summarizeParams(queryString: string): string {
const params = new URLSearchParams(queryString);
const parts: string[] = [];
// New format: repeated `filter` params
const filterParams = params.getAll('filter');
if (filterParams.length > 0) {
const filterNames = filterParams
@ -207,28 +158,11 @@ export function summarizeParams(queryString: string): string {
filterNames.length <= 2 ? filterNames.join(', ') : `${filterNames.length} filters`
);
}
} else {
// Backward compat: old packed `f` param
const f = params.get('f');
if (f) {
const filterNames = f
.split(',')
.map((seg) => {
const colonIdx = seg.indexOf(':');
return colonIdx > 0 ? seg.substring(0, colonIdx) : seg;
})
.filter(Boolean);
if (filterNames.length > 0) {
parts.push(
filterNames.length <= 2 ? filterNames.join(', ') : `${filterNames.length} filters`
);
}
}
}
const poiParams = params.getAll('poi');
if (poiParams.length > 0) {
const count = poiParams.flatMap((p) => p.split(',')).filter(Boolean).length;
const count = poiParams.filter(Boolean).length;
if (count > 0) {
parts.push(`${count} POI ${count === 1 ? 'category' : 'categories'}`);
}