Changing Gpx and Trkpt indexes so that GPX are sorted by datetime desc and Trkpt use their timestamp as indexes.
This commit is contained in:
parent
be72adce05
commit
86a8c823f1
|
@ -21,9 +21,9 @@ const GpxImport: Component = () => {
|
|||
'load',
|
||||
() => {
|
||||
// this will then display a text file
|
||||
console.log(fileReader.result);
|
||||
console.log({ caller: 'GpxImport / XML', result: fileReader.result });
|
||||
const gpx = GPX.parse(fileReader.result);
|
||||
console.log(`gpx: ${JSON.stringify(gpx)}`);
|
||||
console.log({ caller: 'GpxImport / JSON', gpx });
|
||||
if (gpx) {
|
||||
const startTime = new Date(findStartTime(gpx)!);
|
||||
dispatch({
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { PureComponent } from 'react';
|
||||
import { Point, Rectangle } from '../components/map/types';
|
||||
import { lat2tile, lon2tile, rectanglesIntersect } from '../lib/geo';
|
||||
import getUri, { intToGpxId } from '../lib/ids';
|
||||
import getUri, { intToGpxId, intToTrkptId } from '../lib/ids';
|
||||
import { get, getDocsByType, getFamily, put, putAll } from './lib';
|
||||
|
||||
const emptyGpx: Gpx = {
|
||||
|
@ -74,7 +74,18 @@ const prune = (id: any, object: any, docs: any[]) => {
|
|||
const subObjects = object[key];
|
||||
for (const index in subObjects) {
|
||||
const subId = { ...id };
|
||||
subId[key] = index;
|
||||
subId[key] =
|
||||
key === 'trkpt'
|
||||
? intToTrkptId(new Date(object[key][index].time).valueOf())
|
||||
: index;
|
||||
// console.log({
|
||||
// caller: 'prune',
|
||||
// id,
|
||||
// subId,
|
||||
// key,
|
||||
// object: object[key][index],
|
||||
// time: object[key][index].time,
|
||||
// });
|
||||
docs.push({
|
||||
_id: getUri(key, subId),
|
||||
type: key,
|
||||
|
@ -177,7 +188,7 @@ export const pruneAndSaveImportedGpx = async (params: any) => {
|
|||
},
|
||||
];
|
||||
prune(id, gpx, docs);
|
||||
console.log(JSON.stringify(docs));
|
||||
console.log({ caller: 'pruneAndSaveImportedGpx / pruned', docs });
|
||||
try {
|
||||
const result = await putAll(docs);
|
||||
console.log(JSON.stringify(result));
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import getUri from '../lib/ids';
|
||||
import getUri, { intToTrkptId } from '../lib/ids';
|
||||
import { put } from './lib';
|
||||
import { putNewTrkseg } from './trkseg';
|
||||
|
||||
|
@ -35,7 +35,7 @@ export const putNewTrkpt = async (id?: IdTrk | IdGpx | IdTrkseg | IdTrkpt) => {
|
|||
let finalId = { ...id };
|
||||
if (!('trkpt' in finalId)) {
|
||||
const trksegId = await putNewTrkseg(id);
|
||||
finalId = { ...trksegId, trkpt: 0 };
|
||||
finalId = { ...trksegId, trkpt: intToTrkptId(Date.now()) };
|
||||
}
|
||||
const uri = getUri('trkpt', finalId);
|
||||
await put(
|
||||
|
|
|
@ -21,7 +21,7 @@ const coding = {
|
|||
rtept: integerType(6),
|
||||
trk: integerType(6),
|
||||
trkseg: integerType(6),
|
||||
trkpt: integerType(6),
|
||||
trkpt: integerType(16),
|
||||
};
|
||||
|
||||
const routes = {
|
||||
|
@ -47,5 +47,9 @@ export default uri;
|
|||
|
||||
const minDate = -8640000000000000;
|
||||
const halfMinDate = minDate / 2;
|
||||
const maxDate = 8640000000000000;
|
||||
const halfMaxDate = maxDate / 2;
|
||||
|
||||
export const intToGpxId = (i: number) => Math.round(i / 2) - halfMinDate;
|
||||
export const intToGpxId = (i: number) => halfMaxDate - Math.round(i / 2);
|
||||
|
||||
export const intToTrkptId = (i: number) => Math.round(i / 2) - halfMinDate;
|
||||
|
|
Loading…
Reference in New Issue