more file formats && list add in edit
This commit is contained in:
@@ -47,6 +47,7 @@
|
||||
"entry": "Eintrag",
|
||||
"error-creating-user": "Fehler beim Erstellen des Nutzers",
|
||||
"error-during-login": "Fehler beim Login",
|
||||
"error-reading-file": "",
|
||||
"est-duration": "Gesch. Dauer",
|
||||
"explore": "Erkunden",
|
||||
"explore-some-trails": "Erkunden Sie einige Routen",
|
||||
|
||||
@@ -47,6 +47,7 @@
|
||||
"entry": "Entry",
|
||||
"error-creating-user": "Error creating user",
|
||||
"error-during-login": "Error during login",
|
||||
"error-reading-file": "Error reading file",
|
||||
"est-duration": "Est. duration",
|
||||
"explore": "Explore",
|
||||
"explore-some-trails": "Explore some trails",
|
||||
|
||||
@@ -47,6 +47,7 @@
|
||||
"entry": "Item",
|
||||
"error-creating-user": "Fout bij het aanmaken van de gebruiker",
|
||||
"error-during-login": "Fout bij het inloggen",
|
||||
"error-reading-file": "",
|
||||
"est-duration": "Geschatte duur",
|
||||
"explore": "Verkennen",
|
||||
"explore-some-trails": "Verken enkele routes",
|
||||
|
||||
@@ -47,6 +47,7 @@
|
||||
"entry": "Pozycja",
|
||||
"error-creating-user": "Błąd tworzenia użytkownika",
|
||||
"error-during-login": "Błąd podczas logowania",
|
||||
"error-reading-file": "",
|
||||
"est-duration": "Szacowany czas",
|
||||
"explore": "Eksploruj",
|
||||
"explore-some-trails": "Eksploruj różne ścieżki",
|
||||
|
||||
@@ -47,6 +47,7 @@
|
||||
"entry": "Entrada",
|
||||
"error-creating-user": "Erro ao criar usuário",
|
||||
"error-during-login": "Erro durante o login",
|
||||
"error-reading-file": "",
|
||||
"est-duration": "Duração prevista",
|
||||
"explore": "Explorar",
|
||||
"explore-some-trails": "Explore algumas trilhas",
|
||||
|
||||
@@ -5,7 +5,7 @@ import { ClientResponseError } from "pocketbase";
|
||||
|
||||
export const categories: Writable<Category[]> = writable([])
|
||||
|
||||
export async function categories_index(f: Function = fetch) {
|
||||
export async function categories_index(f: (url: RequestInfo | URL, config?: RequestInit) => Promise<Response> = fetch) {
|
||||
const r = await f('/api/v1/category', {
|
||||
method: 'GET',
|
||||
})
|
||||
|
||||
@@ -167,7 +167,7 @@ export async function trails_search_bounding_box(northEast: LatLng, southWest: L
|
||||
|
||||
export async function trails_show(id: string, loadGPX?: boolean, f: (url: RequestInfo | URL, config?: RequestInit) => Promise<Response> = fetch) {
|
||||
const r = await f(`/api/v1/trail/${id}?` + new URLSearchParams({
|
||||
expand: "category,waypoints,summit_logs",
|
||||
expand: "category,waypoints,summit_logs,lists_via_trails",
|
||||
}), {
|
||||
method: 'GET',
|
||||
})
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
import { Trail } from "$lib/models/trail";
|
||||
import { Waypoint } from "$lib/models/waypoint";
|
||||
import { JSDOM } from "jsdom"
|
||||
import { kml, tcx } from "$lib/vendor/toGeoJSON/toGeoJSON"
|
||||
import GeoJsonToGpx from "$lib/vendor/geoJSONToGPX"
|
||||
|
||||
export function gpx2trail(gpx: string) {
|
||||
export async function gpx2trail(gpx: string) {
|
||||
const JSDOM = (await import("jsdom")).JSDOM
|
||||
const xml = new JSDOM(gpx).window.document
|
||||
const trail = new Trail("");
|
||||
|
||||
@@ -15,7 +17,7 @@ export function gpx2trail(gpx: string) {
|
||||
trail.description = desc[0].textContent ?? "";
|
||||
}
|
||||
|
||||
const el = xml.getElementsByTagName('wpt');
|
||||
const el = xml.getElementsByTagName('wpt');
|
||||
for (let i = 0; i < el.length; i++) {
|
||||
const wp = new Waypoint(parseFloat(el[i].getAttribute('lat')!), parseFloat(el[i].getAttribute('lon')!));
|
||||
|
||||
@@ -29,10 +31,45 @@ export function gpx2trail(gpx: string) {
|
||||
}
|
||||
|
||||
const startPoint = xml.getElementsByTagName("trk")[0].getElementsByTagName("trkseg")[0].getElementsByTagName("trkpt")[0];
|
||||
if(startPoint) {
|
||||
if (startPoint) {
|
||||
trail.lat = parseFloat(startPoint.getAttribute('lat')!)
|
||||
trail.lon = parseFloat(startPoint.getAttribute('lon')!)
|
||||
}
|
||||
}
|
||||
|
||||
return trail
|
||||
}
|
||||
|
||||
export function fromKML(kmlData: string) {
|
||||
const geojson = kml(new DOMParser().parseFromString(kmlData, "text/xml"))
|
||||
const options = {
|
||||
metadata: {
|
||||
name: '',
|
||||
author: {
|
||||
name: '',
|
||||
link: {
|
||||
href: ''
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
const gpx = GeoJsonToGpx(geojson as any, options)
|
||||
|
||||
return new XMLSerializer().serializeToString(gpx)
|
||||
}
|
||||
|
||||
export function fromTCX(tcxData: string) {
|
||||
const geojson = tcx(new DOMParser().parseFromString(tcxData, "text/xml"))
|
||||
const options = {
|
||||
metadata: {
|
||||
name: '',
|
||||
author: {
|
||||
name: '',
|
||||
link: {
|
||||
href: ''
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
const gpx = GeoJsonToGpx(geojson as any, options)
|
||||
return new XMLSerializer().serializeToString(gpx)
|
||||
}
|
||||
39
web/src/lib/vendor/geoJSONToGPX/index.d.ts
vendored
Normal file
39
web/src/lib/vendor/geoJSONToGPX/index.d.ts
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
import { Feature, FeatureCollection } from 'geojson';
|
||||
declare interface Bounds {
|
||||
minlat: string;
|
||||
minlon: string;
|
||||
maxlat: string;
|
||||
maxlon: string;
|
||||
}
|
||||
declare interface Copyright {
|
||||
author?: string;
|
||||
year?: string;
|
||||
license?: string;
|
||||
}
|
||||
declare interface Link {
|
||||
href: string;
|
||||
text?: string;
|
||||
type?: string;
|
||||
}
|
||||
declare interface Person {
|
||||
name?: string;
|
||||
email?: string;
|
||||
link?: Link;
|
||||
}
|
||||
declare interface MetaData {
|
||||
name?: string;
|
||||
desc?: string;
|
||||
author?: Person;
|
||||
copyright?: Copyright;
|
||||
link?: Link;
|
||||
time?: string;
|
||||
keywords?: string;
|
||||
bounds?: Bounds;
|
||||
}
|
||||
export declare interface Options {
|
||||
creator?: string;
|
||||
version?: string;
|
||||
metadata?: MetaData;
|
||||
}
|
||||
export default function GeoJsonToGpx(geoJson: Feature | FeatureCollection, options?: Options, implementation?: DOMImplementation): XMLDocument;
|
||||
export {};
|
||||
155
web/src/lib/vendor/geoJSONToGPX/index.js
vendored
Normal file
155
web/src/lib/vendor/geoJSONToGPX/index.js
vendored
Normal file
@@ -0,0 +1,155 @@
|
||||
export default function GeoJsonToGpx(geoJson, options, implementation) {
|
||||
if (implementation === void 0) { implementation = document.implementation; }
|
||||
var doc = implementation.createDocument('http://www.topografix.com/GPX/1/1', '');
|
||||
var instruct = doc.createProcessingInstruction('xml', 'version="1.0" encoding="UTF-8"');
|
||||
doc.appendChild(instruct);
|
||||
var defaultPackageName = '@dwayneparton/geojson-to-gpx';
|
||||
var creator = (options === null || options === void 0 ? void 0 : options.creator) || defaultPackageName;
|
||||
var createElementWithNS = function (tagName) {
|
||||
return doc.createElementNS('http://www.topografix.com/GPX/1/1', tagName);
|
||||
};
|
||||
var gpx = createElementWithNS('gpx');
|
||||
gpx.setAttribute('version', '1.1');
|
||||
gpx.setAttribute('creator', creator);
|
||||
var wpts = [];
|
||||
var trks = [];
|
||||
function createTagInParentElement(parent, tagName, content) {
|
||||
if (content === undefined) {
|
||||
return;
|
||||
}
|
||||
var element = createElementWithNS(tagName);
|
||||
var contentEl = doc.createTextNode(String(content));
|
||||
element.appendChild(contentEl);
|
||||
parent.appendChild(element);
|
||||
}
|
||||
function addSupportedPropertiesFromObject(el, supports, properties) {
|
||||
if (properties && typeof properties === 'object') {
|
||||
supports.forEach(function (key) {
|
||||
var value = properties[key];
|
||||
if (value && typeof value === 'string' && supports.includes(key)) {
|
||||
createTagInParentElement(el, key, value);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
function createLinkInParentElement(parent, props) {
|
||||
var href = props.href;
|
||||
if (!href) {
|
||||
return;
|
||||
}
|
||||
var el = createElementWithNS('link');
|
||||
el.setAttribute('href', href);
|
||||
addSupportedPropertiesFromObject(el, ['text', 'type'], props);
|
||||
parent.appendChild(el);
|
||||
}
|
||||
function createTrk(properties) {
|
||||
var el = createElementWithNS('trk');
|
||||
var supports = ['name', 'desc', 'src', 'type'];
|
||||
addSupportedPropertiesFromObject(el, supports, properties);
|
||||
return el;
|
||||
}
|
||||
function createPt(type, position, properties) {
|
||||
var lon = position[0], lat = position[1], ele = position[2], time = position[3];
|
||||
var el = createElementWithNS(type);
|
||||
el.setAttribute('lat', String(lat));
|
||||
el.setAttribute('lon', String(lon));
|
||||
createTagInParentElement(el, 'ele', ele);
|
||||
createTagInParentElement(el, 'time', time);
|
||||
var supports = ['name', 'desc', 'src', 'type'];
|
||||
addSupportedPropertiesFromObject(el, supports, properties);
|
||||
return el;
|
||||
}
|
||||
function createTrkSeg(coordinates) {
|
||||
var el = createElementWithNS('trkseg');
|
||||
coordinates.forEach(function (point) {
|
||||
el.appendChild(createPt('trkpt', point));
|
||||
});
|
||||
return el;
|
||||
}
|
||||
function interpretFeature(feature) {
|
||||
var geometry = feature.geometry, properties = feature.properties;
|
||||
var type = geometry.type;
|
||||
switch (type) {
|
||||
case 'Polygon':
|
||||
break;
|
||||
case 'Point': {
|
||||
wpts.push(createPt('wpt', geometry.coordinates, properties));
|
||||
break;
|
||||
}
|
||||
case 'MultiPoint': {
|
||||
geometry.coordinates.forEach(function (coord) {
|
||||
wpts.push(createPt('wpt', coord, properties));
|
||||
});
|
||||
break;
|
||||
}
|
||||
case 'LineString': {
|
||||
var lineTrk = createTrk(properties);
|
||||
var trkseg = createTrkSeg(geometry.coordinates);
|
||||
lineTrk.appendChild(trkseg);
|
||||
trks.push(lineTrk);
|
||||
break;
|
||||
}
|
||||
case 'MultiLineString': {
|
||||
var trk_1 = createTrk(properties);
|
||||
geometry.coordinates.forEach(function (pos) {
|
||||
var trkseg = createTrkSeg(pos);
|
||||
trk_1.appendChild(trkseg);
|
||||
});
|
||||
trks.push(trk_1);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (options && typeof options.metadata === 'object') {
|
||||
var meta = options.metadata;
|
||||
var metadata = createElementWithNS('metadata');
|
||||
createTagInParentElement(metadata, 'name', meta.name);
|
||||
createTagInParentElement(metadata, 'desc', meta.desc);
|
||||
if (meta.author && typeof meta.author === 'object') {
|
||||
var author = createElementWithNS('author');
|
||||
createTagInParentElement(author, 'name', meta.author.name);
|
||||
createTagInParentElement(author, 'email', meta.author.email);
|
||||
if (meta.author.link && typeof meta.author.link === 'object') {
|
||||
createLinkInParentElement(author, meta.author.link);
|
||||
}
|
||||
metadata.appendChild(author);
|
||||
}
|
||||
if (typeof meta.copyright === 'object') {
|
||||
var copyright = createElementWithNS('copyright');
|
||||
if (meta.copyright.author) {
|
||||
copyright.setAttribute('author', meta.copyright.author);
|
||||
}
|
||||
createTagInParentElement(copyright, 'year', meta.copyright.year);
|
||||
createTagInParentElement(copyright, 'license', meta.copyright.license);
|
||||
metadata.appendChild(copyright);
|
||||
}
|
||||
if (typeof meta.link === 'object') {
|
||||
createLinkInParentElement(metadata, meta.link);
|
||||
}
|
||||
createTagInParentElement(metadata, 'time', meta.time);
|
||||
createTagInParentElement(metadata, 'keywords', meta.keywords);
|
||||
gpx.appendChild(metadata);
|
||||
}
|
||||
var type = geoJson.type;
|
||||
switch (type) {
|
||||
case 'Feature': {
|
||||
interpretFeature(geoJson);
|
||||
break;
|
||||
}
|
||||
case 'FeatureCollection': {
|
||||
var features = geoJson.features;
|
||||
features.forEach(function (feature) {
|
||||
interpretFeature(feature);
|
||||
});
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
wpts.forEach(function (wpt) { return gpx.appendChild(wpt); });
|
||||
trks.forEach(function (trk) { return gpx.appendChild(trk); });
|
||||
doc.appendChild(gpx);
|
||||
return doc;
|
||||
}
|
||||
1157
web/src/lib/vendor/toGeoJSON/toGeoJSON.js
vendored
Normal file
1157
web/src/lib/vendor/toGeoJSON/toGeoJSON.js
vendored
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user