-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
325 lines (300 loc) · 11.2 KB
/
index.html
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
<!DOCTYPE html>
<html>
<head>
<title>New Zealand Coastal Landcover Change</title>
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css"
integrity="sha256-p4NxAoJBhIIN+hmNHrzRCf9tD/miZyoHS5obTRR9BMY="
crossorigin=""/>
<!-- Make sure you put this AFTER Leaflet's CSS -->
<script src="https://unpkg.com/[email protected]/dist/leaflet.js"
integrity="sha256-20nQCchB9co0qIjJZRGuk2/Z9VM+kNiyxNV1lvTlZBo="
crossorigin=""></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<!-- Chroma for colour scheme -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/chroma-js/2.4.2/chroma.min.js"
integrity="sha512-zInFF17qBFVvvvFpIfeBzo7Tj7+rQxLeTJDmbxjBz5/zIr89YVbTNelNhdTT+/DCrxoVzBeUPVFJsczKbB7sew=="
crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
<style>
html,
body,
#map {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
}
.info {
padding: 6px 8px;
font: 11px/12px Arial, Helvetica, sans-serif;
background: white;
background: rgba(255,255,255,0.8);
box-shadow: 0 0 15px rgba(0,0,0,0.2);
border-radius: 5px;
}
.info h4 {
margin: 0 0 5px;
color: #777;
}
.info table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
.info th, td {
padding: 10px;
}
.legend {
padding: 10pv;
line-height: 18px;
border-radius: 5px;
max-width: 250px;
color: #555;
}
.legend i {
width: 18px;
height: 18px;
float: left;
margin-right: 8px;
opacity: 0.7;
clear: left;
}
#title {
position: absolute;
top: 30px;
left: 0;
right: 0;
margin: auto;
z-index: 1000;
width: 50%;
text-align: center;
color: white;
border-radius: 5px;
padding: 10px;
background-color: rgba(0, 0, 0, 0.8);
font-family: Arial, Helvetica, sans-serif;
text-shadow: 2px 2px #000000;
font-weight: normal;
font-size: 1rem;
}
</style>
</head>
<body>
<!-- <h1 id="title">New Zealand Coastal Landcover Change</h1> -->
<div id="map"></div>
<script type="text/javascript">
var mymap = L.map('map').setView([-41, 172], 5);
L.tileLayer('https://basemaps.linz.govt.nz/v1/tiles/aerial/WebMercatorQuad/{z}/{x}/{y}.webp?api=c01hevnqk6vravw5jx6tw7xw9zx', {
attribution: 'Map data © <a href="">OpenStreetMap</a> contributors, ' +
'<a href="https://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, ' +
'Imagery © <a href="https://www.mapbox.com/">Mapbox</a>',
maxZoom: 18
}).addTo(mymap);
// define style for cells - colour scheme from chroma
var cmap = chroma.scale("RdYlGn").domain([-5, 5]);
function style(feature) {
return {
fillColor: cmap(feature.properties["IW shoreline trend"]),
weight: 1,
opacity: 1,
color: 'black',
fillOpacity: 0.7
}}
// get HR5 geojson and add to map
var cells = $.getJSON("shoreline_trends_by_cell.geojson", function (HR5geojson) {
console.log(HR5geojson)
L.geoJSON(HR5geojson, {
style:style,
onEachFeature:onEachFeature
}).addTo(mymap)
});
// define plots as popup
function onEachFeature(feature, layer) {
layer.on('click', function() {
var id = feature.properties.index // get cell trend data
var p = feature.properties // get properties to get trend line
console.log(id)
layer.unbindPopup(); // Unbind any existing popup
var popupContent = L.popup({
minWidth: 1200,
minHeight: 1000,
}).setContent(`
<h3>${id}<h3>
<div id="shPlot"></div>
<div id="lcPlot"></div>
`);
layer.bindPopup(popupContent).openPopup();
// Calculate the center of the bounds
var center = layer.getBounds().getCenter();
// Offset the center to account for the popup's dimensions
var offset = mymap.getSize().y * 0.5; // Adjust this value as needed
var target = mymap.project(center).subtract([0, offset]);
mymap.panTo(mymap.unproject(target), {
animate: true,
duration: 1.0
});
makeShorelinePlot(id, p)
makeLandcoverPlot(id);
});
}
// define landcover plot
function makeLandcoverPlot(cellId, layer) {
var lc_url = `data/HR5/${cellId}/landcover_timeseries_percentage_change.csv`
Plotly.d3.csv(lc_url, function(data) {processData(data)});
function processData(allRows) {
console.log(allRows);
var x = [], sand = [], vegetation = [], water = [];
for (var i=0; i<allRows.length; i++) {
row = allRows[i]
x.push (row['date']);
sand.push (row['sand_area_percentage_change']);
vegetation.push (row['vegetation_area_percentage_change']);
water.push (row['water_area_percentage_change'])
}
console.log('x',x, 'sand',sand, 'vegetation',vegetation, 'water',water);
var data = [{
type: "scatter",
mode: "lines+markers",
name: "Sediment",
x: x,
y: sand,
line: {color: '#FFC300'}
}, {
type: "scatter",
mode: "lines+markers",
name: "Vegetation",
x: x,
y: vegetation,
line: {color: '#008000'},
}, {
type: "scatter",
mode: "lines+markers",
name: "Water",
x: x,
y: water,
line: {color: '#0000FF'},
}];
var layout = {
// font: {
// family: 'Courier New, monospace',
// size: 12
// },
title: `Landcover percentage change`,
autosize: true,
//height: 350,
automargin: true,
xaxis: {
title: "Date/Time"
},
yaxis: {
title: "Change (%)",
hoverformat: '.2f'
},
legend: {
"orientation": "h",
x: 0.5,
y: 1,
xanchor: 'center',
yanchor: 'bottom'
}};
Plotly.newPlot('lcPlot', data, layout)
};
};
function makeShorelinePlot(cellId, properties) {
var sh_url = `data/HR5/${cellId}/shoreline_timeseries_tidal_correction.csv`
Plotly.d3.csv(sh_url, function(data) {processData(data)});
function processData(allRows) {
console.log(allRows);
var x = [], iw = [], eov = [];
for (var i=0; i<allRows.length; i++) {
row = allRows[i]
x.push (row['date']);
iw.push (row['normalised_IW_shoreline_position']);
eov.push (row['normalised_EOV_shoreline_position']);
}
var iw_mean = Plotly.d3.mean(iw)
var eov_mean = Plotly.d3.mean(eov)
// get min/max date
var min_date = new Date(x[0])
var max_date = new Date(x[x.length - 1])
var datediff = (max_date - min_date) / 1000 / 60 / 60 / 24 / 365.25
console.log('x',x, 'iw',iw, 'eov',eov);
var data = [{
type: "scatter",
mode: "lines+markers",
name: "Instantaneous Waterline",
x: x,
y: iw,
line: {color: '#FFC300'}
}, {
type: "scatter",
mode: "lines",
name: "Instantaneous Waterline trendline",
x: [min_date, max_date],
y: [properties["IW shoreline intercept"], properties["IW shoreline trend"] * datediff + properties["IW shoreline intercept"] - iw_mean],
line: {color: '#FFC300'},
opacity: 0.5
}, {
type: "scatter",
mode: "lines+markers",
name: "Edge of Vegetation",
x: x,
y: eov,
line: {color: '#008000'},
}, {
type: "scatter",
mode: "lines",
name: "Edge of Vegetation trendline",
x: [min_date, max_date],
y: [properties["EOV shoreline intercept"], properties["EOV shoreline trend"] * datediff + properties["EOV shoreline intercept"] - eov_mean],
line: {color: '#008000', },
opacity: 0.5
}];
var layout = {
title: `Estimated shoreline proxy change`,
//font: {
// family: 'Courier New, monospace',
// size: 18
// },
autosize: true,
//height: 350,
automargin: true,
xaxis: {
title: "Date/Time"
},
yaxis: {
title: "Cross Shore Displacement (m)",
hoverformat: '.2f'
},
legend: {
"orientation": "h",
x: 0.5,
y: 1,
xanchor: 'center',
yanchor: 'bottom'
}};
Plotly.newPlot('shPlot', data, layout)
};
};
// define legend
var legend = L.control({position: 'bottomright'});
legend.onAdd = function (map) {
var div = L.DomUtil.create('div', 'info legend');
div.innerHTML += "<h4>Trend (m/year)<h4>"
// gen prefix for legend
for (var i = -5; i <= 5; i++) {
var prefix = ""
if (i == -5) {
prefix = "≤ "
} else if (i == 5) {
prefix = "≥ "
}
div.innerHTML += `<i style="background:${cmap(i).css()}"></i>${prefix + i}<br>`
}
// div.innerHTML += `<div id="attribution">This map shows coastal landcover change and estimated IW and EOV shoreline trends for each cells in New Zealand.<br>
// </div>`
return div;
};
legend.addTo(mymap);
</script>
</body>
</html>