1
mirror of https://github.com/jlelse/GoBlog synced 2024-07-15 12:22:58 +00:00

Show uphill / downhill for tracks

This commit is contained in:
Jan-Lukas Else 2024-07-07 17:11:26 +02:00
parent 83606c0cb7
commit 50276d388e
4 changed files with 38 additions and 3 deletions

View File

@ -31,6 +31,8 @@ type trackResult struct {
PointsJSON string
Kilometers string
Hours string
Uphill string
Downhill string
Name string
MapAttribution string
MinZoom, MaxZoom int
@ -92,6 +94,11 @@ func (a *goBlog) getTrack(p *post, withMapFeatures bool) (result *trackResult, e
)
}
if parseResult.ud != nil {
result.Uphill = lp.Sprintf("%.0f", parseResult.ud.Uphill)
result.Downhill = lp.Sprintf("%.0f", parseResult.ud.Downhill)
}
return result, nil
}
@ -104,14 +111,16 @@ type trackParseResult struct {
points []*trackPoint
gpxData *gpx.GPX
md *gpx.MovingData
ud *gpx.UphillDownhill
}
func trackParseGPX(gpxString string) (result *trackParseResult, err error) {
result = &trackParseResult{}
type trackPath struct {
gpxMovingData *gpx.MovingData
points []*trackPoint
gpxMovingData *gpx.MovingData
gpxUphillDownhill *gpx.UphillDownhill
points []*trackPoint
}
result.gpxData, err = gpx.ParseString(gpxString)
@ -123,8 +132,10 @@ func trackParseGPX(gpxString string) (result *trackParseResult, err error) {
for _, track := range result.gpxData.Tracks {
for _, segment := range track.Segments {
md := segment.MovingData()
ud := segment.UphillDownhill()
path := &trackPath{
gpxMovingData: &md,
gpxMovingData: &md,
gpxUphillDownhill: &ud,
}
for _, point := range segment.Points {
path.points = append(path.points, &trackPoint{
@ -158,6 +169,14 @@ func trackParseGPX(gpxString string) (result *trackParseResult, err error) {
result.md.StoppedDistance = result.md.StoppedDistance + path.gpxMovingData.StoppedDistance
result.md.StoppedTime = result.md.StoppedTime + path.gpxMovingData.StoppedTime
}
// Combine uphill/downhill
if path.gpxUphillDownhill != nil {
if result.ud == nil {
result.ud = &gpx.UphillDownhill{}
}
result.ud.Uphill = result.ud.Uphill + path.gpxUphillDownhill.Uphill
result.ud.Downhill = result.ud.Downhill + path.gpxUphillDownhill.Downhill
}
}
result.points = []*trackPoint{}

View File

@ -50,6 +50,7 @@ locationnotsupported: "Die Standort-API wird von diesem Browser nicht unterstüt
mediafiles: "Medien-Dateien"
message: "Nachricht"
messagesent: "Nachricht gesendet"
meters: "Meter"
next: "Weiter"
nofiles: "Keine Dateien"
nolocations: "Keine Posts mit Standorten"

View File

@ -60,6 +60,7 @@ logout: "Logout"
mediafiles: "Media files"
message: "Message"
messagesent: "Message sent"
meters: "meters"
nameopt: "Name (optional)"
next: "Next"
nofiles: "No files"

View File

@ -502,6 +502,20 @@ func (a *goBlog) renderPostGPX(hb *htmlbuilder.HtmlBuilder, p *post, b *configBl
if track.Hours != "" {
hb.WriteUnescaped("⏱ ")
hb.WriteEscaped(track.Hours)
hb.WriteUnescaped(" ")
}
if track.Uphill != "" {
hb.WriteUnescaped("⬆️ ")
hb.WriteEscaped(track.Uphill)
hb.WriteUnescaped(" ")
hb.WriteEscaped(a.ts.GetTemplateStringVariant(b.Lang, "meters"))
hb.WriteUnescaped(" ")
}
if track.Downhill != "" {
hb.WriteUnescaped("⬇️ ")
hb.WriteEscaped(track.Downhill)
hb.WriteUnescaped(" ")
hb.WriteEscaped(a.ts.GetTemplateStringVariant(b.Lang, "meters"))
}
hb.WriteElementClose("p")
// Map (only show if it has features)