new Waypoint({ $: { lat: p[0], lon: p[1] }, ele: heightResponse.height[i] }))
return waypoints
@@ -62,49 +82,4 @@ export async function editRoute(index: number, waypoints: Waypoint[]) {
export function deleteFromRoute(index: number) {
route.trk?.at(0)?.trkseg?.splice(index, 1);
-}
-
-
-function decodeShape(shape: string, precision: number = 6) {
- var index = 0,
- lat = 0,
- lng = 0,
- coordinates = [],
- shift = 0,
- result = 0,
- byte = null,
- latitude_change,
- longitude_change,
- factor = Math.pow(10, precision);
-
- while (index < shape.length) {
- byte = null;
- shift = 0;
- result = 0;
-
- do {
- byte = shape.charCodeAt(index++) - 63;
- result |= (byte & 0x1f) << shift;
- shift += 5;
- } while (byte >= 0x20);
-
- latitude_change = ((result & 1) ? ~(result >> 1) : (result >> 1));
-
- shift = result = 0;
-
- do {
- byte = shape.charCodeAt(index++) - 63;
- result |= (byte & 0x1f) << shift;
- shift += 5;
- } while (byte >= 0x20);
-
- longitude_change = ((result & 1) ? ~(result >> 1) : (result >> 1));
-
- lat += latitude_change;
- lng += longitude_change;
-
- coordinates.push([lat / factor, lng / factor]);
- }
-
- return coordinates;
-};
\ No newline at end of file
+}
\ No newline at end of file
diff --git a/web/src/lib/util/gpx_util.ts b/web/src/lib/util/gpx_util.ts
index 7e378ec7..c26b0b4c 100644
--- a/web/src/lib/util/gpx_util.ts
+++ b/web/src/lib/util/gpx_util.ts
@@ -29,7 +29,7 @@ export async function gpx2trail(gpxString: string) {
const totals = gpx.getTotals()
const points = gpx.trk?.at(0)?.trkseg?.at(0)?.trkpt
- const startPoint = points?.at(0);
+ const startPoint = points?.at(0);
if (startPoint) {
trail.lat = startPoint.$.lat
trail.lon = startPoint.$.lon
diff --git a/web/src/lib/util/polyline_util.ts b/web/src/lib/util/polyline_util.ts
new file mode 100644
index 00000000..c16b34f4
--- /dev/null
+++ b/web/src/lib/util/polyline_util.ts
@@ -0,0 +1,80 @@
+function py2_round(value: number) {
+ return Math.floor(Math.abs(value) + 0.5) * (value >= 0 ? 1 : -1);
+}
+
+function encode(current: number, previous: number, factor: number) {
+ current = py2_round(current * factor);
+ previous = py2_round(previous * factor);
+ var coordinate = (current - previous) * 2;
+ if (coordinate < 0) {
+ coordinate = -coordinate - 1
+ }
+ var output = '';
+ while (coordinate >= 0x20) {
+ output += String.fromCharCode((0x20 | (coordinate & 0x1f)) + 63);
+ coordinate /= 32;
+ }
+ output += String.fromCharCode((coordinate | 0) + 63);
+ return output;
+}
+
+
+export function decodePolyline(str: string, precision: number = 6) {
+ var index = 0,
+ lat = 0,
+ lng = 0,
+ coordinates = [],
+ shift = 0,
+ result = 0,
+ byte = null,
+ latitude_change,
+ longitude_change,
+ factor = Math.pow(10, precision);
+
+ while (index < str.length) {
+ byte = null;
+ shift = 0;
+ result = 0;
+
+ do {
+ byte = str.charCodeAt(index++) - 63;
+ result |= (byte & 0x1f) << shift;
+ shift += 5;
+ } while (byte >= 0x20);
+
+ latitude_change = ((result & 1) ? ~(result >> 1) : (result >> 1));
+
+ shift = result = 0;
+
+ do {
+ byte = str.charCodeAt(index++) - 63;
+ result |= (byte & 0x1f) << shift;
+ shift += 5;
+ } while (byte >= 0x20);
+
+ longitude_change = ((result & 1) ? ~(result >> 1) : (result >> 1));
+
+ lat += latitude_change;
+ lng += longitude_change;
+
+ coordinates.push([lat / factor, lng / factor]);
+ }
+
+ return coordinates;
+};
+
+
+export function encodePolyline(coordinates: number[][], precision: number = 6) {
+ if (!coordinates.length) { return ''; }
+
+ var factor = Math.pow(10, precision),
+ output = encode(coordinates[0][0], 0, factor) + encode(coordinates[0][1], 0, factor);
+
+ for (var i = 1; i < coordinates.length; i++) {
+ var a = coordinates[i], b = coordinates[i - 1];
+ output += encode(a[0], b[0], factor);
+ output += encode(a[1], b[1], factor);
+ }
+
+ return output;
+};
\ No newline at end of file
diff --git a/web/src/routes/trail/edit/[id]/+page.svelte b/web/src/routes/trail/edit/[id]/+page.svelte
index 9c2bcc28..51ac4148 100644
--- a/web/src/routes/trail/edit/[id]/+page.svelte
+++ b/web/src/routes/trail/edit/[id]/+page.svelte
@@ -60,6 +60,8 @@
import type { DivIcon, LatLng, LeafletMouseEvent, Map } from "leaflet";
import { onMount } from "svelte";
import { _ } from "svelte-i18n";
+ import { backInOut } from "svelte/easing";
+ import { fade, scale } from "svelte/transition";
import { array, number, object, string } from "yup";
export let data: { trail: Trail };
@@ -98,6 +100,15 @@
description: string().optional(),
});
+ const modesOfTransport = [
+ { text: "Hiking", value: "pedestrian" },
+ { text: "Cycling", value: "bicycle" },
+ { text: "Driving", value: "auto" },
+ ];
+ let selectedModeOfTransport = modesOfTransport[0].value;
+
+ let autoRouting = true;
+
const { form, errors, handleChange, handleSubmit } = createForm
({
initialValues: data.trail,
validationSchema: trailSchema,
@@ -141,6 +152,20 @@
});
}
+ if (
+ (!$form.lat || !$form.lon) &&
+ route.trk?.at(0)?.trkseg?.at(0)?.trkpt?.at(0)
+ ) {
+ $form.lat = route.trk
+ ?.at(0)
+ ?.trkseg?.at(0)
+ ?.trkpt?.at(0)?.$.lat;
+ $form.lon = route.trk
+ ?.at(0)
+ ?.trkseg?.at(0)
+ ?.trkpt?.at(0)?.$.lon;
+ }
+
if (!submittedTrail.id) {
const createdTrail = await trails_create(
submittedTrail,
@@ -180,8 +205,6 @@
L = (await import("leaflet")).default;
await import("leaflet.awesome-markers");
- // $form.lat = 47.74604748696788;
- // $form.lon = 11.588988304138185;
clearAnchorMarker();
clearRoute();
@@ -446,6 +469,8 @@
previousAnchor.lon,
e.latlng.lat,
e.latlng.lng,
+ selectedModeOfTransport,
+ autoRouting,
);
appendToRoute(routeWaypoints);
addAnchor(e.latlng.lat, e.latlng.lng);
@@ -537,6 +562,8 @@
anchor.lon,
nextAnchor.lat,
nextAnchor.lon,
+ selectedModeOfTransport,
+ autoRouting,
);
}
if (anchorIndex > 0) {
@@ -546,6 +573,8 @@
previousAnchor.lon,
anchor.lat,
anchor.lon,
+ selectedModeOfTransport,
+ autoRouting,
);
}
if (nextRouteSegment) {
@@ -808,19 +837,33 @@
{loading}>{$_("save-trail")}
- handleMapClick(e.detail)}
- >
+
+ {#if drawingActive}
+
+
+
+
+ {/if}
+
handleMapClick(e.detail)}
+ >
+