2022-12-10 17:31:51 +00:00
|
|
|
import getUri, { intToTrkptId } from '../lib/ids';
|
2022-11-26 18:36:55 +00:00
|
|
|
import { put } from './lib';
|
|
|
|
import { putNewTrkseg } from './trkseg';
|
|
|
|
|
|
|
|
const emptyTrkpt: Wpt = {
|
|
|
|
$: { lat: 0, lon: 0 },
|
|
|
|
ele: undefined,
|
|
|
|
time: undefined,
|
|
|
|
magvar: undefined,
|
|
|
|
geoidheight: undefined,
|
|
|
|
name: undefined,
|
|
|
|
cmt: undefined,
|
|
|
|
desc: undefined,
|
|
|
|
src: undefined,
|
|
|
|
link: undefined,
|
|
|
|
sym: undefined,
|
|
|
|
type: undefined,
|
|
|
|
fix: undefined,
|
|
|
|
sat: undefined,
|
|
|
|
hdop: undefined,
|
|
|
|
vdop: undefined,
|
|
|
|
pdop: undefined,
|
|
|
|
ageofdgpsdata: undefined,
|
|
|
|
dgpsid: undefined,
|
|
|
|
extensions: {
|
|
|
|
'dyo:speed': undefined,
|
|
|
|
'dyo:course': undefined,
|
|
|
|
'dyo:accuracy': undefined,
|
|
|
|
'dyo:batterylevel': undefined,
|
|
|
|
'dyo:useragent': undefined,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
export const putNewTrkpt = async (id?: IdTrk | IdGpx | IdTrkseg | IdTrkpt) => {
|
|
|
|
let finalId = { ...id };
|
|
|
|
if (!('trkpt' in finalId)) {
|
|
|
|
const trksegId = await putNewTrkseg(id);
|
2022-12-10 17:31:51 +00:00
|
|
|
finalId = { ...trksegId, trkpt: intToTrkptId(Date.now()) };
|
2022-11-26 18:36:55 +00:00
|
|
|
}
|
|
|
|
const uri = getUri('trkpt', finalId);
|
|
|
|
await put(
|
|
|
|
uri,
|
|
|
|
'trkpt',
|
|
|
|
(trkpt) => {
|
|
|
|
return trkpt;
|
|
|
|
},
|
|
|
|
emptyTrkpt
|
|
|
|
);
|
|
|
|
return finalId;
|
|
|
|
};
|