forked from NOAA-CEFI-Portal/cefi-portal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lmesPlotlyMapbox.js
46 lines (41 loc) · 1.41 KB
/
lmesPlotlyMapbox.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
// read geojson and create plotly plot
readTextFile("lms_choropleth_mapbox.json", function(text){
var datajson = JSON.parse(text);
lmesPlotlyMapbox(datajson);
// auto-click the reset button to make the mapbox plot show normal view
var inputElement = document.querySelector('a[data-title="Reset view"]')
// first wait for 1 sec for plotly plot in modal to finish and assign the element
setTimeout(()=> {
inputElement = document.querySelector('a[data-title="Reset view"]')
}
,1000);
// reset button is clicked once the modal open (sufficient time out is necessary)
$('#lmeButton').on("click", function () {
setTimeout(()=> {
inputElement.click()
}
,500);
});
});
// function to read geojson
function readTextFile(file, callback) {
var rawFile = new XMLHttpRequest();
rawFile.overrideMimeType("application/json");
rawFile.open("GET", file, true);
rawFile.onreadystatechange = function() {
if (rawFile.readyState === 4 && rawFile.status == "200") {
callback(rawFile.responseText);
}
}
rawFile.send(null);
}
// plot the plotly figure
function lmesPlotlyMapbox(datajson) {
window.PLOTLYENV=window.PLOTLYENV || {};
if (document.getElementById("lmePlotting")) {
Plotly.newPlot(
"lmePlotting",
datajson
)
}
}