-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathchallenge-earthquakes1.html
99 lines (90 loc) · 3.09 KB
/
challenge-earthquakes1.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name='viewport' content='width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no' />
<!--[if lte IE 8]>
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.7/leaflet.ie.css" />
<![endif]-->
<style type="text/css">
body {
padding: 0;
margin: 0;
}
html, body, #leaflet-map {
height: 100%;
}
.leaflet-popup-content {
max-height: 400px;
overflow-y: scroll;
}
</style>
<link rel="stylesheet" href="//cdn.leafletjs.com/leaflet-0.7.3/leaflet.css" />
<link rel="stylesheet" type="text/css" href="//cdnjs.cloudflare.com/ajax/libs/leaflet.markercluster/0.4.0/MarkerCluster.css">
<link rel="stylesheet" type="text/css" href="//cdnjs.cloudflare.com/ajax/libs/leaflet.markercluster/0.4.0/MarkerCluster.Default.css">
</head>
<body>
<div id="leaflet-map"></div>
<script src="http://code.jquery.com/jquery-2.1.1.min.js"></script>
<script src="//cdn.leafletjs.com/leaflet-0.7.3/leaflet.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/leaflet.markercluster/0.4.0/leaflet.markercluster.js"></script>
<script>
// MAP
var map = L.map('leaflet-map', {
center: [0.0, 0.0],
zoom: 3,
});
// copyright
var mbAttr = 'Map data © <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, ' +
'<a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, ' +
'Imagery © <a href="http://mapbox.com">Mapbox</a>',
mbUrl = 'https://{s}.tiles.mapbox.com/v3/{id}/{z}/{x}/{y}.png';
// mapbox gray
var grayscale = L.tileLayer(mbUrl, {
id: 'examples.map-20v6611k',
attribution: mbAttr
});
grayscale.addTo(map);
var markers = new L.MarkerClusterGroup();
map.addLayer(markers);
// geojson
$.ajax({
url: "http://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_week.geojson",
cache: true,
success: function(data) {
// make geojson layer from data
var geojsonlayer = L.geoJson(data, {
pointToLayer: function(feature, latlng) {
var marker = L.marker(latlng);
markers.addLayer(marker);
return marker;
},
onEachFeature: popUp
});
// fit data to map
map.fitBounds(geojsonlayer.getBounds());
//map.addLayer(geojsonlayer);
}
});
// popup Function(feature, layer)
function popUp(f, l) {
var content = "<table class=\"marker-properties\"><tbody>";
var out = [];
var regexp = new RegExp('^http');
var value;
if (f.properties) {
for (var key in f.properties) {
if (regexp.test(f.properties[key])) {
value = "<a href=\"" + f.properties[key] + "\">" + f.properties[key] + "</a>";
} else {
value = f.properties[key];
}
out.push("<tr class=\"unchanged\"><th>" + key + "</th><td>" + value);
}
content = content + out.join("</td></tr>") + "</tbody></table>";
l.bindPopup(content);
}
}
</script>
</body>
</html>