-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
340 lines (312 loc) · 13.6 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
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
<html>
<head>
<title>CoastSat transects (including NZ)</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta charset="UTF-8">
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css"
integrity="sha256-p4NxAoJBhIIN+hmNHrzRCf9tD/miZyoHS5obTRR9BMY="
crossorigin=""/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/PapaParse/5.3.0/papaparse.min.js"></script>
<script src="https://unpkg.com/[email protected]/dist/leaflet.js"
integrity="sha256-20nQCchB9co0qIjJZRGuk2/Z9VM+kNiyxNV1lvTlZBo="
crossorigin=""></script>
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.draw.css"/>
<script src="https://unpkg.com/[email protected]/dist/leaflet.draw.js"></script>
<script src="https://unpkg.com/[email protected]/dist/glify-browser.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/spin.js/2.3.2/spin.min.js"></script>
<script src="https://unpkg.com/[email protected]/leaflet.spin.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"
integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script>
<script src="https://unpkg.com/leaflet-geosearch@latest/dist/bundle.min.js"></script>
<link rel="stylesheet" href="https://unpkg.com/leaflet-geosearch@latest/assets/css/leaflet.css">
<script src="https://unpkg.com/[email protected]/leaflet-providers.js"></script>
<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>
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css" rel="stylesheet">
<script src="
https://cdn.jsdelivr.net/npm/[email protected]/js/leaflet-sidebar.min.js
"></script>
<link href="
https://cdn.jsdelivr.net/npm/[email protected]/css/leaflet-sidebar.min.css
" rel="stylesheet">
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
<script async src="https://www.googletagmanager.com/gtag/js?id=G-LT8M0QZJES"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-LT8M0QZJES');
</script>
<style>
body,
html,
#map {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
}
.legend {
color: white;
padding: 10px;
background-color: rgba(0, 0, 0, 0.8);
border-radius: 5px;
max-width: 500px;
}
.legend i {
width: 18px;
height: 18px;
float: left;
margin-right: 8px;
opacity: 0.7;
clear: left;
}
.legend h4 {
margin-top: 0px;
}
.link {
text-decoration: underline;
cursor: pointer;
}
.fa {
line-height: inherit;
}
</style>
</head>
<body>
<div id="map"></div>
<div id="sidebar" class="leaflet-sidebar collapsed">
<!-- Nav tabs -->
<div class="leaflet-sidebar-tabs">
<ul role="tablist"> <!-- top aligned tabs -->
<li><a href="#home" role="tab"><i class="fa fa-bars"></i></a></li>
<li><a href="https://github.com/UoA-eResearch/CoastSat"><i class="fa fa-github"></i></a></li>
</ul>
</div>
<!-- Tab panes -->
<div class="leaflet-sidebar-content">
<div class="leaflet-sidebar-pane" id="home">
<div id="attribution">Code for shoreline detection provided by K. Vos, M. Harley and K. Splinter (University of New South Wales)<br>
<a href="https://www.unsw.edu.au/research/wrl/our-research/coastsat">https://www.unsw.edu.au/research/wrl/our-research/coastsat</a><br><br>
For more information about the technique:<br>
<a href="https://doi.org/10.1016/j.envsoft.2019.104528">Vos, K., Splinter, K.D., Harley, M.D., Simmons, J.A. and Turner, I.L., 2019. CoastSat: A Google Earth Engine-enabled Python toolkit to extract shorelines from publicly available satellite imagery. Environmental Modelling & Software, 122, p.104528.</a><br><br>
Data for New Zealand reprocessed by Nick Young, using the NIWA Tide API for tidal corrections. Shoreline position is corrected to the MSL. See <a href="https://github.com/UoA-eResearch/CoastSat/blob/main/README.MD">the README</a> for more information. You can download data for an individual site by clicking on a transect, or you can download everything from:<br> <a href="https://zenodo.org/doi/10.5281/zenodo.13835882"><img src="https://zenodo.org/badge/829830765.svg"></a><br>
If you have any questions about this data, please contact <a href="https://profiles.auckland.ac.nz/g-coco">Giovanni Coco</a><br><br>
If you would like to suggest a new site, please use the polyline tool on the left to draw a reference shoreline. Once you do so, you can click the below button to send your shoreline to us via email.<br>
<a id="mailto" target="_blank" class="btn btn-primary" disabled>Email Us</a>
</div>
</div>
</div>
<script>
var map = L.map('map', {
center: [-42, 172],
zoom: 6,
//worldCopyJump: true
})
var sidebar = L.control.sidebar({
autopan: false, // whether to maintain the centered map point when opening the sidebar
closeButton: true, // whether t add a close button to the panes
container: 'sidebar', // the DOM container or #ID of a predefined sidebar container that should be used
position: 'right', // left or right
}).addTo(map).open("home")
var baseMaps = {
"OSM": L.tileLayer.provider("OpenStreetMap.Mapnik"),
"CartoDB Positron": L.tileLayer.provider('CartoDB.Positron'),
"CartoDB Dark Matter": L.tileLayer.provider("CartoDB.DarkMatter"),
"ESRI WorldImagery": L.tileLayer.provider("Esri.WorldImagery").addTo(map),
"Google Hybrid": L.tileLayer('http://{s}.google.com/vt/lyrs=s,h&x={x}&y={y}&z={z}', {
maxZoom: 20,
subdomains: ['mt0', 'mt1', 'mt2', 'mt3']
})
}
var drawnItems = new L.FeatureGroup();
map.addLayer(drawnItems);
var options = {
position: 'topleft',
draw: {
polyline: {
shapeOptions: {
color: '#f357a1',
}
},
polygon: false,
rectangle: false,
marker: false,
circlemarker: false,
circle: false
},
edit: {
featureGroup: drawnItems,
remove: true
}
};
var drawControl = new L.Control.Draw(options);
map.addControl(drawControl);
function drawHandler() {
console.log(drawnItems.toGeoJSON())
$("#mailto").attr("href", "mailto:[email protected]?subject=Suggested new CoastSat NZ site&[email protected]&body=" + encodeURIComponent(JSON.stringify(drawnItems.toGeoJSON())))
$("#mailto").removeAttr("disabled")
}
map.on(L.Draw.Event.CREATED, function (e) {
console.log("created", e)
e.layer.addTo(drawnItems)
drawHandler();
});
map.on(L.Draw.Event.EDITED, function (e) {
console.log("edited", e)
drawHandler();
});
var overlayMaps = {
"Drawn items": drawnItems
}
L.control.layers(baseMaps, overlayMaps, { position: "topleft" }).addTo(map);
var cmap = chroma.scale('RdYlBu').domain([-3, 3])
map.spin(true);
$.getJSON("transects_extended.geojson", function (geojson) {
console.log(geojson)
const hidden = ["nzd0285", "nzd0284", "nzd0282"]
geojson.features = geojson.features.filter(f => !hidden.includes(f.properties.site_id))
console.log(geojson)
for (var f of geojson.features) {
for (var c of f.geometry.coordinates) {
if (c[0] < 0) c[0] += 360
}
}
L.glify.longitudeFirst()
L.glify.lines({
map: map,
data: geojson,
color: function(index, feature) {
if (feature.properties.n_points_nonan < 10) {
return {r:0, g:0, b:0}
}
var c = cmap(feature.properties.trend).gl()
return { r: c[0], g: c[1], b: c[2] };
},
click: function (e, feature) {
$("#plot").remove()
if (window.popup) map.closePopup(window.popup)
var p = feature.properties
var g = feature.geometry.coordinates
if (p.site_id.startsWith("nzd")) {
var url = `data/${p.site_id}/transect_time_series_tidally_corrected.csv`
} else {
var url = `shoreline_data_run6/${p.site_id}/time_series_tidally_corrected.csv`
}
const urlParams = new URLSearchParams(window.location.search);
const debug = urlParams.has('debug') && p.site_id.startsWith("nzd");
window.popup = L.popup({minWidth: 800})
.setContent(`<b>${p.id}</b><br>
along_dist: ${p.along_dist?.toFixed(2)}<br>
along_dist_norm: ${p.along_dist_norm?.toFixed(2)}<br>
origin point (landward): ${g[0][1].toFixed(6)},${g[0][0].toFixed(6)}<br>
destination point (seaward): ${g[1][1].toFixed(6)},${g[1][0].toFixed(6)}<br>
beach_slope: ${p.beach_slope}<br>
n_points: ${p.n_points}<br>
n_points_nonan: ${p.n_points_nonan}<br>
orientation: ${p.orientation?.toFixed(2)}<br>
trend: ${p.trend?.toFixed(2)} m/year<br>
R² score: ${p.r2_score?.toFixed(2)} ${p.r2_score < .05 ? " score < 0.05 - linear trend might not be reliable" : ""}<br>
mae: ${p.mae?.toFixed(2)}<br>
mse: ${p.mse?.toFixed(2)}<br>
rmse: ${p.rmse?.toFixed(2)}<br>
site: ${p.site_id}<br>
<a href="${url}" target="_blank" class="link">Download time series for ${p.site_id}</a><br>
${debug ? `<img id="img" style='height: 100%; width: 100%; object-fit: contain'>` : ""}
<div id="plot"></div>
`)
.setLatLng(e.latlng)
.addTo(map);
Papa.parse(url, {
download: true,
header: true,
dynamicTyping: true,
skipEmptyLines: true,
complete: function(results) {
console.log(results)
var filtered_data = results.data.filter(d => d[p.id])
var dates = filtered_data.map(d => d.dates)
var values = filtered_data.map(d => d[p.id])
var satname = filtered_data.map(d => d.satname)
var mean = Plotly.d3.mean(values)
values = values.map(v => v ? v - mean : v)
console.log(dates,values)
var min_date = new Date(results.data[0].dates)
var max_date = new Date(results.data[results.data.length - 1].dates)
var datediff = (max_date - min_date) / 1000 / 60 / 60 / 24 / 365.25
var data = [{
type: "scatter",
mode: "lines+markers",
name: "chainage",
x: dates,
y: values,
//line: {color: '#17BECF'}
}, {
type: "line",
x: [min_date, max_date],
y: [p.intercept - mean, p.trend * datediff + p.intercept - mean],
name: "trendline"
}];
var layout = {
title: `Time series for ${p.id}`,
xaxis: {
title: "Date/Time"
},
yaxis: {
title: "cross-shore change [m]",
hoverformat: '.1f'
}
};
Plotly.newPlot("plot", data, layout);
var px = map.project(e.latlng);
console.log(px)
px.y -= 400;
map.panTo(map.unproject(px),{animate: true});
if (debug) {
$("#plot").on('plotly_hover plotly_click', function(event, data){
console.log(data)
var d = data.points[0].x;
console.log(`Hovered on ${d}`)
var dt = dates[data.points[0].pointIndex].replace("+00:00", "").replace(/[ :]/g,"-");
var sat = satname[data.points[0].pointIndex]
var plot_url = `https://wave.storm-surge.cloud.edu.au/CoastSat_data/${p.site_id}/jpg_files/detection/${dt}_${sat}.jpg`
console.log(plot_url)
$("#img").attr("src", plot_url);
})
}
}
})
},
sensitivity: .0001
});
map.spin(false);
});
var geoSearch = new GeoSearch.GeoSearchControl({
provider: new GeoSearch.OpenStreetMapProvider(),
style: 'button',
autoComplete: true,
autoCompleteDelay: 250,
autoClose: true,
position: "topleft"
}).addTo(map);
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>"
for (var i = -3; i <= 3; i++) {
var prefix = ""
if (i == -3) {
prefix = "≤ "
} else if (i == 3) {
prefix = "≥ "
}
div.innerHTML += `<i style="background:${cmap(i).css()}"></i>${prefix + i}<br>`
}
div.innerHTML += `<i style="background:black"></i>Uncertain<br>`
return div;
};
legend.addTo(map);
</script>
</body>
</html>