-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
143 lines (125 loc) · 3.17 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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>NYC Shelters by Community District</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://api.mapbox.com/mapbox-gl-js/v2.14.1/mapbox-gl.css" rel="stylesheet">
<script src="https://api.mapbox.com/mapbox-gl-js/v2.14.1/mapbox-gl.js"></script>
<style>
body {
margin: 0;
padding: 0;
}
h2,
h3 {
margin: 10px;
font-size: 18px;
}
h3 {
font-size: 16px;
}
p {
margin: 10px;
}
/**
* Create a position for the map
* on the page */
#map {
position: absolute;
top: 0;
bottom: 0;
width: 100%;
}
/**
* Set rules for how the map overlays
* (information box and legend) will be displayed
* on the page. */
.map-overlay {
position: absolute;
bottom: 0;
right: 0;
background: #fff;
margin-right: 20px;
font-family: Arial, sans-serif;
overflow: auto;
border-radius: 3px;
}
#features {
top: 0;
height: 100px;
margin-top: 20px;
width: 300px;
}
#legend {
padding: 10px;
box-shadow: 0 1px 2px rgb(0 0 0 / 10%);
line-height: 18px;
height: 80px;
margin-bottom: 40px;
width: 100px;
}
.legend-key {
display: inline-block;
border-radius: 20%;
width: 10px;
height: 10px;
margin-right: 5px;
}
</style>
</head>
<body>
<div id="map"></div>
<div class='map-overlay' id='features'><h2>Shelters by Community District</h2><div id='pd'><p>Hover over a Community District!</p></div></div>
<div class='map-overlay' id='legend'></div>
<script>
mapboxgl.accessToken = 'pk.eyJ1IjoiZm12YWxkZXpnODQiLCJhIjoiY2w5eWJzMzkwMDNiaDNvbGltamV1ajdvNiJ9.esyugI1HyBVPAQcRN551xw';
const map = new mapboxgl.Map({
container: 'map',
// Choose from Mapbox's core styles, or make your own style with Mapbox Studio
style: 'mapbox://styles/fmvaldezg84/cluk6nq47005v01qo48j3ab3y',
center: [-73.74380, 40.83090],
zoom: 9.37,
pitch: 40,
//bearing: 20,
//antialias: true
});
map.on('load', () => {
map.getCanvas().style.cursor = 'default';
const layers = [
'0-136',
'136-393',
'393-874',
'874-1544'
];
const colors = [
'#feebe2',
'#fbb4b9',
'#f768a1',
'#ae017e'
];
const legend = document.getElementById('legend');
layers.forEach((layer, i) => {
const color = colors[i];
const item = document.createElement('div');
const key = document.createElement('span');
key.className = 'legend-key';
key.style.backgroundColor = color;
const value = document.createElement('span');
value.innerHTML = `${layer}`;
item.appendChild(key);
item.appendChild(value);
legend.appendChild(item);
});
map.on('mousemove', (event) => {
const shelters = map.queryRenderedFeatures(event.point, {
layers: ['shelterbycommdist-4du506']
});
document.getElementById('pd').innerHTML = shelters.length
? `<h3>${shelters[0].properties.Total_Shelters}</strong> shelters</em></p>`
: `<p>Hover over a Community District!</p>`;
});
});
</script>
</body>
</html>