reverses waypoint relation
This commit is contained in:
@@ -205,27 +205,27 @@ func syncTrailWithTours(app core.App, k *KomootApi, i KomootIntegration, user st
|
|||||||
app.Logger().Warn(fmt.Sprintf("Unable to generate GPX for tour '%s': %v", tour.Name, err))
|
app.Logger().Warn(fmt.Sprintf("Unable to generate GPX for tour '%s': %v", tour.Name, err))
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
wpIds, err := createWaypointsFromTour(app, detailedTour, user)
|
trailid, err := createTrailFromTour(app, k, detailedTour, gpx, actor)
|
||||||
if err != nil {
|
|
||||||
app.Logger().Warn(fmt.Sprintf("Unable to create waypoints for tour '%s': %v", tour.Name, err))
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
err = createTrailFromTour(app, k, detailedTour, gpx, actor, wpIds)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
app.Logger().Warn(fmt.Sprintf("Unable to create trail for tour '%s': %v", tour.Name, err))
|
app.Logger().Warn(fmt.Sprintf("Unable to create trail for tour '%s': %v", tour.Name, err))
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
err = createWaypointsFromTour(app, detailedTour, user, trailid)
|
||||||
|
if err != nil {
|
||||||
|
app.Logger().Warn(fmt.Sprintf("Unable to create waypoints for tour '%s': %v", tour.Name, err))
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
return hasNewTours, nil
|
return hasNewTours, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func createTrailFromTour(app core.App, k *KomootApi, detailedTour *DetailedKomootTour, gpx *filesystem.File, actor string, wpIds []string) error {
|
func createTrailFromTour(app core.App, k *KomootApi, detailedTour *DetailedKomootTour, gpx *filesystem.File, actor string) (string, error) {
|
||||||
trailid := security.RandomStringWithAlphabet(core.DefaultIdLength, core.DefaultIdAlphabet)
|
trailid := security.RandomStringWithAlphabet(core.DefaultIdLength, core.DefaultIdAlphabet)
|
||||||
|
|
||||||
collection, err := app.FindCollectionByNameOrId("trails")
|
collection, err := app.FindCollectionByNameOrId("trails")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
record := core.NewRecord(collection)
|
record := core.NewRecord(collection)
|
||||||
@@ -251,12 +251,12 @@ func createTrailFromTour(app core.App, k *KomootApi, detailedTour *DetailedKomoo
|
|||||||
if len(detailedTour.Embedded.CoverImages.Embedded.Items) > 0 {
|
if len(detailedTour.Embedded.CoverImages.Embedded.Items) > 0 {
|
||||||
photos, err = fetchRoutePhotos(k, detailedTour)
|
photos, err = fetchRoutePhotos(k, detailedTour)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return "", err
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
photo, err := fetchPhoto(detailedTour.MapImage.Src, "", "")
|
photo, err := fetchPhoto(detailedTour.MapImage.Src, "", "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return "", err
|
||||||
}
|
}
|
||||||
photos = append(photos, photo)
|
photos = append(photos, photo)
|
||||||
}
|
}
|
||||||
@@ -281,7 +281,6 @@ func createTrailFromTour(app core.App, k *KomootApi, detailedTour *DetailedKomoo
|
|||||||
"lon": detailedTour.StartPoint.Lng,
|
"lon": detailedTour.StartPoint.Lng,
|
||||||
"difficulty": diffculty,
|
"difficulty": diffculty,
|
||||||
"category": categoryId,
|
"category": categoryId,
|
||||||
"waypoints": wpIds,
|
|
||||||
"author": actor,
|
"author": actor,
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -293,13 +292,13 @@ func createTrailFromTour(app core.App, k *KomootApi, detailedTour *DetailedKomoo
|
|||||||
}
|
}
|
||||||
|
|
||||||
if err := app.Save(record); err != nil {
|
if err := app.Save(record); err != nil {
|
||||||
return err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
if detailedTour.Type == "tour_recorded" {
|
if detailedTour.Type == "tour_recorded" {
|
||||||
collection, err := app.FindCollectionByNameOrId("summit_logs")
|
collection, err := app.FindCollectionByNameOrId("summit_logs")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
summitLogRecord := core.NewRecord(collection)
|
summitLogRecord := core.NewRecord(collection)
|
||||||
@@ -313,25 +312,23 @@ func createTrailFromTour(app core.App, k *KomootApi, detailedTour *DetailedKomoo
|
|||||||
"trail": trailid,
|
"trail": trailid,
|
||||||
})
|
})
|
||||||
if err := app.Save(summitLogRecord); err != nil {
|
if err := app.Save(summitLogRecord); err != nil {
|
||||||
return err
|
return "", err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return trailid, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func createWaypointsFromTour(app core.App, tour *DetailedKomootTour, user string) ([]string, error) {
|
func createWaypointsFromTour(app core.App, tour *DetailedKomootTour, user string, trailid string) error {
|
||||||
collection, err := app.FindCollectionByNameOrId("waypoints")
|
collection, err := app.FindCollectionByNameOrId("waypoints")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
wpIds := make([]string, len(tour.Embedded.Timeline.Embedded.Items))
|
for _, wp := range tour.Embedded.Timeline.Embedded.Items {
|
||||||
|
|
||||||
for i, wp := range tour.Embedded.Timeline.Embedded.Items {
|
|
||||||
photos, err := fetchWaypointPhotos(wp)
|
photos, err := fetchWaypointPhotos(wp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return err
|
||||||
}
|
}
|
||||||
record := core.NewRecord(collection)
|
record := core.NewRecord(collection)
|
||||||
|
|
||||||
@@ -358,6 +355,7 @@ func createWaypointsFromTour(app core.App, tour *DetailedKomootTour, user string
|
|||||||
"icon": "circle",
|
"icon": "circle",
|
||||||
"author": user,
|
"author": user,
|
||||||
"distance_from_start": 0,
|
"distance_from_start": 0,
|
||||||
|
"trail": trailid,
|
||||||
})
|
})
|
||||||
|
|
||||||
if photos != nil {
|
if photos != nil {
|
||||||
@@ -365,13 +363,11 @@ func createWaypointsFromTour(app core.App, tour *DetailedKomootTour, user string
|
|||||||
}
|
}
|
||||||
|
|
||||||
if err := app.Save(record); err != nil {
|
if err := app.Save(record); err != nil {
|
||||||
return nil, err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
wpIds[i] = record.Id
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return wpIds, nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func fetchRoutePhotos(k *KomootApi, tour *DetailedKomootTour) ([]*filesystem.File, error) {
|
func fetchRoutePhotos(k *KomootApi, tour *DetailedKomootTour) ([]*filesystem.File, error) {
|
||||||
|
|||||||
@@ -251,17 +251,16 @@ func syncTrailsWithRoutes(app core.App, accessToken string, user string, actor s
|
|||||||
app.Logger().Warn(fmt.Sprintf("Unable to fetch GPX for route '%s': %v", route.Name, err))
|
app.Logger().Warn(fmt.Sprintf("Unable to fetch GPX for route '%s': %v", route.Name, err))
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
wpIds, err := createWaypointsFromRoute(app, route, user)
|
trailid, err := createTrailFromRoute(app, route, gpx, actor)
|
||||||
if err != nil {
|
|
||||||
app.Logger().Warn(fmt.Sprintf("Unable to create waypoints for route '%s': %v", route.Name, err))
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
err = createTrailFromRoute(app, route, gpx, actor, wpIds)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
app.Logger().Warn(fmt.Sprintf("Unable to create trail for route '%s': %v", route.Name, err))
|
app.Logger().Warn(fmt.Sprintf("Unable to create trail for route '%s': %v", route.Name, err))
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
err = createWaypointsFromRoute(app, route, user, trailid)
|
||||||
|
if err != nil {
|
||||||
|
app.Logger().Warn(fmt.Sprintf("Unable to create waypoints for route '%s': %v", route.Name, err))
|
||||||
|
continue
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return hasNewRoutes, nil
|
return hasNewRoutes, nil
|
||||||
@@ -305,10 +304,12 @@ func fetchRouteGPX(route StravaRoute, accessToken string) (*filesystem.File, err
|
|||||||
return gpxFile, nil
|
return gpxFile, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func createTrailFromRoute(app core.App, route StravaRoute, gpx *filesystem.File, actor string, wpIds []string) error {
|
func createTrailFromRoute(app core.App, route StravaRoute, gpx *filesystem.File, actor string) (string, error) {
|
||||||
|
trailid := security.RandomStringWithAlphabet(core.DefaultIdLength, core.DefaultIdAlphabet)
|
||||||
|
|
||||||
collection, err := app.FindCollectionByNameOrId("trails")
|
collection, err := app.FindCollectionByNameOrId("trails")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
record := core.NewRecord(collection)
|
record := core.NewRecord(collection)
|
||||||
@@ -337,6 +338,7 @@ func createTrailFromRoute(app core.App, route StravaRoute, gpx *filesystem.File,
|
|||||||
}
|
}
|
||||||
|
|
||||||
record.Load(map[string]any{
|
record.Load(map[string]any{
|
||||||
|
"id": trailid,
|
||||||
"name": route.Name,
|
"name": route.Name,
|
||||||
"description": route.Description,
|
"description": route.Description,
|
||||||
"public": !route.Private,
|
"public": !route.Private,
|
||||||
@@ -348,7 +350,6 @@ func createTrailFromRoute(app core.App, route StravaRoute, gpx *filesystem.File,
|
|||||||
"external_id": route.IDStr,
|
"external_id": route.IDStr,
|
||||||
"lat": lat,
|
"lat": lat,
|
||||||
"lon": lon,
|
"lon": lon,
|
||||||
"waypoints": wpIds,
|
|
||||||
"difficulty": "easy",
|
"difficulty": "easy",
|
||||||
"category": category,
|
"category": category,
|
||||||
"author": actor,
|
"author": actor,
|
||||||
@@ -359,20 +360,18 @@ func createTrailFromRoute(app core.App, route StravaRoute, gpx *filesystem.File,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if err := app.Save(record); err != nil {
|
if err := app.Save(record); err != nil {
|
||||||
return err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return trailid, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func createWaypointsFromRoute(app core.App, route StravaRoute, user string) ([]string, error) {
|
func createWaypointsFromRoute(app core.App, route StravaRoute, user string, trailid string) error {
|
||||||
collection, err := app.FindCollectionByNameOrId("waypoints")
|
collection, err := app.FindCollectionByNameOrId("waypoints")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
wpIds := make([]string, len(route.Waypoints))
|
|
||||||
|
|
||||||
for i, wp := range route.Waypoints {
|
for i, wp := range route.Waypoints {
|
||||||
record := core.NewRecord(collection)
|
record := core.NewRecord(collection)
|
||||||
|
|
||||||
@@ -383,13 +382,15 @@ func createWaypointsFromRoute(app core.App, route StravaRoute, user string) ([]s
|
|||||||
record.Set("icon", "circle")
|
record.Set("icon", "circle")
|
||||||
record.Set("author", user)
|
record.Set("author", user)
|
||||||
record.Set("distance_from_start", wp.DistanceIntoRoute)
|
record.Set("distance_from_start", wp.DistanceIntoRoute)
|
||||||
|
record.Set("trail", trailid)
|
||||||
|
|
||||||
app.Save(record)
|
if err := app.Save(record); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
wpIds[i] = record.Id
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return wpIds, nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func syncTrailsWithActivities(app core.App, accessToken string, user string, actor string, activities []StravaActivity) (bool, error) {
|
func syncTrailsWithActivities(app core.App, accessToken string, user string, actor string, activities []StravaActivity) (bool, error) {
|
||||||
|
|||||||
62
db/migrations/1757689107_updated_waypoints.go
Normal file
62
db/migrations/1757689107_updated_waypoints.go
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
package migrations
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
|
||||||
|
"github.com/pocketbase/pocketbase/core"
|
||||||
|
m "github.com/pocketbase/pocketbase/migrations"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
m.Register(func(app core.App) error {
|
||||||
|
collection, err := app.FindCollectionByNameOrId("goeo2ubp103rzp9")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// update collection data
|
||||||
|
if err := json.Unmarshal([]byte(`{
|
||||||
|
"listRule": "author = @request.auth.id || trail.author.user ?= @request.auth.id || trail.public ?= true || trail.trail_share_via_trail.actor.user ?= @request.auth.id\n|| \n(trail.trail_link_share_via_trail.token != \"\" && trail.trail_link_share_via_trail.token = @request.query.share)",
|
||||||
|
"viewRule": "author = @request.auth.id || trail.author.user ?= @request.auth.id || trail.public ?= true || trail.trail_share_via_trail.actor.user ?= @request.auth.id\n|| \n(trail.trail_link_share_via_trail.token != \"\" && trail.trail_link_share_via_trail.token = @request.query.share)"
|
||||||
|
}`), &collection); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// add field
|
||||||
|
if err := collection.Fields.AddMarshaledJSONAt(9, []byte(`{
|
||||||
|
"cascadeDelete": true,
|
||||||
|
"collectionId": "e864strfxo14pm4",
|
||||||
|
"hidden": false,
|
||||||
|
"id": "relation2993194383",
|
||||||
|
"maxSelect": 1,
|
||||||
|
"minSelect": 0,
|
||||||
|
"name": "trail",
|
||||||
|
"presentable": false,
|
||||||
|
"required": true,
|
||||||
|
"system": false,
|
||||||
|
"type": "relation"
|
||||||
|
}`)); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return app.Save(collection)
|
||||||
|
}, func(app core.App) error {
|
||||||
|
collection, err := app.FindCollectionByNameOrId("goeo2ubp103rzp9")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// update collection data
|
||||||
|
if err := json.Unmarshal([]byte(`{
|
||||||
|
"listRule": "author = @request.auth.id || trails_via_waypoints.author.user ?= @request.auth.id || trails_via_waypoints.public ?= true || \n(@collection.trail_share.trail.id ?= trails_via_waypoints.id && @collection.trail_share.actor.user ?= @request.auth.id)\n|| \n(@collection.trail_link_share.token != \"\" && @collection.trail_link_share.trail.waypoints.id ?= id)",
|
||||||
|
"viewRule": "author = @request.auth.id || trails_via_waypoints.author.user ?= @request.auth.id || trails_via_waypoints.public ?= true || \n(@collection.trail_share.trail.id ?= trails_via_waypoints.id && @collection.trail_share.actor.user ?= @request.auth.id)\n|| \n(@collection.trail_link_share.token != \"\" && @collection.trail_link_share.trail.waypoints.id ?= id)"
|
||||||
|
}`), &collection); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// remove field
|
||||||
|
collection.Fields.RemoveById("relation2993194383")
|
||||||
|
|
||||||
|
return app.Save(collection)
|
||||||
|
})
|
||||||
|
}
|
||||||
34
db/migrations/1757689185_migrate_waypoint_trails.go
Normal file
34
db/migrations/1757689185_migrate_waypoint_trails.go
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
package migrations
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/pocketbase/dbx"
|
||||||
|
"github.com/pocketbase/pocketbase/core"
|
||||||
|
m "github.com/pocketbase/pocketbase/migrations"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
m.Register(func(app core.App) error {
|
||||||
|
wps, err := app.FindAllRecords("waypoints")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, wp := range wps {
|
||||||
|
trail, err := app.FindFirstRecordByFilter("trails", "waypoints ?~ {:id}", dbx.Params{"id": wp.Id})
|
||||||
|
if err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
wp.Set("trail", trail.Id)
|
||||||
|
err = app.UnsafeWithoutHooks().Save(wp)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}, func(app core.App) error {
|
||||||
|
// add down queries...
|
||||||
|
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
}
|
||||||
44
db/migrations/1757690946_updated_trails.go
Normal file
44
db/migrations/1757690946_updated_trails.go
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
package migrations
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/pocketbase/pocketbase/core"
|
||||||
|
m "github.com/pocketbase/pocketbase/migrations"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
m.Register(func(app core.App) error {
|
||||||
|
collection, err := app.FindCollectionByNameOrId("e864strfxo14pm4")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// remove field
|
||||||
|
collection.Fields.RemoveById("ppq2sist")
|
||||||
|
|
||||||
|
return app.Save(collection)
|
||||||
|
}, func(app core.App) error {
|
||||||
|
collection, err := app.FindCollectionByNameOrId("e864strfxo14pm4")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// add field
|
||||||
|
if err := collection.Fields.AddMarshaledJSONAt(16, []byte(`{
|
||||||
|
"cascadeDelete": false,
|
||||||
|
"collectionId": "goeo2ubp103rzp9",
|
||||||
|
"hidden": false,
|
||||||
|
"id": "ppq2sist",
|
||||||
|
"maxSelect": 2147483647,
|
||||||
|
"minSelect": 0,
|
||||||
|
"name": "waypoints",
|
||||||
|
"presentable": false,
|
||||||
|
"required": false,
|
||||||
|
"system": false,
|
||||||
|
"type": "relation"
|
||||||
|
}`)); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return app.Save(collection)
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -658,7 +658,7 @@
|
|||||||
<MapWithElevationMaplibre
|
<MapWithElevationMaplibre
|
||||||
trails={[trail]}
|
trails={[trail]}
|
||||||
activeTrail={0}
|
activeTrail={0}
|
||||||
waypoints={trail.expand?.waypoints}
|
waypoints={trail.expand?.waypoints_via_trail}
|
||||||
showElevation={true}
|
showElevation={true}
|
||||||
elevationProfileContainer={"epc-container"}
|
elevationProfileContainer={"epc-container"}
|
||||||
showStyleSwitcher={false}
|
showStyleSwitcher={false}
|
||||||
|
|||||||
@@ -25,7 +25,7 @@
|
|||||||
<div class="">
|
<div class="">
|
||||||
<p class="font-semibold">{$_("start")}</p>
|
<p class="font-semibold">{$_("start")}</p>
|
||||||
</div>
|
</div>
|
||||||
{#each trail.expand?.waypoints ?? [] as wp, i}
|
{#each trail.expand?.waypoints_via_trail ?? [] as wp, i}
|
||||||
<div
|
<div
|
||||||
class="bg-background cursor-pointer"
|
class="bg-background cursor-pointer"
|
||||||
role="presentation"
|
role="presentation"
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ const TrailCreateSchema = z.object({
|
|||||||
duration: z.number({ coerce: true }).nonnegative().optional(),
|
duration: z.number({ coerce: true }).nonnegative().optional(),
|
||||||
photos: z.array(z.string()).default([]),
|
photos: z.array(z.string()).default([]),
|
||||||
thumbnail: z.number().int().nonnegative().optional(),
|
thumbnail: z.number().int().nonnegative().optional(),
|
||||||
waypoints: z.array(z.string()).default([]),
|
|
||||||
like_count: z.number().int().min(0).optional().default(0),
|
like_count: z.number().int().min(0).optional().default(0),
|
||||||
category: z.string().length(15).optional().or(z.literal('')),
|
category: z.string().length(15).optional().or(z.literal('')),
|
||||||
tags: z.array(z.string()).default([]),
|
tags: z.array(z.string()).default([]),
|
||||||
@@ -44,7 +43,6 @@ const TrailUpdateSchema = z.object({
|
|||||||
"photos-": z.string().optional(),
|
"photos-": z.string().optional(),
|
||||||
"photos+": z.string().optional(),
|
"photos+": z.string().optional(),
|
||||||
thumbnail: z.number().int().nonnegative().optional(),
|
thumbnail: z.number().int().nonnegative().optional(),
|
||||||
waypoints: z.array(z.string()).optional(),
|
|
||||||
like_count: z.number().int().min(0).optional().default(0),
|
like_count: z.number().int().min(0).optional().default(0),
|
||||||
category: z.string().optional(),
|
category: z.string().optional(),
|
||||||
tags: z.array(z.string()).optional(),
|
tags: z.array(z.string()).optional(),
|
||||||
|
|||||||
@@ -6,20 +6,21 @@ const WaypointCreateSchema = z.object({
|
|||||||
id: z.string().length(15).optional(),
|
id: z.string().length(15).optional(),
|
||||||
name: z.string().optional(),
|
name: z.string().optional(),
|
||||||
description: z.string().optional(),
|
description: z.string().optional(),
|
||||||
lat: z.number({coerce: true}).min(-90).max(90),
|
lat: z.number({ coerce: true }).min(-90).max(90),
|
||||||
lon: z.number({coerce: true}).min(-180).max(180),
|
lon: z.number({ coerce: true }).min(-180).max(180),
|
||||||
distance_from_start: z.number({coerce: true}).min(0).optional(),
|
distance_from_start: z.number({ coerce: true }).min(0).optional(),
|
||||||
icon: z.enum(icons).optional(),
|
icon: z.enum(icons).optional(),
|
||||||
author: z.string().length(15),
|
author: z.string().length(15),
|
||||||
photos: z.array(z.string()).default([]),
|
photos: z.array(z.string()).default([]),
|
||||||
|
trail: z.string().length(15).optional()
|
||||||
}) satisfies ZodType<Partial<Waypoint>>
|
}) satisfies ZodType<Partial<Waypoint>>
|
||||||
|
|
||||||
const WaypointUpdateSchema = z.object({
|
const WaypointUpdateSchema = z.object({
|
||||||
name: z.string().optional(),
|
name: z.string().optional(),
|
||||||
description: z.string().optional(),
|
description: z.string().optional(),
|
||||||
lat: z.number({coerce: true}).min(-90).max(90).optional(),
|
lat: z.number({ coerce: true }).min(-90).max(90).optional(),
|
||||||
lon: z.number({coerce: true}).min(-180).max(180).optional(),
|
lon: z.number({ coerce: true }).min(-180).max(180).optional(),
|
||||||
distance_from_start: z.number({coerce: true}).min(0).optional(),
|
distance_from_start: z.number({ coerce: true }).min(0).optional(),
|
||||||
icon: z.enum(icons).default("circle").optional(),
|
icon: z.enum(icons).default("circle").optional(),
|
||||||
photos: z.array(z.string()).optional(),
|
photos: z.array(z.string()).optional(),
|
||||||
"photos-": z.string().optional(),
|
"photos-": z.string().optional(),
|
||||||
|
|||||||
@@ -28,7 +28,6 @@ class Trail {
|
|||||||
updated?: string;
|
updated?: string;
|
||||||
category?: string;
|
category?: string;
|
||||||
tags: string[];
|
tags: string[];
|
||||||
waypoints: string[];
|
|
||||||
polyline?: string;
|
polyline?: string;
|
||||||
domain?: string;
|
domain?: string;
|
||||||
iri?: string;
|
iri?: string;
|
||||||
@@ -36,7 +35,7 @@ class Trail {
|
|||||||
expand?: {
|
expand?: {
|
||||||
tags?: Tag[]
|
tags?: Tag[]
|
||||||
category?: Category;
|
category?: Category;
|
||||||
waypoints?: Waypoint[]
|
waypoints_via_trail?: Waypoint[]
|
||||||
summit_logs_via_trail?: SummitLog[]
|
summit_logs_via_trail?: SummitLog[]
|
||||||
author?: Actor
|
author?: Actor
|
||||||
comments_via_trail?: Comment[]
|
comments_via_trail?: Comment[]
|
||||||
@@ -90,13 +89,12 @@ class Trail {
|
|||||||
this.lon = params?.lon;
|
this.lon = params?.lon;
|
||||||
this.thumbnail = params?.thumbnail ?? 0;
|
this.thumbnail = params?.thumbnail ?? 0;
|
||||||
this.photos = params?.photos ?? [];
|
this.photos = params?.photos ?? [];
|
||||||
this.waypoints = [];
|
|
||||||
this.tags = []
|
this.tags = []
|
||||||
this.gpx = params?.gpx;
|
this.gpx = params?.gpx;
|
||||||
this.like_count = 0
|
this.like_count = 0
|
||||||
this.expand = {
|
this.expand = {
|
||||||
category: params?.category,
|
category: params?.category,
|
||||||
waypoints: params?.waypoints ?? [],
|
waypoints_via_trail: params?.waypoints ?? [],
|
||||||
summit_logs_via_trail: params?.summit_logs ?? [],
|
summit_logs_via_trail: params?.summit_logs ?? [],
|
||||||
comments_via_trail: params?.comments ?? [],
|
comments_via_trail: params?.comments ?? [],
|
||||||
trail_share_via_trail: params?.shares ?? []
|
trail_share_via_trail: params?.shares ?? []
|
||||||
|
|||||||
@@ -13,10 +13,12 @@ class Waypoint {
|
|||||||
photos: string[];
|
photos: string[];
|
||||||
_photos?: File[];
|
_photos?: File[];
|
||||||
author: string;
|
author: string;
|
||||||
|
trail?: string;
|
||||||
|
|
||||||
constructor(lat: number, lon: number, params?: {
|
constructor(lat: number, lon: number, params?: {
|
||||||
id?: string, name?: string, description?: string, icon?: typeof icons[number], marker?: M.Marker, photos?: string[];
|
id?: string, name?: string, description?: string, icon?: typeof icons[number], marker?: M.Marker, photos?: string[], trail?: string
|
||||||
}) {
|
}) {
|
||||||
|
this.trail = params?.trail;
|
||||||
this.id = params?.id;
|
this.id = params?.id;
|
||||||
this.name = params?.name ?? "";
|
this.name = params?.name ?? "";
|
||||||
this.description = params?.description ?? "";
|
this.description = params?.description ?? "";
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ export const editTrail: Writable<Trail> = writable(new Trail(""));
|
|||||||
export async function trails_index(perPage: number = 21, random: boolean = false, f: (url: RequestInfo | URL, config?: RequestInit) => Promise<Response> = fetch) {
|
export async function trails_index(perPage: number = 21, random: boolean = false, f: (url: RequestInfo | URL, config?: RequestInit) => Promise<Response> = fetch) {
|
||||||
const r = await f('/api/v1/trail?' + new URLSearchParams({
|
const r = await f('/api/v1/trail?' + new URLSearchParams({
|
||||||
"perPage": perPage.toString(),
|
"perPage": perPage.toString(),
|
||||||
expand: "category,waypoints,summit_logs_via_trail,tags",
|
expand: "category,waypoints_via_trail,summit_logs_via_trail,tags",
|
||||||
sort: random ? "@random" : "",
|
sort: random ? "@random" : "",
|
||||||
}), {
|
}), {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
@@ -136,7 +136,7 @@ export async function trails_search_bounding_box(northEast: M.LngLat, southWest:
|
|||||||
export async function trails_show(id: string, handle?: string, share?: string, loadGPX?: boolean, f: (url: RequestInfo | URL, config?: RequestInit) => Promise<Response> = fetch) {
|
export async function trails_show(id: string, handle?: string, share?: string, loadGPX?: boolean, f: (url: RequestInfo | URL, config?: RequestInit) => Promise<Response> = fetch) {
|
||||||
|
|
||||||
const r = await f(`/api/v1/trail/${id}?` + new URLSearchParams({
|
const r = await f(`/api/v1/trail/${id}?` + new URLSearchParams({
|
||||||
expand: "category,waypoints,summit_logs_via_trail,summit_logs_via_trail.author,trail_share_via_trail.actor,trail_like_via_trail,tags,author",
|
expand: "category,waypoints_via_trail,summit_logs_via_trail,summit_logs_via_trail.author,trail_share_via_trail.actor,trail_like_via_trail,tags,author",
|
||||||
...(handle ? { handle } : {}),
|
...(handle ? { handle } : {}),
|
||||||
...(share ? { share } : {})
|
...(share ? { share } : {})
|
||||||
}), {
|
}), {
|
||||||
@@ -148,7 +148,7 @@ export async function trails_show(id: string, handle?: string, share?: string, l
|
|||||||
throw new APIError(r.status, response.message, response.detail)
|
throw new APIError(r.status, response.message, response.detail)
|
||||||
}
|
}
|
||||||
|
|
||||||
const response = await r.json()
|
const response: Trail = await r.json()
|
||||||
|
|
||||||
if (loadGPX) {
|
if (loadGPX) {
|
||||||
if (!response.expand) {
|
if (!response.expand) {
|
||||||
@@ -171,8 +171,8 @@ export async function trails_show(id: string, handle?: string, share?: string, l
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
response.expand.waypoints = response.expand.waypoints || [];
|
response.expand!.waypoints_via_trail = response.expand!.waypoints_via_trail || [];
|
||||||
response.expand.summit_logs = response.expand.summit_logs?.sort((a: SummitLog, b: SummitLog) => Date.parse(a.date) - Date.parse(b.date)) || [];
|
response.expand!.summit_logs_via_trail = response.expand!.summit_logs_via_trail?.sort((a: SummitLog, b: SummitLog) => Date.parse(a.date) - Date.parse(b.date)) || [];
|
||||||
|
|
||||||
trail.set(response);
|
trail.set(response);
|
||||||
|
|
||||||
@@ -185,13 +185,6 @@ export async function trails_create(trail: Trail, photos: File[], gpx: File | Bl
|
|||||||
throw Error("Unauthenticated")
|
throw Error("Unauthenticated")
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const waypoint of trail.expand?.waypoints ?? []) {
|
|
||||||
const model = await waypoints_create({
|
|
||||||
...waypoint,
|
|
||||||
marker: undefined,
|
|
||||||
}, f, user);
|
|
||||||
trail.waypoints.push(model.id!);
|
|
||||||
}
|
|
||||||
for (const tag of trail.expand?.tags ?? []) {
|
for (const tag of trail.expand?.tags ?? []) {
|
||||||
if (!tag.id) {
|
if (!tag.id) {
|
||||||
const model = await tags_create(tag)
|
const model = await tags_create(tag)
|
||||||
@@ -214,7 +207,7 @@ export async function trails_create(trail: Trail, photos: File[], gpx: File | Bl
|
|||||||
}
|
}
|
||||||
|
|
||||||
let r = await f(`/api/v1/trail/form?` + new URLSearchParams({
|
let r = await f(`/api/v1/trail/form?` + new URLSearchParams({
|
||||||
expand: "category,waypoints,summit_logs_via_trail,trail_share_via_trail,tags",
|
expand: "category,waypoints_via_trail,summit_logs_via_trail,trail_share_via_trail,tags",
|
||||||
}), {
|
}), {
|
||||||
method: 'PUT',
|
method: 'PUT',
|
||||||
body: formData,
|
body: formData,
|
||||||
@@ -232,6 +225,14 @@ export async function trails_create(trail: Trail, photos: File[], gpx: File | Bl
|
|||||||
await summit_logs_create(summitLog, f);
|
await summit_logs_create(summitLog, f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (const wp of trail.expand?.waypoints_via_trail ?? []) {
|
||||||
|
wp.trail = model.id!;
|
||||||
|
await waypoints_create({
|
||||||
|
...wp,
|
||||||
|
marker: undefined,
|
||||||
|
}, f, user);
|
||||||
|
}
|
||||||
|
|
||||||
return model;
|
return model;
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -239,18 +240,17 @@ export async function trails_create(trail: Trail, photos: File[], gpx: File | Bl
|
|||||||
export async function trails_update(oldTrail: Trail, newTrail: Trail, photos?: File[], gpx?: File | Blob | null) {
|
export async function trails_update(oldTrail: Trail, newTrail: Trail, photos?: File[], gpx?: File | Blob | null) {
|
||||||
newTrail.author = oldTrail.author
|
newTrail.author = oldTrail.author
|
||||||
|
|
||||||
const waypointUpdates = compareObjectArrays<Waypoint>(oldTrail.expand?.waypoints ?? [], newTrail.expand?.waypoints ?? []);
|
const waypointUpdates = compareObjectArrays<Waypoint>(oldTrail.expand?.waypoints_via_trail ?? [], newTrail.expand?.waypoints_via_trail ?? []);
|
||||||
|
|
||||||
for (const addedWaypoint of waypointUpdates.added) {
|
for (const addedWaypoint of waypointUpdates.added) {
|
||||||
const model = await waypoints_create({
|
const model = await waypoints_create({
|
||||||
...addedWaypoint,
|
...addedWaypoint,
|
||||||
marker: undefined,
|
marker: undefined,
|
||||||
},);
|
},);
|
||||||
newTrail.waypoints.push(model.id!);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const updatedWaypoint of waypointUpdates.updated) {
|
for (const updatedWaypoint of waypointUpdates.updated) {
|
||||||
const oldWaypoint = oldTrail.expand?.waypoints?.find(w => w.id == updatedWaypoint.id);
|
const oldWaypoint = oldTrail.expand?.waypoints_via_trail?.find(w => w.id == updatedWaypoint.id);
|
||||||
const model = await waypoints_update(oldWaypoint!, {
|
const model = await waypoints_update(oldWaypoint!, {
|
||||||
...updatedWaypoint,
|
...updatedWaypoint,
|
||||||
marker: undefined,
|
marker: undefined,
|
||||||
@@ -313,7 +313,7 @@ export async function trails_update(oldTrail: Trail, newTrail: Trail, photos?: F
|
|||||||
|
|
||||||
|
|
||||||
let r = await fetch(`/api/v1/trail/form/${newTrail.id}?` + new URLSearchParams({
|
let r = await fetch(`/api/v1/trail/form/${newTrail.id}?` + new URLSearchParams({
|
||||||
expand: "category,waypoints,summit_logs_via_trail,trail_share_via_trail,tags",
|
expand: "category,waypoints_via_trail,summit_logs_via_trail,trail_share_via_trail,tags",
|
||||||
}), {
|
}), {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: formData,
|
body: formData,
|
||||||
@@ -340,17 +340,6 @@ export async function trails_update(oldTrail: Trail, newTrail: Trail, photos?: F
|
|||||||
|
|
||||||
|
|
||||||
export async function trails_delete(trail: Trail) {
|
export async function trails_delete(trail: Trail) {
|
||||||
if (trail.expand?.waypoints) {
|
|
||||||
for (const waypoint of trail.expand.waypoints) {
|
|
||||||
await waypoints_delete(waypoint);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (trail.expand?.summit_logs_via_trail) {
|
|
||||||
for (const summit_log of trail.expand.summit_logs_via_trail) {
|
|
||||||
await summit_logs_delete(summit_log);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const r = await fetch('/api/v1/trail/' + trail.id, {
|
const r = await fetch('/api/v1/trail/' + trail.id, {
|
||||||
method: 'DELETE',
|
method: 'DELETE',
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ export async function gpx2trail(gpxString: string, fallbackName?: string, correc
|
|||||||
wp.id = cryptoRandomString({ length: 15 });
|
wp.id = cryptoRandomString({ length: 15 });
|
||||||
wp.name = wpt.name ?? ""
|
wp.name = wpt.name ?? ""
|
||||||
wp.description = wpt.desc;
|
wp.description = wpt.desc;
|
||||||
trail.expand!.waypoints?.push(wp);
|
trail.expand!.waypoints_via_trail?.push(wp);
|
||||||
}
|
}
|
||||||
|
|
||||||
const totals = gpx.features
|
const totals = gpx.features
|
||||||
@@ -108,7 +108,7 @@ export async function trail2gpx(trail: Trail, user?: AuthRecord) {
|
|||||||
gpx.wpt = [];
|
gpx.wpt = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const wp of gpxTrail.expand!.waypoints ?? []) {
|
for (const wp of gpxTrail.expand!.waypoints_via_trail ?? []) {
|
||||||
const gpxWpt = gpx.wpt.find((w) => w.$.lat == wp.lat && w.$.lon == wp.lon)
|
const gpxWpt = gpx.wpt.find((w) => w.$.lat == wp.lat && w.$.lon == wp.lon)
|
||||||
if (!gpxWpt) {
|
if (!gpxWpt) {
|
||||||
gpx.wpt.push(new GPXWaypoint({
|
gpx.wpt.push(new GPXWaypoint({
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ export async function GET(event: RequestEvent) {
|
|||||||
t.expand = {} as any
|
t.expand = {} as any
|
||||||
}
|
}
|
||||||
|
|
||||||
t.expand?.waypoints?.sort((a, b) => (a.distance_from_start ?? 0) - (b.distance_from_start ?? 0))
|
t.expand?.waypoints_via_trail?.sort((a, b) => (a.distance_from_start ?? 0) - (b.distance_from_start ?? 0))
|
||||||
}
|
}
|
||||||
return json(r)
|
return json(r)
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ export async function GET(event: RequestEvent) {
|
|||||||
l.expand.author.isLocal = false
|
l.expand.author.isLocal = false
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
t.expand?.waypoints?.forEach(w => {
|
t.expand?.waypoints_via_trail?.forEach(w => {
|
||||||
|
|
||||||
w.photos = w.photos.map(p =>
|
w.photos = w.photos.map(p =>
|
||||||
`${origin}/api/v1/files/waypoints/${w.id}/${p}`
|
`${origin}/api/v1/files/waypoints/${w.id}/${p}`
|
||||||
@@ -131,7 +131,7 @@ export async function GET(event: RequestEvent) {
|
|||||||
await enrichRecord(event.locals.pb, t);
|
await enrichRecord(event.locals.pb, t);
|
||||||
|
|
||||||
// sort waypoints by distance
|
// sort waypoints by distance
|
||||||
t.expand?.waypoints?.sort((a, b) => (a.distance_from_start ?? 0) - (b.distance_from_start ?? 0))
|
t.expand?.waypoints_via_trail?.sort((a, b) => (a.distance_from_start ?? 0) - (b.distance_from_start ?? 0))
|
||||||
return json(t)
|
return json(t)
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
return handleError(e)
|
return handleError(e)
|
||||||
|
|||||||
@@ -71,7 +71,7 @@
|
|||||||
let selectedTrailIndex = $derived(selectedTrail ? 0 : null);
|
let selectedTrailIndex = $derived(selectedTrail ? 0 : null);
|
||||||
|
|
||||||
let selectedTrailWaypoints = $derived(
|
let selectedTrailWaypoints = $derived(
|
||||||
(selectedTrail as Trail | null)?.expand?.waypoints,
|
(selectedTrail as Trail | null)?.expand?.waypoints_via_trail,
|
||||||
);
|
);
|
||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
|
|||||||
@@ -45,7 +45,7 @@
|
|||||||
<div id="trail-details">
|
<div id="trail-details">
|
||||||
<MapWithElevationMaplibre
|
<MapWithElevationMaplibre
|
||||||
trails={[trail]}
|
trails={[trail]}
|
||||||
waypoints={trail.expand?.waypoints}
|
waypoints={trail.expand?.waypoints_via_trail}
|
||||||
activeTrail={0}
|
activeTrail={0}
|
||||||
bind:markers
|
bind:markers
|
||||||
showTerrain={true}
|
showTerrain={true}
|
||||||
|
|||||||
@@ -390,7 +390,7 @@
|
|||||||
currentHeight += getTextHeight($trail.description, doc, width - 32) + 8;
|
currentHeight += getTextHeight($trail.description, doc, width - 32) + 8;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (includeWaypoints && $trail.expand?.waypoints) {
|
if (includeWaypoints && $trail.expand?.waypoints_via_trail) {
|
||||||
const header = $_("waypoints", { values: { n: 2 } })
|
const header = $_("waypoints", { values: { n: 2 } })
|
||||||
let textHeight = getTextHeight(header, doc, width - 32)
|
let textHeight = getTextHeight(header, doc, width - 32)
|
||||||
if (currentHeight + textHeight + 8 > height) {
|
if (currentHeight + textHeight + 8 > height) {
|
||||||
@@ -401,7 +401,7 @@
|
|||||||
currentHeight += textHeight + 8;
|
currentHeight += textHeight + 8;
|
||||||
doc.setFont("IBMPlexSans-Regular", "normal");
|
doc.setFont("IBMPlexSans-Regular", "normal");
|
||||||
|
|
||||||
($trail.expand.waypoints || []).forEach(waypoint => {
|
($trail.expand.waypoints_via_trail || []).forEach(waypoint => {
|
||||||
let description = waypoint.description || "";
|
let description = waypoint.description || "";
|
||||||
let name = waypoint.name || "";
|
let name = waypoint.name || "";
|
||||||
|
|
||||||
@@ -616,7 +616,7 @@
|
|||||||
<div class="basis-full">
|
<div class="basis-full">
|
||||||
<MapWithElevationMaplibre
|
<MapWithElevationMaplibre
|
||||||
trails={[$trail]}
|
trails={[$trail]}
|
||||||
waypoints={$trail.expand?.waypoints}
|
waypoints={$trail.expand?.waypoints_via_trail}
|
||||||
activeTrail={0}
|
activeTrail={0}
|
||||||
onzoom={updateScale}
|
onzoom={updateScale}
|
||||||
bind:map
|
bind:map
|
||||||
|
|||||||
@@ -139,7 +139,7 @@
|
|||||||
summit_logs_via_trail: z
|
summit_logs_via_trail: z
|
||||||
.array(SummitLogCreateSchema)
|
.array(SummitLogCreateSchema)
|
||||||
.optional(),
|
.optional(),
|
||||||
waypoints: z
|
waypoints_via_trail: z
|
||||||
.array(
|
.array(
|
||||||
WaypointCreateSchema.extend({
|
WaypointCreateSchema.extend({
|
||||||
marker: z.any().optional(),
|
marker: z.any().optional(),
|
||||||
@@ -384,11 +384,10 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function clearWaypoints() {
|
function clearWaypoints() {
|
||||||
for (const waypoint of $formData.expand!.waypoints ?? []) {
|
for (const waypoint of $formData.expand!.waypoints_via_trail ?? []) {
|
||||||
waypoint.marker?.remove();
|
waypoint.marker?.remove();
|
||||||
}
|
}
|
||||||
$formData.expand!.waypoints = [];
|
$formData.expand!.waypoints_via_trail = [];
|
||||||
$formData.waypoints = [];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function initRouteAnchors(gpx: GPX, addToMap: boolean = false) {
|
function initRouteAnchors(gpx: GPX, addToMap: boolean = false) {
|
||||||
@@ -445,29 +444,28 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function deleteWaypoint(index: number) {
|
function deleteWaypoint(index: number) {
|
||||||
const wp = $formData.expand!.waypoints?.splice(index, 1);
|
const wp = $formData.expand!.waypoints_via_trail?.splice(index, 1);
|
||||||
$formData.waypoints.splice(index, 1);
|
|
||||||
|
|
||||||
if (!$formData.expand!.waypoints?.length) {
|
if (!$formData.expand!.waypoints_via_trail?.length) {
|
||||||
$formData.expand!.waypoints = [];
|
$formData.expand!.waypoints_via_trail = [];
|
||||||
}
|
}
|
||||||
$formData.expand!.waypoints = $formData.expand!.waypoints;
|
$formData.expand!.waypoints_via_trail = $formData.expand!.waypoints_via_trail;
|
||||||
|
|
||||||
// updateTrailOnMap();
|
// updateTrailOnMap();
|
||||||
}
|
}
|
||||||
|
|
||||||
function saveWaypoint(savedWaypoint: Waypoint) {
|
function saveWaypoint(savedWaypoint: Waypoint) {
|
||||||
let editedWaypointIndex =
|
let editedWaypointIndex =
|
||||||
$formData.expand!.waypoints?.findIndex(
|
$formData.expand!.waypoints_via_trail?.findIndex(
|
||||||
(s) => s.id == savedWaypoint.id,
|
(s) => s.id == savedWaypoint.id,
|
||||||
) ?? -1;
|
) ?? -1;
|
||||||
|
|
||||||
if (editedWaypointIndex >= 0) {
|
if (editedWaypointIndex >= 0) {
|
||||||
$formData.expand!.waypoints![editedWaypointIndex] = savedWaypoint;
|
$formData.expand!.waypoints_via_trail![editedWaypointIndex] = savedWaypoint;
|
||||||
} else {
|
} else {
|
||||||
savedWaypoint.id = cryptoRandomString({ length: 15 });
|
savedWaypoint.id = cryptoRandomString({ length: 15 });
|
||||||
$formData.expand!.waypoints = [
|
$formData.expand!.waypoints_via_trail = [
|
||||||
...($formData.expand!.waypoints ?? []),
|
...($formData.expand!.waypoints_via_trail ?? []),
|
||||||
savedWaypoint,
|
savedWaypoint,
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -478,15 +476,15 @@
|
|||||||
function moveMarker(marker: M.Marker, wpId?: string) {
|
function moveMarker(marker: M.Marker, wpId?: string) {
|
||||||
const position = marker.getLngLat();
|
const position = marker.getLngLat();
|
||||||
const editableWaypointIndex =
|
const editableWaypointIndex =
|
||||||
$formData.expand!.waypoints?.findIndex((w) => w.id == wpId) ?? -1;
|
$formData.expand!.waypoints_via_trail?.findIndex((w) => w.id == wpId) ?? -1;
|
||||||
const editableWaypoint =
|
const editableWaypoint =
|
||||||
$formData.expand!.waypoints![editableWaypointIndex];
|
$formData.expand!.waypoints_via_trail![editableWaypointIndex];
|
||||||
if (!editableWaypoint) {
|
if (!editableWaypoint) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
editableWaypoint.lat = position.lat;
|
editableWaypoint.lat = position.lat;
|
||||||
editableWaypoint.lon = position.lng;
|
editableWaypoint.lon = position.lng;
|
||||||
$formData.expand!.waypoints = [...($formData.expand!.waypoints ?? [])];
|
$formData.expand!.waypoints_via_trail = [...($formData.expand!.waypoints_via_trail ?? [])];
|
||||||
// updateTrailOnMap();
|
// updateTrailOnMap();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1369,7 +1367,7 @@
|
|||||||
{$_("waypoints", { values: { n: 2 } })}
|
{$_("waypoints", { values: { n: 2 } })}
|
||||||
</h3>
|
</h3>
|
||||||
<ul>
|
<ul>
|
||||||
{#each $formData.expand?.waypoints ?? [] as waypoint, i}
|
{#each $formData.expand?.waypoints_via_trail ?? [] as waypoint, i}
|
||||||
<li
|
<li
|
||||||
onmouseenter={() => openMarkerPopup(waypoint)}
|
onmouseenter={() => openMarkerPopup(waypoint)}
|
||||||
onmouseleave={() => openMarkerPopup(waypoint)}
|
onmouseleave={() => openMarkerPopup(waypoint)}
|
||||||
@@ -1501,7 +1499,7 @@
|
|||||||
<div id="trail-map">
|
<div id="trail-map">
|
||||||
<MapWithElevationMaplibre
|
<MapWithElevationMaplibre
|
||||||
trails={mapTrail}
|
trails={mapTrail}
|
||||||
waypoints={$formData.expand?.waypoints}
|
waypoints={$formData.expand?.waypoints_via_trail}
|
||||||
drawing={drawingActive}
|
drawing={drawingActive}
|
||||||
showTerrain={true}
|
showTerrain={true}
|
||||||
onmarkerdragend={moveMarker}
|
onmarkerdragend={moveMarker}
|
||||||
|
|||||||
Reference in New Issue
Block a user