-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
78 lines (61 loc) · 2.07 KB
/
index.html
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
<!doctype html>
<html>
<head>
<title>GFS Winds on Leaflet Canvas</title>
<meta charset="utf-8">
<style>
html, body, #map {
height:100%;
width:100%;
padding:0px;
margin:0px;
}
</style>
</head>
<body>
<div id="map"></div>
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.7.2/leaflet.css" />
<script src="http://cdn.leafletjs.com/leaflet-0.7.2/leaflet.js"></script>
<script src="http://code.jquery.com/jquery-1.11.2.min.js"></script>
<script src="L.CanvasOverlay.js"></script>
<script src="windy.js"></script>
<script>
var map = L.map('map').setView([35, -75], 4);
L.tileLayer("http://{s}.sm.mapstack.stamen.com/(toner-lite,$fff[difference],$fff[@23],$fff[hsl-saturation@20])/{z}/{x}/{y}.png")
.addTo(map);
$.getJSON('gfs.json').done(function(result) {
var timer = null;
//Add CanvasLayer to the map
canvasOverlay = L.canvasOverlay()
.drawing(redraw)
.addTo(map);
//windy object
windy = new Windy({canvas: canvasOverlay.canvas(), data: result});
//prepare context global var
context = canvasOverlay.canvas().getContext('2d');
//start drawing wind map
function redraw(overlay, params) {
if( timer )
window.clearTimeout( timer );
timer = setTimeout(function() { //showing wind is delayed
var bounds = map.getBounds();
var size = map.getSize();
/*context.rect(0,0,3000,3000);
context.fillStyle = "red";
context.fill();*/
windy.start( [[0,0],[size.x, size.y]], size.x, size.y,
[[bounds._southWest.lng, bounds._southWest.lat ],[bounds._northEast.lng, bounds._northEast.lat]] );
},750)
}
//clear canvas and stop animation
function clearWind() {
windy.stop();
context.clearRect(0,0,3000, 3000);
}
map.on('dragstart', function() { clearWind() });
map.on('zoomstart', function() { clearWind() });
map.on('resize', function() { clearWind() });
})
</script>
</body>
</html>