-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmap.js
73 lines (57 loc) · 2.65 KB
/
map.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
//Leaflet Documentation https://docs.eegeo.com/eegeo.js/v0.1.730/docs/leaflet/
//Graph Documentation https://developers.arcgis.com/esri-leaflet/samples/dynamic-chart/
import { getAllSites, latestOfSet, getSitesData } from './data.js';
import { createColorLegend, updateTime, updateAOD, getStartEndDateTime } from './components.js';
import { MarkerManager } from './marker.js';
import { initMap } from './init.js';
import { FieldInitializer } from './fields.js';
// Declare variables
let map = null;
let markerLayer = null;
let initFields = null;
let colorLegend = null;
let args = null;
let defaultDate = null;
let site_data = null;
let all_site_data = null;
let optical_depth = 'AOD_500nm'; // to be set by drop menu
// Function to initialize the map
async function initializeMap() {
if (!map) {
map = initMap();
}
// map = initMap();
defaultDate = getStartEndDateTime();
let year, month, day, previousHr, hour, bufferHr, minute,previousYear, previousMonth, previousDay
if (defaultDate.length === 2) {
[year, month, day] = defaultDate[0].map(Number);
[previousHr, hour, bufferHr, minute] = defaultDate[1].map(Number);
args = `?year=${year}&month=${month}&day=${day}&year2=${year}&month2=${month}&day2=${day}&hour=${previousHr}&hour2=${bufferHr}&AOD15=1&AVG=10&if_no_html=1`;
} else if (defaultDate.length === 3) {
[previousYear, previousMonth, previousDay] = defaultDate[0].map(Number);
[year, month, day] = defaultDate[1].map(Number);
[previousHr, hour, bufferHr, minute] = defaultDate[2].map(Number);
args = `?year=${previousYear}&month=${previousMonth}&day=${previousDay}&year2=${year}&month2=${month}&day2=${day}&hour=${previousHr}&hour2=${bufferHr}&AOD15=1&AVG=10&if_no_html=1`;
}
site_data = await getSitesData(args, 10, defaultDate); // passing default args and (realtime = 10)
all_site_data = await getAllSites(year);
colorLegend = createColorLegend(optical_depth);
colorLegend.addTo(map);
updateAOD(optical_depth);
updateTime(defaultDate);
markerLayer = new MarkerManager(map, args);
markerLayer.addMarker(latestOfSet(site_data), optical_depth);
markerLayer.addInactiveMarker(all_site_data, optical_depth);
// Build fields
initFields = new FieldInitializer(site_data, all_site_data, optical_depth, map, markerLayer, defaultDate, colorLegend);
markerLayer.fieldsClass = initFields;
// Set center and default zoom
map.setView([0, 0], 1);
initFields.addTermToMap()
// Slightly improves tile loading
setTimeout(function() {
map.invalidateSize();
}, 500);
}
// Call the initializeMap function
initializeMap();