Debian Codegraph @

cylc/flow/etc/tutorial/consolidation-tutorial/lib/template/map.html

raw
1 <html>
2
3 <head>
4 <meta name="referrer" content="strict-origin-when-cross-origin">
5 <link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css" />
6 <script src="https://unpkg.com/[email protected]/dist/leaflet.js"></script>
7 </head>
8
9 <body>
10 <div id="map" style="width:100%;height:100%; position: relative; z-index: 0;"></div>
11 <div style="position: absolute; bottom: 10px; left: 10px; background: rgba(255, 255, 255, 0.7); padding: 5px; border-radius: 5px; font-size: 12px; z-index: 1000;">
12 <a href="https://www.openstreetmap.org/copyright" target="_blank" style="text-decoration: none; color: #000;">
13 © OpenStreetMap contributors
14 </a>
15 </div>
16
17 <script type="text/javascript">
18 // Define the colours to display for the different rainfall values.
19 // NOTE: Rainfall values range from 0 to 6+.
20 function get_colour(value) {
21 if (value < 0.1)
22 return '#ffffff88';
23 if (value < 0.5)
24 return '#00F7FF';
25 if (value < 1)
26 return '#00AAFF';
27 else if (value < 2)
28 return '#0051FF';
29 else if (value < 3)
30 return '#6600FF';
31 else if (value < 4)
32 return '#AE00FF';
33 else if (value < 5)
34 return '#FF00EA';
35 else
36 return '#FF0055';
37 }
38
39 // Forecast data as dict {'lead_time': [2d data matrix]}.
40 var data = {{ data }};
41
42 // Annotate map with data.
43 var lng;
44 var lat;
45 var rects;
46 var times = [];
47 var layers = [];
48 for (let time in data) {
49 rects = L.layerGroup();
50 for (let pos_y in data[time]) {
51 for (let pos_x in data[time][0]) {
52 lng = (pos_x * {{ resolution }}) + {{ lng1 }};
53 lat = {{ lat2 }} - (pos_y * {{ resolution }});
54 L.rectangle(
55 [
56 [lat, lng],
57 [lat + {{ resolution }}, lng + {{ resolution }}]
58 ], {
59 color: get_colour(data[time][pos_y][pos_x]),
60 weight: 0,
61 fillOpacity: 0.5
62 }).addTo(rects);
63 }
64 }
65 layers.push(rects);
66 times.push(time);
67 }
68
69 // Sort map layers lexicographically.
70 var sorted_times = times.slice(0); // Copy the times list.
71 var fcsts = {}; // {'lead_time': L.LayerGroup} Note dicts are ordered.
72 sorted_times.sort();
73 var ind;
74 for (let time of sorted_times) {
75 ind = times.indexOf(time);
76 fcsts[times[ind]] = layers[ind];
77 }
78
79 // Create map.
80 var map = L.map('map', {
81 layers: [fcsts[sorted_times[0]]]
82 });
83
84 // Zoom / center map to fit domain.
85 map.fitBounds([
86 [{{ lat1 }}, {{ lng1 }}],
87 [{{ lat2 }}, {{ lng2 }}]
88 ]);
89
90 // Add map tiles.
91 map.addLayer(
92 L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png'));
93
94 // Add layer selector.
95 L.control.layers(fcsts).addTo(map);
96 </script>
97 </body>
98
99 </html>