-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
277 lines (243 loc) · 9.75 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
<!DOCTYPE html>
<html lang="en">
<head>
<title>Recent earthquakes in the world</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.css">
<link rel="stylesheet" href="css/font-awesome.min.css" />
<link rel="stylesheet" href="css/leaflet/v0.7.7/leaflet.css" />
<link rel="stylesheet" href="css/style.css" />
<link rel="stylesheet" href="css/rangeslider.css" type="text/css" />
<link rel="stylesheet" href="css/loader.css" type="text/css" />
<script src="js/leaflet/v0.7.7/leaflet.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script>
<script src="js/jQDateRangeSlider-withRuler-min.js"></script> <!-- http://ghusse.github.io/jQRangeSlider -->
<script src="js/slidereveal.js"></script> <!-- http://nnattawat.github.io/slideReveal/ -->
<script src="geojson/PB2002_boundaries.json"></script>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga'); ga('create', 'UA-101644076-1', 'auto'); ga('send', 'pageview');
</script>
</head>
<body>
<script type="text/javascript">
if ($(document).width() < 800) {
alert("For the best experience, it is recommended to view this page with a resolution larger than 800px wide (your current browser's resolution is " + $(document).width() + "px).");
}
</script>
<div id="map"></div>
<div id="loader" class="cs-loader">
<div class="cs-loader-inner">
Loading<br />
<label> ●</label>
<label> ●</label>
<label> ●</label>
<label> ●</label>
<label> ●</label>
<label> ●</label>
</div>
</div>
<div id="slider" class="slider">
<h2>Settings</h2>
<label for="magnitude">Magnitude filter:</label>
<select name="magnitude" id="magnitude">
<option value="5.0" selected="selected">Significant only (5.0+)</option>
<option value="4.5">Magnitude 4.5+</option>
<option value="2.5">Magnitude 2.5+</option>
<option value="1.0"> Magnitude 1.0+</option>
<option value="0.0">All earthquakes</option>
</select>
<label for="dateSlider">Time Period filter:</label>
<div id="dateSlider"></div>
<br />
<br />
<label for="btnTectonicPlates">Show/hide tectonic plates:</label>
<button id="btnTectonicPlates" onclick="toggleTectonicPlates();" class="btn">Show</button>
<h2>Information</h2>
<div id="summary">
<p>Data from: <a href="http://earthquake.usgs.gov/" target="_blank">U.S. Geological Survey</a></p>
</div>
<div class='legend'>
<table style="width: 100%">
<thead>
<tr>
<th>Alert Level and Color</th>
<th>Estimated Fatalities</th>
<th>Estimated Losses (USD)</th>
</tr>
</thead>
<tbody>
<tr>
<td class="alert"><span class='circle blue'></span><span class="label">No Alert</span></td>
<td class="alert">-</td>
<td class="alert">-</td>
</tr>
<tr>
<td class="alert"><span class='circle green'></span></span><span class="label">Green</span></td>
<td class="alert">0</td>
<td class="alert">< $1 million</td>
</tr>
<tr>
<td class="alert"><span class='circle yellow'></span><span class="label">Yellow</span></td>
<td class="alert">1 - 99</td>
<td class="alert">$1 million - $100 million</td>
</tr>
<tr>
<td class="alert"><span class='circle orange'></span><span class="label">Orange</span></td>
<td class="alert">100 - 999</td>
<td class="alert">$100 million - $1 billion</td>
</tr>
<tr>
<td class="alert"><span class='circle red'></span><span class="label">Red</span></td>
<td class="alert">1,000+</td>
<td class="alert">$1 billion+</td>
</tr>
</tbody>
</table>
<small>Source: <a href="http://earthquake.usgs.gov/data/pager/" target="_blank">USGS PAGER System</a></small>
</div>
</div>
<div id="menu-handle">
<span class="menu-text">Infos & Settings</span><!--<i class="fa fa-chevron-left"></i>-->
</div>
<div class="bottom-title">
<div class="title"><h1>EARTHQUAKE MONITOR</h1></div>
</div>
<script type="text/javascript">
$(function(){
slider = $("#slider").slideReveal({
width: "50%",
position: "right",
speed: 600,
trigger: $("#menu-handle"),
hide: function(obj){
//<console.log(obj);
}
});
});
</script>
<script>
// Create map
var map = L.map('map').setView([10.0, 0.0], 2);
// Dark Background
var CartoDB_DarkMatter = L.tileLayer('http://{s}.basemaps.cartocdn.com/dark_all/{z}/{x}/{y}.png', {
attribution: '© <a href="http://www.openstreetmap.org/copyright" target="_blank">OpenStreetMap</a> © <a href="http://cartodb.com/attributions" target="_blank">CartoDB</a> | Data from: <a href="http://earthquake.usgs.gov/earthquakes/" target="_blank">USGS.gov</a>',
subdomains: 'abcd',
maxZoom: 19
}).addTo(map);
// Get user's location
/*function onLocationFound(e) {
L.marker(e.latlng).addTo(map).bindPopup("<strong>You are here</strong><br />(or about " + e.accuracy / 2 + "m from here)");
}
function onLocationError(e) {
alert(e.message);
}
map.on('locationfound', onLocationFound);
map.on('locationerror', onLocationError);
map.locate({setView: false, maxZoom: 16});*/
var markers = [];
var earthquakes;
// Retrieve Earthquake events details
// GEOJSON Details here: http://earthquake.usgs.gov/earthquakes/feed/v1.0/geojson_detail.php
$.getJSON('https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_month.geojson', function(data) {
earthquakes = data;
updateGlobalInfos(earthquakes.metadata);
var endDateDefault = new Date();
var startDateDefault = new Date(endDateDefault.getFullYear(), endDateDefault.getMonth(), endDateDefault.getDate() - 7);
updateMap(startDateDefault, endDateDefault, $("#magnitude").val());
updateSlider(startDateDefault, endDateDefault);
$("#loader").hide();
$("#menu-handle").effect( "highlight", {color:"#ffcc00"}, 2000 );
});
function updateGlobalInfos(metadata) {
if (typeof(earthquakes) !== undefined) {
$("#summary p").append( '<br/>Updated on: ' + new Date(metadata.generated).toString() + '.<br/>Total earthquakes last month: ' + metadata.count + '.');
}
}
function zoomOnMarker(minLat, minLng, maxLat, maxLng) {
var southWest = L.latLng(minLat, minLng),
northEast = L.latLng(maxLat, maxLng),
bounds = L.latLngBounds(southWest, northEast);
map.fitBounds(bounds);
}
var tectonicPlatesLayer = null;
// Adds/Removes tectonic plates boundaries to the map
function toggleTectonicPlates() {
if (map != null) {
if (tectonicPlatesLayer != null) {
map.removeLayer(tectonicPlatesLayer);
tectonicPlatesLayer = null;
$("#btnTectonicPlates").html("Show");
}
else {
tectonicPlatesLayer = L.geoJson([boundaries], {
color: 'red',
"weight": 2,
"opacity": 0.65
})
.addTo(map);
$("#btnTectonicPlates").html("Hide");
}
}
}
// Add a CircleMarker with a popup for each Earthquake for the selected start date, end date and magnitude
function updateMap(startDate, endDate, magnitude) {
$("#loader").show();
// Clear all markers from map
$.each(markers, function(key, marker) {
map.removeLayer(marker);
});
if (typeof(earthquakes) !== undefined) {
$.each(earthquakes.features, function(key, feature) {
// If the earthquake happened in the required time period & magnitude as required
if (feature.properties.time >= startDate.getTime() && feature.properties.time < endDate.getTime() && feature.properties.mag >= magnitude) {
// Create marker and bind info popup to it
var popupContent = "<p>";
if (feature.properties) {
popupContent += "<p><b>Location: " + feature.properties.place + "</b><br />";
popupContent += "<b>Time: " + new Date(feature.properties.time).toString() + "</b><br />";
popupContent += "<b>Magnitude: " + feature.properties.mag + "</b>";
}
popupContent += "</p>";
popupContent += "<p>";
popupContent += "<a onclick=\"$('.leaflet-popup').hide(); zoomOnMarker(" + (feature.geometry.coordinates[1] - 5) + ", " + (feature.geometry.coordinates[0] + 5) + ", " + (feature.geometry.coordinates[1] + 5) + ", " + (feature.geometry.coordinates[0] - 5) + ");\" style=\"cursor: pointer\">Zoom in</a>";
popupContent += "</p>";
circleMarker = L.circleMarker(
L.latLng(feature.geometry.coordinates[1], feature.geometry.coordinates[0]),
{
radius: feature.properties.mag * 10 ,
color: feature.properties.alert !== null ? feature.properties.alert : 'lightblue'
}
)
.bindPopup(popupContent, {minWidth: 100})
.addTo(map);
markers.push(circleMarker);
}
});
}
$("#loader").hide();
}
// Create the slider
function updateSlider(startDate, endDate) {
var now = new Date();
$("#dateSlider").dateRangeSlider({
bounds: {min: new Date().setMonth(now.getMonth() - 1), max: now}, // Past Month
defaultValues: {min: startDate, max: endDate},
});
// Bind event on Slider Date changed
$("#dateSlider").bind("valuesChanged", function(e, data){
updateMap(data.values.min, data.values.max, $("#magnitude").val())
});
}
// Bind event to the Magnitude dropdown
$("#magnitude").change(function() {
var dateValues = $("#dateSlider").dateRangeSlider("values");
updateMap(dateValues.min, dateValues.max, $("#magnitude").val())
});
</script>
</body>
</html>