correct elevation for summit logs
This commit is contained in:
@@ -90,9 +90,13 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const gpxObject = GPX.parse(trailData);
|
const gpxObject = GPX.parse(trailData);
|
||||||
|
try {
|
||||||
const totals = gpxObject.features;
|
await gpxObject.correctElevation();
|
||||||
|
} catch (e) {
|
||||||
|
console.warn("Unable to correct elevation: " + e);
|
||||||
|
}
|
||||||
|
|
||||||
|
const totals = gpxObject.features;
|
||||||
$data.duration = totals.duration / 1000;
|
$data.duration = totals.duration / 1000;
|
||||||
$data.elevation_gain = totals.elevationGain;
|
$data.elevation_gain = totals.elevationGain;
|
||||||
$data.elevation_loss = totals.elevationLoss;
|
$data.elevation_loss = totals.elevationLoss;
|
||||||
|
|||||||
@@ -58,7 +58,7 @@
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
trail = gpx2trail(log.expand.gpx_data!).trail;
|
trail = (await gpx2trail(log.expand.gpx_data!)).trail;
|
||||||
trail.id = log.id;
|
trail.id = log.id;
|
||||||
trail.expand!.gpx_data = log.expand.gpx_data;
|
trail.expand!.gpx_data = log.expand.gpx_data;
|
||||||
|
|
||||||
|
|||||||
@@ -10,9 +10,7 @@ import geohash from "ngeohash"
|
|||||||
import { encodePolyline } from '$lib/util/polyline_util';
|
import { encodePolyline } from '$lib/util/polyline_util';
|
||||||
import { APIError } from '$lib/util/api_util';
|
import { APIError } from '$lib/util/api_util';
|
||||||
import type { ValhallaHeightResponse } from '../valhalla';
|
import type { ValhallaHeightResponse } from '../valhalla';
|
||||||
import { bbox, splitMultiLineStringToLineStrings } from '$lib/util/geojson_util';
|
import { bbox } from '$lib/util/geojson_util';
|
||||||
import { browser } from '$app/environment';
|
|
||||||
import xmldom from 'xmldom';
|
|
||||||
|
|
||||||
const defaultAttributes = {
|
const defaultAttributes = {
|
||||||
version: '1.1',
|
version: '1.1',
|
||||||
|
|||||||
@@ -18,18 +18,21 @@ import { handleFromRecordWithIRI } from "./activitypub_util";
|
|||||||
import { Waypoint } from "$lib/models/waypoint";
|
import { Waypoint } from "$lib/models/waypoint";
|
||||||
|
|
||||||
|
|
||||||
export function gpx2trail(gpxString: string, fallbackName?: string, f: (url: RequestInfo | URL, config?: RequestInit) => Promise<Response> = fetch) {
|
export async function gpx2trail(gpxString: string, fallbackName?: string, correctElevation: boolean = false, f: (url: RequestInfo | URL, config?: RequestInit) => Promise<Response> = fetch) {
|
||||||
|
|
||||||
const gpx = GPX.parse(gpxString);
|
const gpx = GPX.parse(gpxString);
|
||||||
|
|
||||||
if (gpx instanceof Error) {
|
if (gpx instanceof Error) {
|
||||||
throw gpx;
|
throw gpx;
|
||||||
}
|
}
|
||||||
// try {
|
if (correctElevation) {
|
||||||
// await gpx.correctElevation(f)
|
try {
|
||||||
// } catch(e) {
|
await gpx.correctElevation(f)
|
||||||
// console.warn("Unable to correct elevation: " + e)
|
} catch (e) {
|
||||||
// }
|
console.warn("Unable to correct elevation: " + e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
const trail = new Trail("");
|
const trail = new Trail("");
|
||||||
|
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ export async function PUT(event: RequestEvent) {
|
|||||||
}
|
}
|
||||||
let parseResult: { trail: Trail, gpx: GPX };
|
let parseResult: { trail: Trail, gpx: GPX };
|
||||||
try {
|
try {
|
||||||
parseResult = gpx2trail(gpxData, data.get("name") as string | undefined, event.fetch);
|
parseResult = await gpx2trail(gpxData, data.get("name") as string | undefined, true, event.fetch);
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(e)
|
console.error(e)
|
||||||
throw new ClientResponseError({ status: 400, response: { message: "Invalid file" } })
|
throw new ClientResponseError({ status: 400, response: { message: "Invalid file" } })
|
||||||
|
|||||||
@@ -319,7 +319,7 @@
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const prevId = $formData.id;
|
const prevId = $formData.id;
|
||||||
const parseResult = gpx2trail(gpxData, selectedFile.name);
|
const parseResult = await gpx2trail(gpxData, selectedFile.name);
|
||||||
setFields(parseResult.trail);
|
setFields(parseResult.trail);
|
||||||
$formData.id = prevId ?? cryptoRandomString({ length: 15 });
|
$formData.id = prevId ?? cryptoRandomString({ length: 15 });
|
||||||
$formData.expand!.gpx_data = gpxData;
|
$formData.expand!.gpx_data = gpxData;
|
||||||
|
|||||||
Reference in New Issue
Block a user