adds italian && fit support
This commit is contained in:
@@ -9,12 +9,12 @@
|
||||
import "leaflet/dist/leaflet.css";
|
||||
import { createEventDispatcher, onMount } from "svelte";
|
||||
import { _ } from "svelte-i18n";
|
||||
import Dropdown, { type DropdownItem } from "../base/dropdown.svelte";
|
||||
import Dropdown from "../base/dropdown.svelte";
|
||||
|
||||
export let trail: Trail | null;
|
||||
export let markers: Marker[] = [];
|
||||
export let map: Map | null = null;
|
||||
export let options = {};
|
||||
export let options: any = {};
|
||||
export let graticule: AutoGraticule | null = null;
|
||||
export let crosshair: boolean = false;
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
$: gpxData = trail?.expand.gpx_data;
|
||||
$: if (gpxData && controlElevation) {
|
||||
controlElevation.updateOptions({
|
||||
autofitBounds: true,
|
||||
autofitBounds: options.autofitBounds ?? true,
|
||||
});
|
||||
controlElevation.clear();
|
||||
controlElevation.load(gpxData);
|
||||
|
||||
@@ -9,6 +9,7 @@ register('en', () => import('./locales/en.json'))
|
||||
register('de', () => import('./locales/de.json'))
|
||||
register('fr', () => import('./locales/fr.json'))
|
||||
register('hu', () => import('./locales/hu.json'))
|
||||
register('it', () => import('./locales/it.json'))
|
||||
register('nl', () => import('./locales/nl.json'))
|
||||
register('pl', () => import('./locales/pl.json'))
|
||||
register('pt', () => import('./locales/pt.json'))
|
||||
|
||||
@@ -2,14 +2,14 @@
|
||||
class Settings {
|
||||
id?: string;
|
||||
unit?: "metric" | "imperial";
|
||||
language?: "en" | "de" | "fr" | "hu" | "nl" | "pl" | "pt" | "zh";
|
||||
language?: "en" | "de" | "fr" | "hu"| "it" | "nl" | "pl" | "pt" | "zh";
|
||||
mapFocus?: "trails" | "location";
|
||||
location?: { name: string, lat: number, lon: number };
|
||||
user?: string;
|
||||
|
||||
constructor(
|
||||
unit: "metric" | "imperial",
|
||||
language: "en" | "de" | "fr" | "hu" | "nl" | "pl" | "pt" | "zh",
|
||||
language: "en" | "de" | "fr" | "hu"| "it" | "nl" | "pl" | "pt" | "zh",
|
||||
mapFocus: "trails" | "location",
|
||||
user: string,
|
||||
params?: {
|
||||
|
||||
@@ -1,11 +1,16 @@
|
||||
import GPX from "$lib/models/gpx/gpx";
|
||||
import { Trail } from "$lib/models/trail";
|
||||
import { Waypoint } from "$lib/models/waypoint";
|
||||
import { Waypoint, waypointSchema } from "$lib/models/waypoint";
|
||||
import { currentUser } from "$lib/stores/user_store";
|
||||
import GeoJsonToGpx from "$lib/vendor/geoJSONToGPX";
|
||||
import { kml, tcx } from "$lib/vendor/toGeoJSON/toGeoJSON";
|
||||
import cryptoRandomString from "crypto-random-string";
|
||||
import { get } from "svelte/store";
|
||||
//@ts-ignore
|
||||
import EasyFit from "easy-fit"
|
||||
import Track from "$lib/models/gpx/track";
|
||||
import TrackSegment from "$lib/models/gpx/track-segment";
|
||||
import GPXWaypoint from "$lib/models/gpx/waypoint";
|
||||
|
||||
export async function gpx2trail(gpxString: string) {
|
||||
const gpx = await GPX.parse(gpxString);
|
||||
@@ -16,7 +21,7 @@ export async function gpx2trail(gpxString: string) {
|
||||
|
||||
const trail = new Trail("");
|
||||
|
||||
trail.name = gpx.metadata?.name || gpx.trk?.at(0)?.name || gpx.rte?.at(0)?.name || `trail-${new Date().toISOString()}`;
|
||||
trail.name = gpx.metadata?.name || gpx.trk?.at(0)?.name || gpx.rte?.at(0)?.name || `trail-${new Date().toISOString()}`;
|
||||
|
||||
trail.description = gpx.metadata?.desc;
|
||||
|
||||
@@ -72,13 +77,13 @@ export async function trail2gpx(trail: Trail) {
|
||||
author: { name: trail.author ?? "", email: get(currentUser)?.email ?? "" }
|
||||
}
|
||||
|
||||
if(!gpx.wpt) {
|
||||
if (!gpx.wpt) {
|
||||
gpx.wpt = [];
|
||||
}
|
||||
|
||||
for (const wp of trail.expand.waypoints) {
|
||||
const gpxWpt = gpx.wpt.find((w) => w.$.lat == wp.lat && w.$.lon == wp.lon)
|
||||
if(!gpxWpt) {
|
||||
if (!gpxWpt) {
|
||||
gpx.wpt.push({
|
||||
$: {
|
||||
lat: wp.lat,
|
||||
@@ -124,4 +129,43 @@ export function fromTCX(tcxData: string) {
|
||||
}
|
||||
const gpx = GeoJsonToGpx(geojson as any, options)
|
||||
return new XMLSerializer().serializeToString(gpx)
|
||||
}
|
||||
|
||||
export async function fromFIT(fitData: ArrayBuffer) {
|
||||
const easyFit = new EasyFit({
|
||||
});
|
||||
return new Promise<string>((resolve, reject) => easyFit.parse(fitData, function (error: string, data: any) {
|
||||
|
||||
if (error) {
|
||||
console.log(error);
|
||||
reject(error)
|
||||
}
|
||||
console.log(data);
|
||||
|
||||
const gpx = new GPX({
|
||||
metadata: {
|
||||
name: "",
|
||||
desc: "",
|
||||
time: data.activity?.timestamp ?? new Date(),
|
||||
keywords: "wanderer"
|
||||
},
|
||||
trk: [
|
||||
new Track({
|
||||
trkseg: new TrackSegment({
|
||||
trkpt: data.records.flatMap((d => {
|
||||
return (d.position_lat && d.position_long) ? new GPXWaypoint({
|
||||
$: { lat: d.position_lat, lon: d.position_long },
|
||||
time: d.timestamp,
|
||||
ele: d.altitude
|
||||
|
||||
}) : []
|
||||
}))
|
||||
})
|
||||
})
|
||||
]
|
||||
});
|
||||
console.log(gpx);
|
||||
|
||||
resolve(gpx.toString());
|
||||
}));
|
||||
}
|
||||
Reference in New Issue
Block a user