-
Notifications
You must be signed in to change notification settings - Fork 1
/
lmesPlotlyMapbox.js
78 lines (70 loc) · 2.48 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
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
// Using fetch() to read the JSON file
fetch('lms_choropleth_mapbox.json')
.then(response => {
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response.json(); // Parse the JSON
})
.then(dataJson => {
// create the plotly plot
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);
});
})
.catch(error => {
console.error('There was a problem with the fetch operation:', error);
});
// plot the plotly figure
function lmesPlotlyMapbox(datajson) {
window.PLOTLYENV=window.PLOTLYENV || {};
if (document.getElementById("lmePlotting")) {
Plotly.newPlot(
"lmePlotting",
datajson
)
}
}
// // 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);
// }