Changes
This commit is contained in:
parent
3a3f899ea2
commit
128b3191e7
68 changed files with 28060 additions and 1152 deletions
|
|
@ -1,5 +1,10 @@
|
|||
import type { FeatureMeta, FeatureFilters, ViewState } from '../types';
|
||||
import type { TransportMode, TravelTimeInitial } from '../hooks/useTravelTime';
|
||||
import {
|
||||
TRANSPORT_MODES,
|
||||
type TransportMode,
|
||||
type TravelTimeEntries,
|
||||
type TravelTimeInitial,
|
||||
} from '../hooks/useTravelTime';
|
||||
|
||||
function parseFilters(params: URLSearchParams): FeatureFilters | undefined {
|
||||
const filterParams = params.getAll('filter');
|
||||
|
|
@ -65,26 +70,33 @@ export function parseUrlState(): {
|
|||
result.tab = tab;
|
||||
}
|
||||
|
||||
// Travel time
|
||||
const dest = params.get('dest');
|
||||
if (dest) {
|
||||
const parts = dest.split(',').map(Number);
|
||||
if (parts.length === 2 && parts.every((n) => !isNaN(n))) {
|
||||
const tt: TravelTimeInitial = {
|
||||
destination: [parts[0], parts[1]],
|
||||
destinationLabel: params.get('destLabel') || '',
|
||||
mode: (params.get('tmode') as TransportMode) || 'car',
|
||||
};
|
||||
const ttRange = params.get('tt');
|
||||
if (ttRange) {
|
||||
const [min, max] = ttRange.split(':').map(Number);
|
||||
if (!isNaN(min) && !isNaN(max)) {
|
||||
tt.timeRange = [min, max];
|
||||
// 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];
|
||||
}
|
||||
}
|
||||
entries[mode] = {
|
||||
destination: [parts[0], parts[1]],
|
||||
destinationLabel: label,
|
||||
timeRange,
|
||||
};
|
||||
}
|
||||
result.travelTime = tt;
|
||||
}
|
||||
}
|
||||
if (Object.keys(entries).length > 0) {
|
||||
result.travelTime = { entries };
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
@ -95,7 +107,7 @@ export function stateToParams(
|
|||
features: FeatureMeta[],
|
||||
selectedPOICategories: Set<string>,
|
||||
rightPaneTab: 'properties' | 'area',
|
||||
travelTime?: { enabled: boolean; destination: [number, number] | null; destinationLabel: string; mode: string; timeRange: [number, number] | null }
|
||||
travelTimeEntries?: TravelTimeEntries
|
||||
): URLSearchParams {
|
||||
const params = new URLSearchParams();
|
||||
|
||||
|
|
@ -123,16 +135,18 @@ export function stateToParams(
|
|||
params.set('tab', 'properties');
|
||||
}
|
||||
|
||||
if (travelTime?.enabled && travelTime.destination) {
|
||||
params.set('dest', `${travelTime.destination[0].toFixed(5)},${travelTime.destination[1].toFixed(5)}`);
|
||||
if (travelTime.destinationLabel) {
|
||||
params.set('destLabel', travelTime.destinationLabel);
|
||||
}
|
||||
if (travelTime.mode !== 'car') {
|
||||
params.set('tmode', travelTime.mode);
|
||||
}
|
||||
if (travelTime.timeRange) {
|
||||
params.set('tt', `${travelTime.timeRange[0]}:${travelTime.timeRange[1]}`);
|
||||
// Travel time: per-mode 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);
|
||||
}
|
||||
if (entry.timeRange) {
|
||||
params.set(`ttr_${mode}`, `${entry.timeRange[0]}:${entry.timeRange[1]}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue