-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscript.js
More file actions
67 lines (58 loc) · 1.59 KB
/
script.js
File metadata and controls
67 lines (58 loc) · 1.59 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
62
63
64
65
66
67
mapboxgl.accessToken = 'pk.eyJ1IjoiZ2xvYmFsLWRhdGEtdmlld2VyIiwiYSI6ImNqdG9lYWQ3NTFsNWk0M3Fqb2Q5dXBpeWUifQ.3DvxuGByM33VNa59rDogWw';
var map = new mapboxgl.Map({
container: 'map',
style: 'mapbox://styles/mapbox/dark-v10',
center: [0, 0],
zoom: 1
});
function getJSON(url, callback) {
const xhr = new XMLHttpRequest();
xhr.responseType = 'json';
xhr.open('get', url, true);
xhr.onload = function () {
if (xhr.status >= 200 && xhr.status < 300) {
callback(xhr.response);
} else {
throw new Error(xhr.statusText);
}
};
xhr.send();
}
function newSource(newCanvas, data, coords, colorRamp){
function updateWind(windFile) {
getJSON('./wind/' + windFile + '.json', function (windData) {
const windImage = new Image();
windData.image = windImage;
windImage.src = './wind/' + windFile + '.png';
windImage.onload = function () {
wind.setWind(windData);
};
});
}
function frame() {
if (wind.windData) {
wind.draw();
// wind.getOutOfDomain()
}
requestAnimationFrame(frame);
}
var canvas = document.getElementById(newCanvas);
var gl = canvas.getContext('webgl', {antialiasing: true});
var wind = new WindGL(gl, colorRamp);
wind.fadeOpacity = 0.7;
wind.numParticles = 10000;
updateWind(data);
map.addSource(newCanvas, {
type: 'canvas',
canvas: newCanvas,
animate: true,
coordinates: coords
});
map.addLayer({
"id": "overlay" + newCanvas,
"source": newCanvas,
"type": "raster",
"paint": {"raster-opacity": 0.7}
})
frame();
}