-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathwind-direction-arrows.html
More file actions
61 lines (58 loc) · 2.11 KB
/
wind-direction-arrows.html
File metadata and controls
61 lines (58 loc) · 2.11 KB
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
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.0.3/dist/leaflet.css"/>
<style>
#map {
bottom: 0;
left: 0;
position: absolute;
right: 0;
top: 0;
}
</style>
</head>
<body>
<div id="map"></div>
<script src="https://unpkg.com/leaflet@1.0.3/dist/leaflet.js"></script>
<script src="https://unpkg.com/georaster"></script>
<script src="https://unpkg.com/georaster-layer-for-leaflet"></script>
<script>
// initalize leaflet map
var map = L.map('map').setView([0, 0], 5);
// add OpenStreetMap basemap
L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
attribution: '© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);
var url_to_geotiff_file = "https://georaster-layer-for-leaflet.s3.amazonaws.com/wind_direction.tif";
fetch(url_to_geotiff_file)
.then(response => response.arrayBuffer())
.then(arrayBuffer => {
parseGeoraster(arrayBuffer).then(georaster => {
var layer = new GeoRasterLayer({
georaster,
customDrawFunction: function({ context, x, y, width, height, values }) {
// from https://github.com/stuartmatthews/leaflet-geotiff/blob/master/leaflet-geotiff-vector-arrows.js
var value = values[0];
var arrowSize = width / 2.5;
context.save();
context.translate(x, y);
context.rotate((90+value)*Math.PI/180);
context.beginPath();
context.moveTo(-arrowSize/2, 0);
context.lineTo(+arrowSize/2, 0);
context.moveTo(arrowSize*0.25, -arrowSize*0.25);
context.lineTo(+arrowSize/2, 0);
context.lineTo(arrowSize*0.25, arrowSize*0.25);
context.stroke();
context.restore();
}
});
layer.addTo(map);
map.fitBounds(layer.getBounds());
});
});
</script>
</body>
</html>