-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
201 lines (182 loc) · 7 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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Retrolens alternative interface</title>
<meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no" />
<!-- Load Leaflet from CDN -->
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css"
integrity="sha512-xodZBNTC5n17Xt2atTPuE1HxjVMSvLVW9ocqUKLsCC5CXdbqCmblAshOMAS6/keqq/sMZMZ19scR4PsZChSR7A=="
crossorigin="" />
<script src="https://unpkg.com/[email protected]/dist/leaflet.js"
integrity="sha512-XQoYMqMTK8LvdxXYG3nZ448hOEQiglfqkJs1NOQV44cWnUrBc8PkAOcXy20w0vlaXaVUearIOBhiXZ5V3ynxwA=="
crossorigin=""></script>
<!-- Load Esri Leaflet from CDN -->
<script src="https://unpkg.com/[email protected]/dist/esri-leaflet.js"
integrity="sha512-q7X96AASUF0hol5Ih7AeZpRF6smJS55lcvy+GLWzJfZN+31/BQ8cgNx2FGF+IQSA4z2jHwB20vml+drmooqzzQ=="
crossorigin=""></script>
<script src="https://cdn.plot.ly/plotly-latest.min.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>
<style>
html,
body {
margin: 0;
padding: 0;
height: 100%;
width: 100%;
}
.legend {
color: white;
padding: 10px;
background-color: rgba(0, 0, 0, 0.8);
border-radius: 5px;
}
#map,
#timeline {
width: 100%;
height: 50%;
}
#title {
position: absolute;
top: 30;
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">Retrolens alternative interface</h1>
<div id="map"></div>
<div id="timeline"></div>
<script>
// Map
var map = L.map('map', {
zoom: 10,
minZoom: 6,
//maxZoom: 14,
center: { lat: -39.11407918425644, lng: 177.703857421875 }
});
var bounds = map.getBounds();
bounds._northEast.lat += 10;
bounds._northEast.lng += 10;
bounds._southWest.lat -= 10;
bounds._southWest.lng -= 10;
map.setMaxBounds(bounds);
var imagery = L.esri.basemapLayer('Imagery').addTo(map);
var imageryLabels = L.esri.basemapLayer('ImageryLabels').addTo(map);
window.images = {}
var imageOverlays = L.layerGroup([], {
attribution: "<a href='http://retrolens.nz'>Retrolens (LINZ CC-BY 3.0)</a>",
}).addTo(map);
map.spin(true, { color: "white" });
var featureLayer = L.esri.featureLayer({
url: 'https://api-proxy.auckland-cer.cloud.edu.au/Retrolens',
attribution: "<a href='http://retrolens.nz'>Retrolens (LINZ CC-BY 3.0)</a>",
minZoom: 10,
interactive: false,
style: {
fill: false,
weight: .5,
color: "red",
opacity: 1
},
timeField: "Date",
onEachFeature: function (feature, layer) {
var p = feature.properties;
var imageUrl = `https://files.interpret.co.nz/Retrolens/Imagery/SN${p.Survey}/${p.COPYRIGHT}_${p.Survey}_${p.Run}_${p.Photo_Number}/thumbnail.jpg`;
var bounds = layer.getBounds();
var imageOverlay = L.imageOverlay(imageUrl, bounds, {opacity:1, interactive: true});
imageOverlay.on("click", function() {
imageOverlay.removeFrom(imageOverlays);
})
imageOverlay.on("mouseover", function(event) {
L.popup()
.setLatLng(event.latlng)
.setContent(`Date taken: ${new Date(p.Date).toLocaleDateString()}<br>Altitude: ${p.Altitude}`)
.openOn(map);
})
window.images[feature.id] = {
start: new Date(p.Date),
feature: feature,
imageUrl: imageUrl,
bounds: bounds,
imageOverlay: imageOverlay
}
}
}).on("load", function () {
console.log("loaded", window.images);
var plotData = [{
x: Object.values(window.images).map(image => image.start),
type: 'histogram',
xbins: {
size: "M12",
}
}];
var layout = {
title: "Images over time",
xaxis: { title: "Date" },
yaxis: { title: "Number of images" }
}
Plotly.newPlot('timeline', plotData, layout, { responsive: true })
timeline.on("plotly_hover", function (data) {
console.log(data)
var d = new Date(data.points[0].x);
featureLayer.setStyle(function (feature) {
if (new Date(feature.properties.Date).getFullYear() == d.getFullYear()) {
return {
fill: false,
weight: .5,
color: "red",
opacity: 1
}
}
return {
fill: false,
weight: .5,
color: "gray",
opacity: .2,
}
});
})
timeline.on('plotly_click', function (data) {
console.log(data)
var d = new Date(data.points[0].x);
for (var i in window.images) {
var image = window.images[i];
if (image.start.getFullYear() == d.getFullYear()) {
image.imageOverlay.addTo(imageOverlays);
} else {
image.imageOverlay.removeFrom(imageOverlays);
}
}
})
map.spin(false);
}).addTo(map);
L.control.layers({}, {
"Image extents": featureLayer,
"Image overlays": imageOverlays,
"Town labels": imageryLabels
}).addTo(map);
var legend = L.control({ position: 'bottomright' });
legend.onAdd = function (map) {
var div = L.DomUtil.create('div', 'info legend');
div.innerHTML = "Hover over the timeline to view extents for a given year, click to load images";
return div;
};
legend.addTo(map);
</script>
</body>
</html>