-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathindex.html
260 lines (247 loc) · 11.4 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
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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
<html lang="en">
<head>
<meta charset="utf-8">
<title>[TESTING] BCU Labs Stressmap</title>
<meta name="viewport"
content="initial-scale=1,maximum-scale=1,user-scalable=no">
<link href="https://api.mapbox.com/mapbox-gl-js/v3.6.0/mapbox-gl.css"
rel="stylesheet">
<script src="https://api.mapbox.com/mapbox-gl-js/v3.6.0/mapbox-gl.js"></script>
<style>
body {
margin: 0;
padding: 0;
}
#map {
position: absolute;
top: 0;
bottom: 0;
width: 100%;
}
</style>
</head>
<body>
<style>
.map-overlay {
background-color: #fff;
font:
12px/20px 'Helvetica Neue',
Arial,
Helvetica,
sans-serif;
position: absolute;
width: 100px;
top: 0;
left: 0;
padding: 1px;
}
</style>
<h1>BCU Labs - Data Team</h1>
<div id="map"></div>
<div class="map-overlay top">
<div class="map-overlay-inner">
<fieldset>
<label>Zoom Level: </label>
<label id="zoom"></label>
</fieldset>
</div>
</div>
<script src="https://api.mapbox.com/mapbox-gl-js/v3.6.0/mapbox-gl.js"></script>
<script>
const baseWidth = 3;
const baseZoom = 12
mapboxgl.accessToken = 'pk.eyJ1Ijoic2tpbGNveW5lIiwiYSI6ImNseTd2cXpwOTA5MnUya3E2ejBkN2ttOW8ifQ.TN39Bd_yu_SqMsu-IW4FKQ';
const map = new mapboxgl.Map({
container: 'map', // container ID
center: [-71.057083, 42.361145], // Boston starting position [lng, lat]
// style: "mapbox://styles/skilcoyne/cly7vy7v200ut01qohg1ycwl7/draft",
style:'mapbox://styles/mapbox/dark-v11',
zoom: baseZoom // starting zoom
});
// map.on('style.load', () => {
// map.setConfigProperty('basemap', 'showPointOfInterestLabels', false);
// map.setConfigProperty('basemap', 'showPlaceLabels', false);
// map.setConfigProperty('basemap', 'show3dObjects', false);
// map.setConfigProperty('basemap', 'showTransitLabels', true);
// map.setConfigProperty('basemap', 'theme', 'monochrome');
// map.setConfigProperty('basemap', 'lightPreset', 'night');
// });
map.on('load', function () {
map.addSource('LTS_source', {
type: 'vector',
url: 'mapbox://skilcoyne.stressmap_tiles'
});
map.addLayer({
'id': 'lts-layer',
"type": "line",
'source': 'LTS_source',
'source-layer': 'lts',
'paint': {
'line-color': [
'match',
['get', 'LTS'],
// 0, 'black',
// Colors based on 5 equally spaced from 'turbo' colormap
1, '#28BCEB',
2, '#A4FC3C',
3, '#FB7E21',
4, '#7A0403',
'white'
],
'line-width': baseWidth
// 'line-opacity': 0.5,
}
},
'road-label-simple' // Add layer below labels
);
// When a click event occurs on a feature in the places layer, open a popup at the
// location of the feature, with description HTML from its properties.
map.on('click', 'lts-layer', (e) => {
// Copy coordinates array.
const coordinates = e.features[0].geometry.coordinates.slice(); // I don't think this works with line strings
const description = `
<h1>${e.features[0].properties.name}</h1>
<p>Road Type: ${e.features[0].properties.highway}<br></p>
<table>
<tr>
<th>Value</th>
<th>Left</th>
<th>Right</th>
</tr>
<tr>
<td><b>LTS</b></td>
<td><b>${e.features[0].properties.LTS_left}</b></td>
<td><b>${e.features[0].properties.LTS_right}</b></td>
</tr>
<tr>
<td colspan="3"><b>Bike Infrastructure</b></td>
</tr>
<tr>
<td>Bike Permitted</td>
<td>${e.features[0].properties.biking_permitted_left} <font color="gray">${e.features[0].properties.biking_permitted_rule_left}</font></td>
<td>${e.features[0].properties.biking_permitted_right} <font color="gray">${e.features[0].properties.biking_permitted_rule_right}</font></td>
</tr>
<tr>
<td>Bike Lane</td>
<td>${e.features[0].properties.bike_lane_exist_left} <font color="gray">${e.features[0].properties.bike_lane_exist_rule_left}</font></td>
<td>${e.features[0].properties.bike_lane_exist_right} <font color="gray">${e.features[0].properties.bike_lane_exist_rule_right}</font></td>
</tr>
<tr>
<td>Separation</td>
<td>${e.features[0].properties.bike_lane_separation_left} <font color="gray">${e.features[0].properties.bike_lane_separation_rule_left}</font></td>
<td>${e.features[0].properties.bike_lane_separation_right} <font color="gray">${e.features[0].properties.bike_lane_separation_rule_right}</font></td>
</tr>
<tr>
<td>Width</td>
<td>${e.features[0].properties.width_bikelane_left} <font color="gray">${e.features[0].properties.width_bikelane_rule_left}</font></td>
<td>${e.features[0].properties.width_bikelane_right} <font color="gray">${e.features[0].properties.width_bikelane_rule_right}</font></td>
</tr>
<tr>
<td>Buffer</td>
<td>${e.features[0].properties.width_bikelanebuffer_left} <font color="gray">${e.features[0].properties.width_bikelanebuffer_rule_left}</font></td>
<td>${e.features[0].properties.width_bikelanebuffer_right} <font color="gray">${e.features[0].properties.width_bikelanebuffer_rule_right}</font></td>
</tr>
<tr>
<td>Reach</td>
<td>${e.features[0].properties.bikelane_reach_left}</td>
<td>${e.features[0].properties.bikelane_reach_right}</td>
</tr>
<tr>
<td colspan="3"><b>Street Design for Cars</b></td>
</tr>
<tr>
<td>Oneway</td>
<td colspan="2">${e.features[0].properties.oneway} <font color="gray">${e.features[0].properties.street_narrow_wide}</font></td>
</tr>
<tr>
<td>Street Width</td>
<td colspan="2">${e.features[0].properties.width_street} <font color="gray">${e.features[0].properties.width_street_rule}</font></td>
</tr>
<tr>
<td>Parking Width</td>
<td>${e.features[0].properties.width_parking_left} <font color="gray">${e.features[0].properties.width_parking_rule_left}</font></td>
<td>${e.features[0].properties.width_parking_right} <font color="gray">${e.features[0].properties.width_parking_rule_right}</font></td>
</tr>
<tr>
<td>Lane Count</td>
<td colspan="2">${e.features[0].properties.lane_count} <font color="gray">${e.features[0].properties.lane_count_rule}</font></td>
</tr>
<tr>
<td>Parking</td>
<td>${e.features[0].properties.parking_left} <font color="gray">${e.features[0].properties.parking_rule_left}</font></td>
<td>${e.features[0].properties.parking_right} <font color="gray">${e.features[0].properties.parking_rule_right}</font></td>
</tr>
<tr>
<td>Prevailing Speed</td>
<td colspan="2">${e.features[0].properties.speed} <font color="gray">${e.features[0].properties.speed_rule}</font></td>
</tr>
<tr>
<td>Centerline</td>
<td colspan="2">${e.features[0].properties.centerline} <font color="gray">${e.features[0].properties.centerline_rule}</font></td>
</tr>
<tr>
<td>Average Daily Traffic (ADT)</td>
<td colspan="2">${e.features[0].properties.ADT} <font color="gray">${e.features[0].properties.ADT_rule}</font></td>
</tr>
<tr>
<td colspan="3"><b>Technical Info</b></td>
</tr>
<tr>
<td>OSMid</td>
<td colspan="2"><a href="https://www.openstreetmap.org/way/${e.features[0].properties.osmid}" target="_blank">${e.features[0].properties.osmid}</a></td>
</tr>
<tr>
<td>LTS_biking_permitted</td>
<td>${e.features[0].properties.LTS_biking_permitted_left}</td>
<td>${e.features[0].properties.LTS_biking_permitted_right}</td>
</tr>
<tr>
<td>LTS_bike_lane_separation</td>
<td>${e.features[0].properties.LTS_bike_lane_separation_left}</td>
<td>${e.features[0].properties.LTS_bike_lane_separation_right}</td>
</tr>
<tr>
<td>LTS_mixed</td>
<td>${e.features[0].properties.LTS_mixed_left}</td>
<td>${e.features[0].properties.LTS_mixed_right}</td>
</tr>
<tr>
<td>LTS_bikelane_noparking</td>
<td>${e.features[0].properties.LTS_bikelane_noparking_left}</td>
<td>${e.features[0].properties.LTS_bikelane_noparking_right}</td>
</tr>
<tr>
<td>LTS_bikelane_yesparking</td>
<td>${e.features[0].properties.LTS_bikelane_yesparking_left}</td>
<td>${e.features[0].properties.LTS_bikelane_yesparking_right}</td>
</tr>
</table>`;
// Ensure that if the map is zoomed out such that multiple
// copies of the feature are visible, the popup appears
// over the copy being pointed to.
if (['mercator', 'equirectangular'].includes(map.getProjection().name)) {
while (Math.abs(e.lngLat.lng - coordinates[0]) > 180) {
coordinates[0] += e.lngLat.lng > coordinates[0] ? 360 : -360;
}
}
new mapboxgl.Popup()
.setLngLat(e.lngLat) // Changed to use click location instead of feature location (I think)
.setHTML(description)
.setMaxWidth("600px")
.addTo(map);
});
// Change the cursor to a pointer when the mouse is over the LTS layer.
map.on('mouseenter', 'lts-layer', () => {
map.getCanvas().style.cursor = 'pointer';
});
// Change it back to a pointer when it leaves.
map.on('mouseleave', 'lts-layer', () => {
map.getCanvas().style.cursor = '';
});
map.on('zoom', () => {
document.getElementById('zoom').textContent = map.getZoom().toFixed(2);
});
})
</script>
</body>
</html>