diff options
Diffstat (limited to 'web')
| -rw-r--r-- | web/rides.go | 9 | ||||
| -rw-r--r-- | web/views.go | 18 |
2 files changed, 15 insertions, 12 deletions
diff --git a/web/rides.go b/web/rides.go index 81017d9..71ab3fd 100644 --- a/web/rides.go +++ b/web/rides.go @@ -65,7 +65,7 @@ func (s *Server) handleRide(w http.ResponseWriter, r *http.Request) { }), w) return } - passes, err := mountain_pass.LoadMountainPassesAroundRide(s.db, parsed, rideDetailMountainPassMarginM) + passes, err := mountain_pass.LoadMountainPassesAroundRide(s.db, parsed.Coords(), rideDetailMountainPassMarginM) if err != nil { slog.Warn("Failed to load nearby mountain passes for ride detail", "ride_id", id, "error", err) } @@ -144,14 +144,15 @@ func (s *Server) handleCreateOfficialClimb(w http.ResponseWriter, r *http.Reques http.Error(w, "the recorded route is unavailable", http.StatusBadRequest) return } - if startIndex >= endIndex || endIndex >= parsed.Len() { + bounds := parsed.Coords() + if startIndex >= endIndex || endIndex >= len(bounds) { http.Error(w, "the official climb boundaries must be ordered route points", http.StatusBadRequest) return } created, err := official_climb.Create(s.db, official_climb.OfficialClimb{ Name: r.FormValue("name"), - StartCoord: parsed.Coord(startIndex), - EndCoord: parsed.Coord(endIndex), + StartCoord: bounds[startIndex], + EndCoord: bounds[endIndex], }) if err != nil { slog.Warn("Failed to create official climb", "ride_id", id, "error", err) diff --git a/web/views.go b/web/views.go index cfb31e5..8df860c 100644 --- a/web/views.go +++ b/web/views.go @@ -280,9 +280,9 @@ func officialClimbCreateURL(id int64) string { } func buildRideDetailView(item ride.StoredRide, parsed ride.Ride, passes []mountain_pass.MountainPass, officialClimbs []official_climb.OfficialClimb, matchPolicy official_climb.MatchPolicy) RideDetailView { - coordinates := make([][]float64, parsed.Len()) - for i := 0; i < parsed.Len(); i++ { - coordinate := parsed.Coord(i) + coords := parsed.Coords() + coordinates := make([][]float64, len(coords)) + for i, coordinate := range coords { coordinates[i] = []float64{coordinate.Lon, coordinate.Lat} } profile := buildRideProfile(parsed, passes, officialClimbs, matchPolicy) @@ -321,16 +321,18 @@ func buildRideMapPasses(passes []mountain_pass.MountainPass) []RideMapPass { } func buildRideProfile(parsed ride.Ride, passes []mountain_pass.MountainPass, officialClimbs []official_climb.OfficialClimb, matchPolicy official_climb.MatchPolicy) RideProfile { + coords := parsed.Coords() + distances := parsed.Distances() + elevations := parsed.Elevations() profile := RideProfile{ - Points: make([]RideProfilePoint, parsed.Len()), + Points: make([]RideProfilePoint, len(coords)), Climbs: make([]RideProfileClimb, 0), Crossings: make([]RideProfileCrossing, 0), } - for i := 0; i < parsed.Len(); i++ { - coordinate := parsed.Coord(i) + for i, coordinate := range coords { profile.Points[i] = RideProfilePoint{ - DistanceKm: parsed.DistanceM(i) / 1000, - ElevationM: parsed.ElevationM(i), + DistanceKm: distances[i] / 1000, + ElevationM: elevations[i], Latitude: coordinate.Lat, Longitude: coordinate.Lon, } |
