trip_map.templ
1package components
2
3import (
4 "git.kilimanjaro.io/rtw/document"
5 "math"
6)
7
8func updateBbox(bbox [4]float64, update []float64) [4]float64 {
9 switch len(update) {
10 case 2:
11 bbox[0] = math.Min(bbox[0], update[0])
12 bbox[1] = math.Min(bbox[1], update[1])
13 bbox[2] = math.Max(bbox[2], update[0])
14 bbox[3] = math.Max(bbox[3], update[1])
15 return bbox
16 case 4:
17 // split into recursive update, one point at a time
18 return updateBbox(updateBbox(bbox, update[0:2]), update[2:])
19 default:
20 return bbox
21 }
22}
23
24func getBbox(waypoints []document.WaypointAttrs) [4]float64 {
25 if len(waypoints) == 0 {
26 return [4]float64{-130, -32, 130, 62}
27 }
28 bbox := [4]float64{180, 90, -180, -90}
29 for _, wp := range waypoints {
30 bbox = updateBbox(bbox, wp.Point)
31 for _, route := range wp.From {
32 bbox = updateBbox(bbox, route.Bbox)
33 }
34 }
35 return bbox
36}
37
38templ TripMap(styleURL string, waypoints []document.WaypointAttrs, color string) {
39 @Map(styleURL, getBbox(waypoints), "rounded-xl shadow-md w-full h-full") {
40 for _, wp := range waypoints {
41 for _, route := range wp.From {
42 @Route(route.ID, color)
43 }
44 }
45 }
46}