-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogic.js
142 lines (112 loc) · 4.97 KB
/
logic.js
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
var API_quakes = "https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_week.geojson"
console.log (API_quakes)
var API_plates = "https://raw.githubusercontent.com/fraxen/tectonicplates/master/GeoJSON/PB2002_boundaries.json"
console.log (API_plates)
function markerSize(magnitude) {
return magnitude * 4;
};
var earthquakes = new L.LayerGroup();
d3.json(API_quakes, function (geoJson) {
L.geoJSON(geoJson.features, {
pointToLayer: function (geoJsonPoint, latlng) {
return L.circleMarker(latlng, { radius: markerSize(geoJsonPoint.properties.mag) });
},
style: function (geoJsonFeature) {
return {
fillColor: Color(geoJsonFeature.properties.mag),
fillOpacity: 0.7,
weight: 0.1,
color: 'black'
}
},
onEachFeature: function (feature, layer) {
layer.bindPopup(
"<h4 style='text-align:center;'>" + new Date(feature.properties.time) +
"</h4> <hr> <h5 style='text-align:center;'>" + feature.properties.title + "</h5>");
}
}).addTo(earthquakes);
createMap(earthquakes);
});
var plateBoundary = new L.LayerGroup();
d3.json(API_plates, function (geoJson) {
L.geoJSON(geoJson.features, {
style: function (geoJsonFeature) {
return {
weight: 2,
color: 'magenta'
}
},
}).addTo(plateBoundary);
})
function Color(magnitude) {
if (magnitude > 5) {
return 'red'
} else if (magnitude > 4) {
return 'darkorange'
} else if (magnitude > 3) {
return 'tan'
} else if (magnitude > 2) {
return 'yellow'
} else if (magnitude > 1) {
return 'darkgreen'
} else {
return 'lightgreen'
}
};
function createMap() {
var highContrastMap = L.tileLayer('https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token={accessToken}', {
attribution: '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>',
maxZoom: 18,
id: 'mapbox.high-contrast',
accessToken: 'pk.eyJ1IjoibW9kZWxvYm9vdGNhbXAiLCJhIjoiY2p2ajB0bHVjMDVzMzQ4cGJwc3Awb2J1aSJ9.EqOe7ebL_KhiMTeGJtcxZA'
});
var streetMap = L.tileLayer('https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token={accessToken}', {
attribution: '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>',
maxZoom: 18,
id: 'mapbox.streets',
accessToken: 'pk.eyJ1IjoibW9kZWxvYm9vdGNhbXAiLCJhIjoiY2p2ajB0bHVjMDVzMzQ4cGJwc3Awb2J1aSJ9.EqOe7ebL_KhiMTeGJtcxZA'
});
var darkMap = L.tileLayer('https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token={accessToken}', {
attribution: '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>',
maxZoom: 18,
id: 'mapbox.dark',
accessToken: 'pk.eyJ1IjoibW9kZWxvYm9vdGNhbXAiLCJhIjoiY2p2ajB0bHVjMDVzMzQ4cGJwc3Awb2J1aSJ9.EqOe7ebL_KhiMTeGJtcxZA'
});
var satellite = L.tileLayer('https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token={accessToken}', {
attribution: '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>',
maxZoom: 18,
id: 'mapbox.satellite',
accessToken: 'pk.eyJ1IjoibW9kZWxvYm9vdGNhbXAiLCJhIjoiY2p2ajB0bHVjMDVzMzQ4cGJwc3Awb2J1aSJ9.EqOe7ebL_KhiMTeGJtcxZA'
});
var baseLayers = {
"High Contrast": highContrastMap,
"Street": streetMap,
"Dark": darkMap,
"Satellite": satellite
};
var overlays = {
"Earthquakes": earthquakes,
"Plate Boundaries": plateBoundary,
};
var mymap = L.map('mymap', {
center: [40, -99],
zoom: 4.3,
layers: [streetMap, earthquakes, plateBoundary]
});
L.control.layers(baseLayers, overlays).addTo(mymap);
var legend = L.control({ position: 'bottomright' });
legend.onAdd = function (map) {
var div = L.DomUtil.create('div', 'info legend'),
magnitude = [0, 1, 2, 3, 4, 5],
labels = [];
div.innerHTML += "<h4 style='margin:4px'>Magnitude</h4>"
for (var i = 0; i < magnitude.length; i++) {
div.innerHTML +=
'<i style="background:' + Color(magnitude[i] + 1) + '"></i> ' +
magnitude[i] + (magnitude[i + 1] ? '–' + magnitude[i + 1] + '<br>' : '+');
}
return div;
};
legend.addTo(mymap);
}
// createMap()