Skip to content

Commit 9ad10e7

Browse files
authored
3/21 initial upload
initial upload of challenge 15 files
1 parent 491fdb1 commit 9ad10e7

File tree

3 files changed

+152
-0
lines changed

3 files changed

+152
-0
lines changed

index.html

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="UTF-8">
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
<meta http-equiv="X-UA-Compatible" content="ie=edge">
8+
<title>Leaflet Step-1</title>
9+
10+
<!-- Leaflet CSS -->
11+
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css"
12+
integrity="sha256-p4NxAoJBhIIN+hmNHrzRCf9tD/miZyoHS5obTRR9BMY="
13+
crossorigin="" />
14+
15+
<!-- Our CSS -->
16+
<link rel="stylesheet" type="text/css" href="static/css/style.css">
17+
</head>
18+
19+
<body>
20+
21+
<!-- The div that holds our map -->
22+
<div id="map"></div>
23+
24+
<!-- Leaflet JS -->
25+
<script src="https://unpkg.com/[email protected]/dist/leaflet.js"
26+
integrity="sha256-20nQCchB9co0qIjJZRGuk2/Z9VM+kNiyxNV1lvTlZBo="
27+
crossorigin=""></script>
28+
<!-- D3 JavaScript -->
29+
<script src="https://d3js.org/d3.v7.min.js"></script>
30+
<!-- Our JavaScript -->
31+
<script type="text/javascript" src="static/js/logic.js"></script>
32+
</body>
33+
34+
</html>

static/css/style.css

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
body {
2+
padding: 0;
3+
margin: 0;
4+
}
5+
6+
#map,
7+
body,
8+
html {
9+
height: 100%;
10+
}
11+
12+
.legend {
13+
padding: 10px;
14+
line-height: 15px;
15+
color: #555;
16+
background: #fff;
17+
border-radius: 5px;
18+
}
19+
20+
.legend i {
21+
float: left;
22+
width: 18px;
23+
height: 18px;
24+
margin-right: 5px;
25+
opacity: 0.7;
26+
}
27+
28+
.leaflet-bottom.leaflet-left {
29+
width: 90%;
30+
}
31+
32+
.leaflet-control-container .leaflet-timeline-controls{
33+
width: 100%;
34+
box-sizing: border-box;
35+
margin: 0;
36+
margin-bottom: 15px;
37+
}

static/js/logic.js

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
let basemap = L.tileLayer(
2+
"https://{s}.tile.opentopomap.org/{z}/{x}/{y}.png", {
3+
attribution: 'Map data: &copy; OpenTopoMap contributors'
4+
});
5+
6+
let map = L.map("map", {
7+
center: [40.7, -94.5],
8+
zoom: 3
9+
});
10+
11+
basemap.addTo(map);
12+
13+
function getColor(depth) {
14+
if(depth > 90) {
15+
return "#ea2c2c"
16+
} else if (depth > 70) {
17+
return "#ea822c"
18+
} else if (depth > 50) {
19+
return "#ee9c00"
20+
} else if (depth > 30) {
21+
return "#eecc00"
22+
} else if (depth > 10) {
23+
return "#d4ee00"
24+
}
25+
else {
26+
return "#98ee00"
27+
}
28+
}
29+
30+
function getRadius(magnitude) {
31+
if(magnitude === 0) {
32+
return 1
33+
}
34+
return magnitude * 4
35+
}
36+
37+
d3.json("https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_week.geojson").then(function(data) {
38+
function styleInfo(feature) {
39+
return {
40+
opacity: 1,
41+
fillOpacity: 1,
42+
fillColor: getColor(feature.geometry.coordinates[2]),
43+
color: "#000000",
44+
weight: 0.5
45+
}
46+
}
47+
48+
L.geoJson(data, {
49+
pointToLayer: function(feature, latlng) {
50+
return L.circleMarker(latlng, {
51+
radius: getRadius(feature.properties.mag)
52+
});
53+
},
54+
style: styleInfo,
55+
onEachFeature: function(feature, layer) {
56+
layer.bindPopup(`
57+
Magnitude: ${feature.properties.mag} <br>
58+
Depth: ${feature.geometry.coordinates[2]} <br>
59+
Location: ${feature.properties.place}
60+
`);
61+
}
62+
}).addTo(map);
63+
64+
let legend = L.control({ position: "bottomright" });
65+
66+
legend.onAdd = function(map) {
67+
let container = L.DomUtil.create("div", "info legend");
68+
const grades = [-10, 10, 30, 50, 70, 90];
69+
const colors = ["#98ee00", "#d4ee00", "#eecc00", "#ee9c00", "#ea822c", "#ea2c2c"];
70+
71+
for (let i = 0; i < grades.length; i++) {
72+
container.innerHTML +=
73+
'<i style="background:' + colors[i] + '"></i> ' +
74+
grades[i] + (grades[i + 1] ? '&ndash;' + grades[i + 1] + '<br>' : '+');
75+
}
76+
77+
return container;
78+
};
79+
80+
legend.addTo(map);
81+
});

0 commit comments

Comments
 (0)