Adding adresses to rtept rather than rte.
This commit is contained in:
parent
2ca519a53c
commit
e7b27cda4e
|
@ -50,23 +50,21 @@ const RteViewer: Component<Props> = ({ rteId }) => {
|
||||||
rte().rtept.map((rtept: any) => [rtept.$.lon, rtept.$.lat])
|
rte().rtept.map((rtept: any) => [rtept.$.lon, rtept.$.lat])
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const firstRtept = rte().rtept.at(0);
|
||||||
|
const lastRtept = rte().rtept.at(-1);
|
||||||
|
|
||||||
const length = getLength(geometry, { projection: 'EPSG:4326' });
|
const length = getLength(geometry, { projection: 'EPSG:4326' });
|
||||||
|
|
||||||
const findClickHandlerFactory = (target: string) => async () => {
|
const findClickHandlerFactory = (rtept: any) => async () => {
|
||||||
const index = target === 'from' ? 0 : -1;
|
const address = await findAddress(rtept.$.lon, rtept.$.lat, locale);
|
||||||
const address = await findAddress(
|
const updatedRtept = cloneDeep(rtept);
|
||||||
rte().rtept.at(index).$.lon,
|
if (updatedRtept.extensions === undefined) {
|
||||||
rte().rtept.at(index).$.lat,
|
updatedRtept.extensions = {};
|
||||||
locale
|
|
||||||
);
|
|
||||||
const updatedRte = cloneDeep(rte());
|
|
||||||
if (updatedRte.extensions === undefined) {
|
|
||||||
updatedRte.extensions = {};
|
|
||||||
}
|
}
|
||||||
updatedRte.extensions[target] = address;
|
updatedRtept.extensions.address = address;
|
||||||
dispatch({
|
dispatch({
|
||||||
action: 'putRte',
|
action: 'putRtept',
|
||||||
params: { id: rteId, rte: updatedRte },
|
params: { id: rtept.id, rtept: updatedRtept },
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -82,24 +80,28 @@ const RteViewer: Component<Props> = ({ rteId }) => {
|
||||||
<div>
|
<div>
|
||||||
{formatLength(length)} {t('from')}{' '}
|
{formatLength(length)} {t('from')}{' '}
|
||||||
<Show
|
<Show
|
||||||
when={!rte()?.extensions?.from}
|
when={!rte().rtept.at(0).extensions?.address}
|
||||||
fallback={<>{getVillageOrTown(rte()?.extensions?.from)}</>}
|
fallback={
|
||||||
|
<>{getVillageOrTown(rte().rtept.at(0).extensions?.address)}</>
|
||||||
|
}
|
||||||
>
|
>
|
||||||
<IconButton
|
<IconButton
|
||||||
color='primary'
|
color='primary'
|
||||||
onClick={findClickHandlerFactory('from')}
|
onClick={findClickHandlerFactory(rte().rtept.at(0))}
|
||||||
>
|
>
|
||||||
<SearchIcon />
|
<SearchIcon />
|
||||||
</IconButton>
|
</IconButton>
|
||||||
</Show>{' '}
|
</Show>{' '}
|
||||||
{t('to')}{' '}
|
{t('to')}{' '}
|
||||||
<Show
|
<Show
|
||||||
when={!rte()?.extensions?.to}
|
when={!rte().rtept.at(-1).extensions?.address}
|
||||||
fallback={<>{getVillageOrTown(rte()?.extensions?.to)}</>}
|
fallback={
|
||||||
|
<>{getVillageOrTown(rte().rtept.at(-1).extensions?.address)}</>
|
||||||
|
}
|
||||||
>
|
>
|
||||||
<IconButton
|
<IconButton
|
||||||
color='primary'
|
color='primary'
|
||||||
onClick={findClickHandlerFactory('to')}
|
onClick={findClickHandlerFactory(rte().rtept.at(-1))}
|
||||||
>
|
>
|
||||||
<SearchIcon />
|
<SearchIcon />
|
||||||
</IconButton>
|
</IconButton>
|
||||||
|
|
|
@ -46,6 +46,7 @@ export const getRte = async (params: any) => {
|
||||||
//level 1
|
//level 1
|
||||||
if (row.doc.type === 'rtept') {
|
if (row.doc.type === 'rtept') {
|
||||||
target.splice(1);
|
target.splice(1);
|
||||||
|
row.doc.doc.id = row.doc._id;
|
||||||
appendToArray(target.at(-1), row.doc.type, row.doc.doc);
|
appendToArray(target.at(-1), row.doc.type, row.doc.doc);
|
||||||
target.push(row.doc.doc);
|
target.push(row.doc.doc);
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,3 +42,10 @@ export const putNewRtept = async (id?: IdGpx | IdRte | IdRtept) => {
|
||||||
);
|
);
|
||||||
return finalId as IdRtept;
|
return finalId as IdRtept;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const putRtept = async (params: any) => {
|
||||||
|
const { id, rtept } = params;
|
||||||
|
rtept.id = undefined;
|
||||||
|
await put(id, 'rtept', (doc) => rtept, rtept);
|
||||||
|
return rtept;
|
||||||
|
};
|
||||||
|
|
|
@ -49,6 +49,7 @@ interface Extensions {
|
||||||
'dyo:batterylevel'?: number;
|
'dyo:batterylevel'?: number;
|
||||||
'dyo:useragent'?: string;
|
'dyo:useragent'?: string;
|
||||||
'dyo:minZoom'?: number;
|
'dyo:minZoom'?: number;
|
||||||
|
address: any;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Trk {
|
interface Trk {
|
||||||
|
|
|
@ -13,6 +13,7 @@ import {
|
||||||
getAllGpxesWithSummary,
|
getAllGpxesWithSummary,
|
||||||
} from '../db/gpx';
|
} from '../db/gpx';
|
||||||
import { putRte } from '../db/rte';
|
import { putRte } from '../db/rte';
|
||||||
|
import { putRtept } from '../db/rtept';
|
||||||
import { getSettings, putSettings } from '../db/settings';
|
import { getSettings, putSettings } from '../db/settings';
|
||||||
import { getState, setState } from '../db/state';
|
import { getState, setState } from '../db/state';
|
||||||
import { getTrk, putNewTrk } from '../db/trk';
|
import { getTrk, putNewTrk } from '../db/trk';
|
||||||
|
@ -49,7 +50,8 @@ onmessage = async function (e) {
|
||||||
|
|
||||||
putWpt,
|
putWpt,
|
||||||
putRte,
|
putRte,
|
||||||
|
putRtept,
|
||||||
|
|
||||||
getState,
|
getState,
|
||||||
setState,
|
setState,
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue