-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.html
More file actions
190 lines (187 loc) · 7.07 KB
/
index.html
File metadata and controls
190 lines (187 loc) · 7.07 KB
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
<!DOCTYPE html>
<html>
<head>
<!-- standard setup -->
<meta charset='utf-8' />
<title>Display a map</title>
<meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' />
<script src='https://api.tiles.mapbox.com/mapbox-gl-js/v0.53.0/mapbox-gl.js'></script>
<link href='https://api.tiles.mapbox.com/mapbox-gl-js/v0.53.0/mapbox-gl.css' rel='stylesheet' />
<link href='origin_map_styles.css' rel='stylesheet' />
</head>
<body>
<div id='map'></div>
<div class='map-overlay top'>
<div class='map-overlay-inner'>
<!-- all the credits and data sources -->
<h2>Countries of Origin for Foreign-Born Residents of Wayne County, Michigan 2018</h2>
<p>Click on an origin point within a country to see how many people born there now live in Wayne County</p>
<p class="credit">Population Data: <a href="https://factfinder.census.gov/faces/nav/jsf/pages/searchresults.xhtml?refresh=t">U.S Census 2018</a></p>
<p class="credit">Country Centroids: <a href="https://worldmap.harvard.edu/data/geonode:country_centroids_az8">Harvard World Map</a></p>
<p class="credit">Wayne County: <a href="http://gis-michigan.opendata.arcgis.com/datasets/67a8ff23b5f54f15b7133b8c30981441_0">MI GIS Open Data</a></p>
<p class="credit"><a href="https://carto.com/blog/jets-and-datelines/">A helpful polyline wrapping resource</a></p>
<p class="credit"><a href="https://github.com/klovskim">My Github</a></p>
</div>
</div>
<div class='box-legend' id='legend'></div>
<script>
mapboxgl.accessToken = 'pk.eyJ1IjoibWtsb3Zza2kiLCJhIjoiY2l6N2R0azl2MDA1NDJ3cG9uZ2RoMzF5aiJ9.UacgAXrCVFX4BmcbH4oj_w';
const map = new mapboxgl.Map({
container: 'map',
style: 'mapbox://styles/mklovski/cjsswrzi53eeq1fpaqlb62fam',
// set the default load location
center: [-37.705044, 25.502323],
zoom: 2
});
map.addControl(new mapboxgl.NavigationControl());
map.on('load', function () {
// adding wayne county outline
map.addLayer({
id: 'wayne_county',
type: 'fill',
source: {
type: 'vector',
url: 'mapbox://mklovski.5jbu3hm3'
},
'source-layer': 'wayne_county_border-23lapf',
'layout': {
'visibility': 'visible'
},
// style the borders of wayne county
paint: {
'fill-color': '#ffffff',
'fill-opacity': .5,
'fill-outline-color': '#000000',
}
}),
// adding the lines that were split to accomodate the dateline
map.addLayer({
id: 'split_circle_lines',
type: 'line',
source: {
type: 'vector',
url: 'mapbox://mklovski.75q4x6yf'
},
'source-layer': 'asia_lines-abqtv5',
'layout': {
'visibility': 'visible'
},
// style for the origin nodes, size according to people_count and then scale by 2000
paint: {
'line-color': [
'match',
['get', 'continent'],
'Americas', '#99420c',
'Africa', '#7570b3',
'Asia', '#e55e5e',
'Europe', '#1b9e77',
'Oceania', '#3bb2d0',
/* other */ '#ccc'
],
'line-opacity': 1,
'line-width': [
'/',
['number', ['get', 'people_cou']],
2000],
}
}),
// regular lines
map.addLayer({
id: 'reg_circle_lines',
type: 'line',
source: {
type: 'vector',
url: 'mapbox://mklovski.8snn31e0'
},
'source-layer': 'nosplit_lines-6tz5xp', // name of tilesets
'layout': {
'visibility': 'visible'
},
// style for the origin nodes, size according to people_count
paint: {
'line-color': [
'match',
['get', 'continent'],
'Americas', '#99420c',
'Africa', '#7570b3',
'Asia', '#e55e5e',
'Europe', '#1b9e77',
'Oceania', '#3bb2d0',
/* other */ '#ccc'
],
'line-opacity': 1,
'line-width': [
'/',
['number', ['get', 'people_cou']],
2000],
}
}),
// adding the points of origin here where the lines "originate"
map.addLayer({
id: 'country_points',
type: 'circle',
source: {
type: 'vector',
url: 'mapbox://mklovski.2p53ryec'
},
'source-layer': 'country_centroids-5solf9',
'layout': {},
// style for the origin nodes, size according to people_count
paint: {
'circle-color': [
'match',
['get', 'continent'],
'Americas', '#99420c',
'Africa', '#7570b3',
'Asia', '#e55e5e',
'Europe', '#1b9e77',
'Oceania', '#3bb2d0',
/* other */ '#ccc'
],
'circle-opacity': 1,
'circle-stroke-color': '#99420c',
'circle-stroke-opacity': 1
}
})
});
// make a popup for when you click on the country points
map.on('click', 'country_points', function (e) {
var coordinates = e.features[0].geometry.coordinates.slice();
var geography = e.features[0].properties.geography;
var people_count = e.features[0].properties.people_count;
while (Math.abs(e.lngLat.lng - coordinates[0]) > 180) {
coordinates[0] += e.lngLat.lng > coordinates[0] ? 360 : -360;
}
// format the popup
new mapboxgl.Popup()
.setLngLat(coordinates)
.setHTML("<h3>" + geography + "</h3>" + people_count + " People Born Here")
.addTo(map);
});
// change the icon when you hover it
map.on('mouseenter', 'country_points', function () {
map.getCanvas().style.cursor = 'pointer';
});
// change it back when you leave
map.on('mouseleave', 'country_points', function () {
map.getCanvas().style.cursor = '';
});
// add a legend
var legendlabels = ['Africa', 'Americas', 'Asia', 'Europe', 'Oceania'];
var colors = ['#7570b3', '#99420c', '#e55e5e', '#1b9e77', '#3bb2d0'];
for (i = 0; i < legendlabels.length; i++) {
var layer = legendlabels[i];
var color = colors[i];
var item = document.createElement('div');
var key = document.createElement('span');
key.className = 'legend-key';
key.style.backgroundColor = color;
var value = document.createElement('span');
value.innerHTML = layer;
item.appendChild(key);
item.appendChild(value);
legend.appendChild(item);
}
</script>
</body>
</html>