forked from antievictionmappingproject/mapbox-storymap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
266 lines (251 loc) · 7.61 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
261
262
263
264
265
266
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>MapboxGL storymap</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.12.2/mapbox-gl.js'></script>
<link href='https://api.tiles.mapbox.com/mapbox-gl-js/v0.12.2/mapbox-gl.css' rel='stylesheet' />
<style>
body {
margin:0;
padding:0;
}
#map {
position:absolute;
top:0;
bottom:0;
width:100%;
}
</style>
</head>
<body>
<style>
/*2nd styling for map - do not confuse with styling above*/
#map {
position: fixed;
width: 70%;
}
#narrative {
width: 30%;
margin-left: 70%;
font-family: sans-serif;
overflow-y: scroll;
background-color: #fafafa;
}
.center {
display:block;
text-align:center;
}
section {
padding: 10px 10px 0px 10px;
border-bottom: 1px solid #ddd;
opacity: 0.25;
font-size: 13px;
}
section.active {
opacity: 1;
}
section:last-child {
border-bottom: none;
margin-bottom: 600px;
}
</style>
<div id='map'></div>
<!-- Write narrative in sections, with IDs to match chapters below -->
<div id='narrative'>
<section id='cover' class='cover active'>
<h2 class='center'>Hartford Public High School</br> sites from 1847-present</h2>
<h3 class='center'>Sample Storymap created with Mapbox GL</h3>
<p>HPHS is recognized as the second-oldest public high school in the US. While the original Latin School dates back to 1638, the modern "high school" name and building began in 1847. Learn more from the <a href="https://hphs1638.wordpress.com/" target="_blank">HPHS Museum and Archive.</a></p>
<p class='center'>Scroll ▾</p>
</section>
<section id='Ann'>
<h3>Ann Street, 1847-1869</h3>
<img src='img/HPHS1847_300.jpg'>
<small class='center'>Source credit to come</small>
<p>The first Hartford Public High School building, located at the corner of Ann Street and Asylum Avenue, was dedicated by Henry Barnard in 1847.</br>
More text to come here.<br>
More text to come here.<br>
More text to come here.<br>
More text to come here.</p>
</section>
<section id='Hopkins'>
<h3>Hopkins Street, 1869-1882</h3>
<img src='img/HPHS1869_300.jpg'>
<small class='center'>Source credit to come</small>
<p>The school moved to Hopkins Street in 1869, but was destroyed by a fire in 1882.<br>
More text to come here.<br>
More text to come here.<br>
More text to come here.<br>
More text to come here.</p>
</section>
<section id='Hopkins2'>
<h3>Hopkins Street rebuilt, 1883-1963</h3>
<img src='img/HPHS1911_300.jpg'>
<small class='center'>Source credit to come</small>
<p>After the fire, a new building was constructed on the same site in 1883.<br>
More text to come here.<br>
More text to come here.<br>
More text to come here.<br>
More text to come here.</p>
</section>
<section id='Forest'>
<h3>Forest Street, 1963-present</h3>
<img src='img/HPHS2011_300.jpg'>
<small class='center'>Source credit to come</small>
<p>When the East-West interstate highway approached, a new school was constructed on Forest Street in 1963.<br>
More text to come here.<br>
More text to come here.<br>
More text to come here.<br>
More text to come here.</p>
</section>
<section id='footer'>
<p>DRAFT visualization created by Jack Dougherty for <a href="http://ontheline.trincoll.edu" target="_blank">OnTheLine.trincoll.edu</a>.<br>
<br>
In order for this last narrative section to display, add sufficient lines of text, or empty line breaks, or modify the CSS section last child margin setting.<br>
<br>
<br>
<br>
</p>
</section>
</div>
<script>
// INSERT your own MapboxGL token and create the map
mapboxgl.accessToken = 'pk.eyJ1IjoiamFja2RvdWdoZXJ0eSIsImEiOiJxMi11TGlzIn0.ydUTGpMKcADi7fKPxy0GVA';
// TO DO: ask MapBox support why this code does not trigger alert in IE8 remove
if (!mapboxgl.supported()) {
alert('Your browser does not support Mapbox GL');
} else {
var map = new mapboxgl.Map({
container: 'map',
style: 'mapbox://styles/mapbox/streets-v8', // Current MapboxGL options: satellite, light
center: [-72.687, 41.765], // Coordinates are lng,lat (NOT lat, lng)
zoom: 13.5
// bearing: 27,
// pitch: 45
});
// Add zoom and rotation controls to the map.
map.addControl(new mapboxgl.Navigation({position: 'top-left'}));
// Insert coordinates and zoom levels for chapters, matching IDs in narrative
var chapters = {
'cover': {
// no center or zoom needed here
},
'Ann': {
center: [-72.6782, 41.7676],
zoom: 17
// optional settings for MapboxGL include:
// duration: 3000,
// bearing: 27,
// pitch: 20
},
'Hopkins': {
center: [-72.6848, 41.7677],
zoom: 17
},
'Hopkins2': {
center: [-72.6848, 41.7677],
zoom: 17
},
'Forest': {
center: [-72.7010, 41.7652],
zoom: 16.5
},
'footer': {
center: [-72.6873, 41.7685],
zoom: 13.5
}
};
// To display simple markers on map, MapboxGL requires two steps
// Step 1: GeoJson for the markers (created with http://geojson.io)
// To Do: ask MapBoxGL support how to load this geojson data from a local file
var locations = {
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {
"id": "Ann Street"
},
"geometry": {
"type": "Point",
"coordinates": [
-72.6782,
41.7676
]
}
},
{
"type": "Feature",
"properties": {
"id": "Hopkins Street"
},
"geometry": {
"type": "Point",
"coordinates": [
-72.6848,
41.7677
]
}
},
{
"type": "Feature",
"properties": {
"id": "Forest Street"
},
"geometry": {
"type": "Point",
"coordinates": [
-72.701,
41.7652
]
}
}
]
};
// Step 2: After map appears, add the geoJson source from above, and add layer to display as circles (rather than markers, since MapboxGL styling is not clearly documented)
map.on('style.load', function () {
map.addSource("markers1", {
"type": "geojson",
"data": locations
});
map.addLayer({
"id": "markers1",
"source": "markers1",
"type": "circle",
"paint": {
"circle-radius": 8,
"circle-color": "#000099",
"circle-opacity": 0.7
}
});
}); // end of function
// On every scroll event, check which element is on screen
window.onscroll = function() {
var chapterNames = Object.keys(chapters);
for (var i = 0; i < chapterNames.length; i++) {
var chapterName = chapterNames[i];
if (isElementOnScreen(chapterName)) {
setActiveChapter(chapterName);
break;
}
}
};
var activeChapterName = 'cover'; // Name must match initial chapter above
function setActiveChapter(chapterName) {
if (chapterName === activeChapterName) return;
map.flyTo(chapters[chapterName]);
document.getElementById(chapterName).setAttribute('class', 'active');
document.getElementById(activeChapterName).setAttribute('class', '');
activeChapterName = chapterName;
}
function isElementOnScreen(id) {
var element = document.getElementById(id);
var bounds = element.getBoundingClientRect();
return bounds.top < window.innerHeight && bounds.bottom > 0;
}
} // end of mapbox browser support check
</script>
</body>
</html>