trip_map_templ.go
1// Code generated by templ - DO NOT EDIT.
2
3// templ: version: v0.3.1020
4package components
5
6//lint:file-ignore SA4006 This context is only used if a nested component is present.
7
8import "github.com/a-h/templ"
9import templruntime "github.com/a-h/templ/runtime"
10
11import (
12 "git.kilimanjaro.io/rtw/document"
13 "math"
14)
15
16func updateBbox(bbox [4]float64, update []float64) [4]float64 {
17 switch len(update) {
18 case 2:
19 bbox[0] = math.Min(bbox[0], update[0])
20 bbox[1] = math.Min(bbox[1], update[1])
21 bbox[2] = math.Max(bbox[2], update[0])
22 bbox[3] = math.Max(bbox[3], update[1])
23 return bbox
24 case 4:
25 // split into recursive update, one point at a time
26 return updateBbox(updateBbox(bbox, update[0:2]), update[2:])
27 default:
28 return bbox
29 }
30}
31
32func getBbox(waypoints []document.WaypointAttrs) [4]float64 {
33 if len(waypoints) == 0 {
34 return [4]float64{-130, -32, 130, 62}
35 }
36 bbox := [4]float64{180, 90, -180, -90}
37 for _, wp := range waypoints {
38 bbox = updateBbox(bbox, wp.Point)
39 for _, route := range wp.From {
40 bbox = updateBbox(bbox, route.Bbox)
41 }
42 }
43 return bbox
44}
45
46func TripMap(styleURL string, waypoints []document.WaypointAttrs, color string) templ.Component {
47 return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
48 templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
49 if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil {
50 return templ_7745c5c3_CtxErr
51 }
52 templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
53 if !templ_7745c5c3_IsBuffer {
54 defer func() {
55 templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer)
56 if templ_7745c5c3_Err == nil {
57 templ_7745c5c3_Err = templ_7745c5c3_BufErr
58 }
59 }()
60 }
61 ctx = templ.InitializeContext(ctx)
62 templ_7745c5c3_Var1 := templ.GetChildren(ctx)
63 if templ_7745c5c3_Var1 == nil {
64 templ_7745c5c3_Var1 = templ.NopComponent
65 }
66 ctx = templ.ClearChildren(ctx)
67 templ_7745c5c3_Var2 := templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
68 templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
69 templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
70 if !templ_7745c5c3_IsBuffer {
71 defer func() {
72 templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer)
73 if templ_7745c5c3_Err == nil {
74 templ_7745c5c3_Err = templ_7745c5c3_BufErr
75 }
76 }()
77 }
78 ctx = templ.InitializeContext(ctx)
79 for _, wp := range waypoints {
80 for _, route := range wp.From {
81 templ_7745c5c3_Err = Route(route.ID, color).Render(ctx, templ_7745c5c3_Buffer)
82 if templ_7745c5c3_Err != nil {
83 return templ_7745c5c3_Err
84 }
85 }
86 }
87 return nil
88 })
89 templ_7745c5c3_Err = Map(styleURL, getBbox(waypoints), "rounded-xl shadow-md w-full h-full").Render(templ.WithChildren(ctx, templ_7745c5c3_Var2), templ_7745c5c3_Buffer)
90 if templ_7745c5c3_Err != nil {
91 return templ_7745c5c3_Err
92 }
93 return nil
94 })
95}
96
97var _ = templruntime.GeneratedTemplate