summaryrefslogtreecommitdiff
path: root/templates/route_map.html.ep
blob: 22d376871391280a72c7e459cbeb7a2370034d5c (plain)
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
% if ($origin and $destination) {
	<div class="container" style="margin-top: 1ex; margin-bottom: 1ex;">
	Fahrt
	% if (stash('train_no')) {
		<strong><%= stash('train_no') %></strong>
	% }
	von <strong><%= $origin->{name} %></strong>
	nach <strong><%= $destination->{name} %></strong>
	% if (my $next = stash('next_stop')) {
		<br/>
		% if ($next->{type} eq 'present' and $next->{station}{dep} and $next->{station}{arr}) {
			Aufenthalt in <strong><%= $next->{station}{name} %></strong>
			an Gleis <strong><%= $next->{station}{platform} %></strong>
			bis <strong><%= $next->{station}{dep}->strftime('%H:%M') %></strong>
			% if ($next->{station}{dep_delay}) {
				%= sprintf('(%+d)', $next->{station}{dep_delay})
			% }
		% }
		% elsif ($next->{type} eq 'present' and $next->{station}{dep}) {
			Abfahrt in <strong><%= $next->{station}{name} %></strong>
			von Gleis <strong><%= $next->{station}{platform} %></strong>
			um <strong><%= $next->{station}{dep}->strftime('%H:%M') %></strong>
			% if ($next->{station}{dep_delay}) {
				%= sprintf('(%+d)', $next->{station}{dep_delay})
			% }
		% }
		% elsif ($next->{type} eq 'present' and $next->{station}{arr}) {
			Endstation erreicht um
			<strong><%= $next->{station}{arr}->strftime('%H:%M') %></strong>
			auf Gleis <strong><%= $next->{station}{platform} %></strong>
			% if ($next->{station}{arr_delay}) {
				%= sprintf('(%+d)', $next->{station}{arr_delay})
			% }
		% }
		% elsif ($next->{type} eq 'present') {
			Zug steht in
			<strong><%= $next->{station}{arr}->strftime('%H:%M') %></strong>
			auf Gleis <strong><%= $next->{station}{platform} %></strong>
		% }
		% elsif ($next->{type} eq 'next' and $next->{station}{arr}) {
			Nächster Halt:
			<strong><%= $next->{station}{name} %></strong>
			um <strong><%= $next->{station}{arr}->strftime('%H:%M') %></strong>
			% if ($next->{station}{arr_delay}) {
				%= sprintf('(%+d)', $next->{station}{arr_delay})
			% }
			auf Gleis <strong><%= $next->{station}{platform} %></strong>
		% }
		% elsif ($next->{type} eq 'next') {
			Nächster Halt:
			<strong><%= $next->{station}{name} %></strong>
			auf Gleis <strong><%= $next->{station}{platform} %></strong>
		% }
	% }
	</div>
% }

<div class="container">
		<div id="map" style="height: 500px;">
		</div>
	</div>

<script>
var map = L.map('map').setView([51.306, 9.712], 6);

L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
  attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);
var stations = [
% for my $station ( @{stash('station_coordinates') // [] } ) {
[[<%= $station->[0][0] %>,<%= $station->[0][1] %>],['<%== join("','", map { Mojo::Util::xml_escape($_) } @{$station->[1]}) %>']],
% }
];

var routes = [];
var pl;
% for my $line_group ( @{ stash('polyline_groups') // [] } ) {
	routes = [
		% for my $pair ( @{$line_group->{polylines} // []} ) {
			[[<%= $pair->[0][0] %>,<%= $pair->[0][1] %>],[<%= $pair->[1][0] %>,<%= $pair->[1][1] %>]],
		% }
	];
	pl = L.polyline(routes, {color: '<%= $line_group->{color} %>', opacity: <%= $line_group->{opacity} %>}).addTo(map);
	% if ($line_group->{fit_bounds}) {
		if (routes.length) {
			map.fitBounds(pl.getBounds());
		}
	% }
% }

for (var station_id in stations) {
	L.circle(stations[station_id][0], {
		color: '#f03',
		opacity: 0.7,
		fillColor: '#f03',
		fillOpacity: 0.5,
		radius: 250
	}).bindPopup(stations[station_id][1].join('<br/>')).addTo(map);
}

var greenIcon = new L.Icon({
  iconUrl: '/static/leaflet/images/marker-icon-2x-green.png',
  shadowUrl: '/static/leaflet/images/marker-shadow.png',
  iconSize: [25, 41],
  iconAnchor: [12, 41],
  popupAnchor: [1, -34],
  shadowSize: [41, 41]
});

var goldIcon = new L.Icon({
  iconUrl: '/static/leaflet/images/marker-icon-2x-gold.png',
  shadowUrl: '/static/leaflet/images/marker-shadow.png',
  iconSize: [25, 41],
  iconAnchor: [12, 41],
  popupAnchor: [1, -34],
  shadowSize: [41, 41]
});

var marker;
% for my $marker (@{stash('markers') // [] } ) {
	% if ($marker->{icon}) {
		marker = L.marker([<%= $marker->{lat} %>,<%= $marker->{lon} %>], {icon: <%= $marker->{icon} %>}).addTo(map);
	% }
	% else {
		marker = L.marker([<%= $marker->{lat} %>,<%= $marker->{lon} %>]).addTo(map);
	% }
	% if ($marker->{title}) {
		marker.bindPopup('<%= $marker->{title} %>');
	% }
% }

</script>

<div class="container" style="margin-top: 1ex; margin-bottom: 1ex; color: #555;">
Die Zugposition auf der Karte ist eine Schätzung und kann erheblich von der
tatsächlichen Position des Zugs abweichen.
Live-Tracking mit automatischer Kartenaktualisierung wird noch nicht
unterstützt.
</div>

% if (my $op = stash('operator')) {
<div class="container" style="margin-top: 1ex; margin-bottom: 1ex; color: #555;">
Betrieb: <%= $op %>
</div>
% }