-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsketch.js
99 lines (85 loc) · 2.65 KB
/
sketch.js
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
/* -----------
Google Maps demo.
Visualizing 45,716 Meteorite Landings.
Data from NASA's Open Data Portal.(https://data.nasa.gov/Space-Science/Meteorite-Landings/gh4g-9sfh)
----------- */
// API Key for Google Maps. Get one here:
// https://developers.google.com/maps/web/
let key = 'AI za Sy Cp gu aF Mz dz 0e BV 16 nA W5 rq uP 8A aH tt zY A'
// Style for Google Maps. This is optional. More information here:
// https://mapstyle.withgoogle.com/
let style = [
{
"featureType": "road.arterial",
"stylers": [
{
"visibility": "off"
}
]
},
{
"featureType": "road.highway",
"elementType": "labels",
"stylers": [
{
"visibility": "off"
}
]
},
{
"featureType": "road.local",
"stylers": [
{
"visibility": "off"
}
]
}
]
// Options for map
let options = {
lat: -25.190994,
lng: 15.362848,
zoom: 8,
styles: style
}
// Create an instance of Google
let mappa = new Mappa('Google', key);
let myMap;
let canvas;
let meteorites;
function setup() {
canvas = createCanvas(window.innerWidth, window.innerHeight);
// Create a tile map and overlay the canvas on top.
myMap = mappa.tileMap(options);
myMap.overlay(canvas);
// Load the data
meteorites = loadTable('../../data/Meteorite_Landings.csv', 'csv', 'header');
// Only redraw the meteorites when the map change and not every frame.
myMap.onChange(drawMeteorites);
fill(207, 204, 0);
noStroke();
}
// The draw loop is fully functional but we are not using it for now.
function draw() {}
function drawMeteorites() {
// Clear the canvas
clear();
for (let i = 0; i < meteorites.getRowCount(); i++) {
// Get the lat/lng of each meteorite
let latitude = Number(meteorites.getString(i, 'reclat'));
let longitude = Number(meteorites.getString(i, 'reclong'));
// Only draw them if the position is inside the current map bounds. We use a
// Google Map method to check if the lat and lng are contain inside the current
// map. This way we draw just what we are going to see and not everything. See
// getBounds() in https://developers.google.com/maps/documentation/javascript/3.exp/reference
if (myMap.map.getBounds().contains({lat: latitude, lng: longitude})) {
// Transform lat/lng to pixel position
let pos = myMap.latLngToPixel(latitude, longitude);
// Get the size of the meteorite and map it. 60000000 is the mass of the largest
// meteorite (https://en.wikipedia.org/wiki/Hoba_meteorite)
let size = meteorites.getString(i, 'mass (g)');
size = map(size, 558, 60000000, 1, 25) + myMap.zoom();
ellipse(pos.x, pos.y, size, size);
}
}
}