-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmap2.ego
69 lines (68 loc) · 3.05 KB
/
map2.ego
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
65
66
67
68
69
<%
package main
import "github.com/tkrajina/gpxgo/gpx"
import "fmt"
import "time"
func (m *Map) renderLines(w io.Writer, t *Track) {
%>
<svg version="1.1" xmlns="http://www.w3.org/2000/svg"
width="<%= m.w %>" height="<%= m.h %>" viewBox="0 0 <%= m.w %> <%= m.h %>">
<style type="text/css" >
<![CDATA[
.segment { fill: none; stroke-width: 4 }
.segment:hover { stroke-width: 8 }
]]>
</style>
<g id="legend">
<% for i := range palette { %>
<rect x="<%= 30*i %>" y="0" width="30" height="20" fill="<%= fmt.Sprintf("#%03x",palette[i]) %>"/>
<rect x="<%= 30*i %>" y="<%= m.h-20 %>" width="30" height="20" fill="<%= fmt.Sprintf("#%03x",palette[i]) %>"/>
<% } %>
<% for i := 0; i < len(palette); i += 5 { %>
<text x="<%= 30*i+5 %>" y="16" fill="white"><%= fmt.Sprint(i) %>kts</text>
<text x="<%= 30*i+5 %>" y="<%= m.h-4 %>" fill="white"><%= fmt.Sprint(i) %>kts</text>
<% } %>
</g>
<% totalDistance := float64(0)
var lastPoint *gpx.GPXPoint
for _, segment := range t.Segments {
%>
<g class="segment">
<% if lastPoint != nil {
prev, next := lastPoint, &segment.gpx.Points[0]
x1, y1 := m.Point(prev)
x2, y2 := m.Point(next)
c := m.SpeedColor(prev, next)
totalDistance += m.Distance(prev,next,nm)
heading := m.Heading(prev, next)
direction := Direction(heading).String()
timestamp := next.Timestamp.In(t.Timezone()).Format(time.TimeOnly)
distance := fmt.Sprintf("%0.1f m", m.Distance(prev,next,meter))
speed := fmt.Sprintf("%0.1f kts", m.Speed(prev,next,nm))
headingAndDirection := fmt.Sprintf("%d\u00b0 %s", heading, direction )
%>
<line class="step" x1="<%= x1 %>" y1="<%= y1 %>" x2="<%= x2 %>" y2="<%= y2 %>" stroke="<%= c %>">
<title> <%= timestamp %>: <%= distance %> @ <%= speed %> ↑ <%= headingAndDirection %> = <%= fmt.Sprintf("%0.2f nm", totalDistance) %></title>
</line>
<% } %>
<% segment.gpxEachPair(func(prev, next *gpx.GPXPoint) {
lastPoint = next
x1, y1 := m.Point(prev)
x2, y2 := m.Point(next)
c := m.SpeedColor(prev, next)
totalDistance += m.Distance(prev,next,nm)
heading := m.Heading(prev, next)
direction := Direction(heading).String()
timestamp := next.Timestamp.In(t.Timezone()).Format(time.TimeOnly)
distance := fmt.Sprintf("%0.1f m", m.Distance(prev,next,meter))
speed := fmt.Sprintf("%0.1f kts", m.Speed(prev,next,nm))
headingAndDirection := fmt.Sprintf("%d\u00b0 %s", heading, direction )
%>
<line class="step" x1="<%= x1 %>" y1="<%= y1 %>" x2="<%= x2 %>" y2="<%= y2 %>" stroke="<%= c %>">
<title> <%= timestamp %>: <%= distance %> @ <%= speed %> ↑ <%= headingAndDirection %> = <%= fmt.Sprintf("%0.2f nm", totalDistance) %></title>
</line>
<% }) %>
</g>
<% } %>
</svg>
<% } %>