lmao
This commit is contained in:
parent
03445188ea
commit
524580eb25
102 changed files with 36625 additions and 1295 deletions
|
|
@ -2,7 +2,7 @@ import type { FeatureMeta, FeatureFilters, ViewState } from '../types';
|
|||
import {
|
||||
TRANSPORT_MODES,
|
||||
type TransportMode,
|
||||
type TravelTimeEntries,
|
||||
type TravelTimeEntry,
|
||||
type TravelTimeInitial,
|
||||
} from '../hooks/useTravelTime';
|
||||
|
||||
|
|
@ -70,32 +70,31 @@ export function parseUrlState(): {
|
|||
result.tab = tab;
|
||||
}
|
||||
|
||||
// Travel time: per-mode params (tt_car=lat,lon ttl_car=label ttr_car=min:max)
|
||||
const entries: TravelTimeEntries = {};
|
||||
for (const mode of TRANSPORT_MODES) {
|
||||
const dest = params.get(`tt_${mode}`);
|
||||
if (dest) {
|
||||
const parts = dest.split(',').map(Number);
|
||||
if (parts.length === 2 && parts.every((n) => !isNaN(n))) {
|
||||
const label = params.get(`ttl_${mode}`) || '';
|
||||
let timeRange: [number, number] | null = null;
|
||||
const rangeStr = params.get(`ttr_${mode}`);
|
||||
if (rangeStr) {
|
||||
const [min, max] = rangeStr.split(':').map(Number);
|
||||
if (!isNaN(min) && !isNaN(max)) {
|
||||
timeRange = [min, max];
|
||||
}
|
||||
// Travel time: repeated `tt` params
|
||||
// Format: mode:slug:label or mode:slug:label:min:max
|
||||
const ttParams = params.getAll('tt');
|
||||
if (ttParams.length > 0) {
|
||||
const entries: TravelTimeEntry[] = [];
|
||||
for (const tt of ttParams) {
|
||||
const parts = tt.split(':');
|
||||
if (parts.length < 3) continue;
|
||||
const mode = parts[0] as TransportMode;
|
||||
if (!TRANSPORT_MODES.includes(mode)) continue;
|
||||
const slug = parts[1];
|
||||
const label = decodeURIComponent(parts[2]);
|
||||
let timeRange: [number, number] | null = null;
|
||||
if (parts.length >= 5) {
|
||||
const min = Number(parts[3]);
|
||||
const max = Number(parts[4]);
|
||||
if (!isNaN(min) && !isNaN(max)) {
|
||||
timeRange = [min, max];
|
||||
}
|
||||
entries[mode] = {
|
||||
destination: [parts[0], parts[1]],
|
||||
destinationLabel: label,
|
||||
timeRange,
|
||||
};
|
||||
}
|
||||
entries.push({ mode, slug, label, timeRange });
|
||||
}
|
||||
if (entries.length > 0) {
|
||||
result.travelTime = { entries };
|
||||
}
|
||||
}
|
||||
if (Object.keys(entries).length > 0) {
|
||||
result.travelTime = { entries };
|
||||
}
|
||||
|
||||
return result;
|
||||
|
|
@ -107,7 +106,7 @@ export function stateToParams(
|
|||
features: FeatureMeta[],
|
||||
selectedPOICategories: Set<string>,
|
||||
rightPaneTab: 'properties' | 'area',
|
||||
travelTimeEntries?: TravelTimeEntries
|
||||
travelTimeEntries?: TravelTimeEntry[]
|
||||
): URLSearchParams {
|
||||
const params = new URLSearchParams();
|
||||
|
||||
|
|
@ -135,18 +134,15 @@ export function stateToParams(
|
|||
params.set('tab', 'properties');
|
||||
}
|
||||
|
||||
// Travel time: per-mode params
|
||||
// Travel time: repeated `tt` params
|
||||
if (travelTimeEntries) {
|
||||
for (const mode of TRANSPORT_MODES) {
|
||||
const entry = travelTimeEntries[mode];
|
||||
if (!entry?.destination) continue;
|
||||
params.set(`tt_${mode}`, `${entry.destination[0].toFixed(5)},${entry.destination[1].toFixed(5)}`);
|
||||
if (entry.destinationLabel) {
|
||||
params.set(`ttl_${mode}`, entry.destinationLabel);
|
||||
}
|
||||
for (const entry of travelTimeEntries) {
|
||||
if (!entry.slug) continue;
|
||||
let val = `${entry.mode}:${entry.slug}:${encodeURIComponent(entry.label)}`;
|
||||
if (entry.timeRange) {
|
||||
params.set(`ttr_${mode}`, `${entry.timeRange[0]}:${entry.timeRange[1]}`);
|
||||
val += `:${entry.timeRange[0]}:${entry.timeRange[1]}`;
|
||||
}
|
||||
params.append('tt', val);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue