-
Notifications
You must be signed in to change notification settings - Fork 1
/
path.go
64 lines (51 loc) · 1.4 KB
/
path.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package builders
import (
"image/color"
gokml "github.com/twpayne/go-kml/v3"
"github.com/noodnik2/flightvisualizer/pkg/aeroapi"
)
// PathBuilder builds the visible "path" track, and optionally its extrusion to the ground
type PathBuilder struct {
Color color.Color
Extrude bool
}
func (pb *PathBuilder) Name() string {
return "Path"
}
func (pb *PathBuilder) Build(aeroTrackPositions []aeroapi.Position) (*KmlProduct, error) {
var coordinates []gokml.Coordinate
for _, position := range aeroTrackPositions {
coordinates = append(coordinates, gokml.Coordinate{
Lon: position.Longitude,
Lat: position.Latitude,
Alt: aeroAlt2Meters(position.AltMslD100),
})
}
lc := func(a uint8) color.RGBA {
r, g, b, _ := pb.Color.RGBA()
return color.RGBA{R: uint8(r), G: uint8(g), B: uint8(b), A: a}
}
flightStyle := gokml.Style(
gokml.LineStyle(
gokml.Color(lc(127)),
gokml.Width(3),
),
gokml.PolyStyle(gokml.Color(lc(63))),
).WithID("FlightStyle")
lineString := gokml.LineString(
gokml.AltitudeMode(gokml.AltitudeModeAbsolute),
gokml.Extrude(pb.Extrude),
gokml.Coordinates(coordinates...),
)
flightLine := gokml.Placemark(
gokml.StyleURL("#FlightStyle"),
lineString,
)
mainFolder := gokml.Folder(
gokml.Name("Path Track"),
gokml.Description("Visible flight path, optionally extruded to the ground"),
flightStyle,
flightLine,
)
return &KmlProduct{Root: mainFolder}, nil
}