-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
653 lines (579 loc) · 18.3 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
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8' />
<title>Champsecc Gietro</title>
<meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' />
<link rel="icon" type="image/x-icon" href="https://raw.githubusercontent.com/mapbox/assembly/publisher-staging/src/svgs/mapbox.svg">
<script src='https://api.mapbox.com/mapbox-gl-js/v3.0.0-beta.1/mapbox-gl.js'></script>
<link href='https://api.mapbox.com/mapbox-gl-js/v3.0.0-beta.1/mapbox-gl.css' rel='stylesheet' />
<script src="https://unpkg.com/intersection-observer@0.12.0/intersection-observer.js"></script>
<script src="https://unpkg.com/scrollama"></script>
<!-- <script src="https://unpkg.com/three@0.126.0/build/three.min.js"></script> -->
<!-- <script src="https://unpkg.com/three@0.126.0/examples/js/loaders/GLTFLoader.js"></script> -->
<script src="https://cdn.jsdelivr.net/gh/jscastro76/threebox@v.2.2.2/dist/threebox.min.js" type="text/javascript"></script>
<link href="https://cdn.jsdelivr.net/gh/jscastro76/threebox@v.2.2.2/dist/threebox.css" rel="stylesheet">
<style>
body {
margin:0;
padding:0;
font-family: sans-serif;
}
a, a:hover, a:visited {
color: #0071bc;
}
#map {
top:0;
height: 100vh;
width:100vw;
position: fixed;
}
#mapInset {
bottom:50px;
right:30px;
height: 180px;
width:250px;
max-width:100%;
position: fixed;
z-index: 1;
opacity: 1;
transition: opacity 0.5s ease-in-out;
pointer-events: none;
}
#mapInset .mapboxgl-ctrl-bottom-left{
display: none;
}
@media (max-width: 500px) {
#mapInset {
display: none;
}
}
#header {
margin: auto;
width: 100%;
position: relative;
z-index: 5;
}
#header h1, #header h2, #header p {
margin: 0;
padding: 2vh 2vw;
text-align: center;
}
#footer {
width: 100%;
min-height: 5vh;
padding-top: 2vh;
padding-bottom: 2vh;
text-align: center;
line-height: 25px;
font-size: 13px;
position: relative;
z-index: 5;
}
#features {
padding-top: 10vh;
padding-bottom: 10vh;
}
.hidden {
visibility: hidden;
}
.centered {
width: 50vw;
margin: 0 auto;
}
.lefty {
width: 33vw;
margin-left: 5vw;
}
.righty {
width: 33vw;
margin-left: 62vw;
}
.fully {
width: 100%;
margin: auto;
}
.light {
color: #444;
background-color: #fafafa;
}
.dark {
color: #fafafa;
background-color: #444;
}
.step {
padding-bottom: 50vh;
/* margin-bottom: 10vh; */
opacity: 0.25;
}
.step.active {
opacity: 0.9;
}
.step div {
padding: 25px 50px;
line-height: 25px;
font-size: 13px;
}
.step img {
width: 100%;
}
@media (max-width: 750px) {
.centered, .lefty, .righty, .fully {
width: 90vw;
margin: 0 auto;
}
}
/* Fix issue on mobile browser where scroll breaks */
.mapboxgl-canvas-container.mapboxgl-touch-zoom-rotate.mapboxgl-touch-drag-pan,
.mapboxgl-canvas-container.mapboxgl-touch-zoom-rotate.mapboxgl-touch-drag-pan .mapboxgl-canvas {
touch-action: unset;
}
</style>
</head>
<body>
<div id="map"></div>
<div id="mapInset"></div>
<div id="story"></div>
<script src="./config.js"></script>
<script>
var initLoad = true;
var layerTypes = {
'fill': ['fill-opacity'],
'line': ['line-opacity'],
'circle': ['circle-opacity', 'circle-stroke-opacity'],
'symbol': ['icon-opacity', 'text-opacity'],
'raster': ['raster-opacity'],
'fill-extrusion': ['fill-extrusion-opacity'],
'heatmap': ['heatmap-opacity']
}
var alignments = {
'left': 'lefty',
'center': 'centered',
'right': 'righty',
'full': 'fully'
}
function getLayerPaintType(layer) {
var layerType = map.getLayer(layer).type;
return layerTypes[layerType];
}
function setLayerOpacity(layer) {
var paintProps = getLayerPaintType(layer.layer);
paintProps.forEach(function(prop) {
var options = {};
if (layer.duration) {
var transitionProp = prop + "-transition";
options = { "duration": layer.duration };
map.setPaintProperty(layer.layer, transitionProp, options);
}
map.setPaintProperty(layer.layer, prop, layer.opacity, options);
});
}
var story = document.getElementById('story');
var features = document.createElement('div');
features.setAttribute('id', 'features');
var header = document.createElement('div');
if (config.title) {
var titleText = document.createElement('h1');
titleText.innerText = config.title;
header.appendChild(titleText);
}
if (config.subtitle) {
var subtitleText = document.createElement('h2');
subtitleText.innerText = config.subtitle;
header.appendChild(subtitleText);
}
if (config.byline) {
var bylineText = document.createElement('p');
bylineText.innerText = config.byline;
header.appendChild(bylineText);
}
if (header.innerText.length > 0) {
header.classList.add(config.theme);
header.setAttribute('id', 'header');
story.appendChild(header);
}
config.chapters.forEach((record, idx) => {
var container = document.createElement('div');
var chapter = document.createElement('div');
if (record.title) {
var title = document.createElement('h3');
title.innerText = record.title;
chapter.appendChild(title);
}
if (record.image) {
var image = new Image();
image.src = record.image;
chapter.appendChild(image);
}
if (record.description) {
var story = document.createElement('p');
story.innerHTML = record.description;
chapter.appendChild(story);
}
container.setAttribute('id', record.id);
container.classList.add('step');
if (idx === 0) {
container.classList.add('active');
}
chapter.classList.add(config.theme);
container.appendChild(chapter);
container.classList.add(alignments[record.alignment] || 'centered');
if (record.hidden) {
container.classList.add('hidden');
}
features.appendChild(container);
});
story.appendChild(features);
var footer = document.createElement('div');
if (config.footer) {
var footerText = document.createElement('p');
footerText.innerHTML = config.footer;
footer.appendChild(footerText);
}
if (footer.innerText.length > 0) {
footer.classList.add(config.theme);
footer.setAttribute('id', 'footer');
story.appendChild(footer);
}
mapboxgl.accessToken = config.accessToken;
const transformRequest = (url) => {
const hasQuery = url.indexOf("?") !== -1;
const suffix = hasQuery ? "&pluginName=scrollytellingV2" : "?pluginName=scrollytellingV2";
return {
url: url + suffix
}
}
var map = new mapboxgl.Map({
container: 'map',
style: config.style,
center: config.chapters[0].location.center,
zoom: config.chapters[0].location.zoom,
bearing: config.chapters[0].location.bearing,
pitch: config.chapters[0].location.pitch,
interactive: false,
transformRequest: transformRequest,
projection: config.projection
});
// /////// From here
// // parameters to ensure the model is georeferenced correctly on the map
// const modelOrigin = [7.242627, 46.058479];
// const modelAltitude = 1050;
// const modelRotate = [Math.PI / 2, 0, 0];
// const modelAsMercatorCoordinate = mapboxgl.MercatorCoordinate.fromLngLat(
// modelOrigin,
// modelAltitude
// );
// // transformation parameters to position, rotate and scale the 3D model onto the map
// const modelTransform = {
// translateX: modelAsMercatorCoordinate.x,
// translateY: modelAsMercatorCoordinate.y,
// translateZ: modelAsMercatorCoordinate.z,
// rotateX: modelRotate[0],
// rotateY: modelRotate[1],
// rotateZ: modelRotate[2],
// /* Since the 3D model is in real world meters, a scale transform needs to be
// * applied since the CustomLayerInterface expects units in MercatorCoordinates.
// */
// scale: modelAsMercatorCoordinate.meterInMercatorCoordinateUnits()
// };
// const THREE = window.THREE;
// // configuration of the custom layer for a 3D model per the CustomLayerInterface
// const customLayer = {
// id: 'modelmodel',
// type: 'custom',
// renderingMode: '3d',
// onAdd: function (map, gl) {
// this.camera = new THREE.Camera();
// this.scene = new THREE.Scene();
// // create two three.js lights to illuminate the model
// const directionalLight = new THREE.DirectionalLight(0xffffff);
// directionalLight.position.set(0, -70, 100).normalize();
// this.scene.add(directionalLight);
// const directionalLight2 = new THREE.DirectionalLight(0xffffff);
// directionalLight2.position.set(0, 70, 100).normalize();
// this.scene.add(directionalLight2);
// // use the three.js GLTF loader to add the 3D model to the three.js scene
// const loader = new THREE.GLTFLoader();
// loader.load(
// 'https://docs.mapbox.com/mapbox-gl-js/assets/34M_17/34M_17.gltf',
// (gltf) => {
// this.scene.add(gltf.scene);
// }
// );
// this.map = map;
// // use the Mapbox GL JS map canvas for three.js
// this.renderer = new THREE.WebGLRenderer({
// canvas: map.getCanvas(),
// context: gl,
// antialias: true
// });
// this.renderer.autoClear = false;
// },
// render: function (gl, matrix) {
// const rotationX = new THREE.Matrix4().makeRotationAxis(
// new THREE.Vector3(1, 0, 0),
// modelTransform.rotateX
// );
// const rotationY = new THREE.Matrix4().makeRotationAxis(
// new THREE.Vector3(0, 1, 0),
// modelTransform.rotateY
// );
// const rotationZ = new THREE.Matrix4().makeRotationAxis(
// new THREE.Vector3(0, 0, 1),
// modelTransform.rotateZ
// );
// const m = new THREE.Matrix4().fromArray(matrix);
// const l = new THREE.Matrix4()
// .makeTranslation(
// modelTransform.translateX,
// modelTransform.translateY,
// modelTransform.translateZ
// )
// .scale(
// new THREE.Vector3(
// modelTransform.scale,
// -modelTransform.scale,
// modelTransform.scale
// )
// )
// .multiply(rotationX)
// .multiply(rotationY)
// .multiply(rotationZ);
// this.camera.projectionMatrix = m.multiply(l);
// this.renderer.resetState();
// this.renderer.render(this.scene, this.camera);
// this.map.triggerRepaint();
// }
// };
// map.on('style.load', () => {
// map.addLayer(customLayer, 'waterway-label');
// });
// //UNTIL HERE
///////////// 2n method
//eslint-disable-next-line no-undef
const tb = (window.tb = new Threebox(
map,
map.getCanvas().getContext('webgl'),
{
defaultLights: true
}
));
map.on('style.load', () => {
map.addLayer({
id: 'custom-threebox-model',
type: 'custom',
renderingMode: '3d',
onAdd: function () {
// Creative Commons License attribution: Metlife Building model by https://sketchfab.com/NanoRay
// https://sketchfab.com/3d-models/metlife-building-32d3a4a1810a4d64abb9547bb661f7f3
const scale = 1;
const options = {
// obj: 'https://docs.mapbox.com/mapbox-gl-js/assets/metlife-building.gltf',
obj: 'houses.glb',
// type: 'gltf',
type: 'glb',
scale: { x: scale, y: scale, z: 1 },
units: 'meters',
rotation: { x: 90, y: 180, z: 0 },
opacity:0
};
tb.loadObj(options, (model) => {
// model.setCoords([7.242627, 46.058479]);
// model.setRotation({ x: 0, y: 0, z: 1050 });
model.setCoords([7.231875, 46.051435, -45]);
model.setRotation({ x: 0, y: 0, z: 0 });
tb.add(model);
});
},
render: function () {
tb.update();
}
});
});
//////////////////////////////////////////////////////////
// Create a inset map if enabled in config.js
if (config.inset) {
var insetMap = new mapboxgl.Map({
container: 'mapInset', // container id
style: 'mapbox://styles/mapbox/dark-v10', //hosted style id
center: config.chapters[0].location.center,
// Hardcode above center value if you want insetMap to be static.
zoom: 3, // starting zoom
hash: false,
interactive: false,
attributionControl: false,
//Future: Once official mapbox-gl-js has globe view enabled,
//insetmap can be a globe with the following parameter.
//projection: 'globe'
});
}
if (config.showMarkers) {
var marker = new mapboxgl.Marker({ color: config.markerColor });
marker.setLngLat(config.chapters[0].location.center).addTo(map);
}
// instantiate the scrollama
var scroller = scrollama();
map.on("load", function() {
if (config.use3dTerrain) {
map.addSource('mapbox-dem', {
'type': 'raster-dem',
'url': 'mapbox://mapbox.mapbox-terrain-dem-v1',
'tileSize': 512,
'maxzoom': 14
});
// add the DEM source as a terrain layer with exaggerated height
map.setTerrain({ 'source': 'mapbox-dem', 'exaggeration': 1.2 });
// add a sky layer that will show when the map is highly pitched
map.addLayer({
'id': 'sky',
'type': 'sky',
'paint': {
'sky-type': 'atmosphere',
'sky-atmosphere-sun': [0.0, 0.0],
'sky-atmosphere-sun-intensity': 15
}
});
};
// As the map moves, grab and update bounds in inset map.
if (config.inset) {
map.on('move', getInsetBounds);
}
// setup the instance, pass callback functions
scroller
.setup({
step: '.step',
offset: 0.5,
progress: true
})
.onStepEnter(async response => {
var current_chapter = config.chapters.findIndex(chap => chap.id === response.element.id);
var chapter = config.chapters[current_chapter];
response.element.classList.add('active');
map[chapter.mapAnimation || 'flyTo'](chapter.location);
// Incase you do not want to have a dynamic inset map,
// rather want to keep it a static view but still change the
// bbox as main map move: comment out the below if section.
if (config.inset) {
if (chapter.location.zoom < 5) {
insetMap.flyTo({center: chapter.location.center, zoom: 0});
}
else {
insetMap.flyTo({center: chapter.location.center, zoom: 3});
}
}
if (config.showMarkers) {
marker.setLngLat(chapter.location.center);
}
if (chapter.onChapterEnter.length > 0) {
chapter.onChapterEnter.forEach(setLayerOpacity);
}
if (chapter.callback) {
window[chapter.callback]();
}
if (chapter.rotateAnimation) {
map.once('moveend', () => {
const rotateNumber = map.getBearing();
map.rotateTo(rotateNumber + 180, {
duration: 30000, easing: function (t) {
return t;
}
});
});
}
if (config.auto) {
var next_chapter = (current_chapter + 1) % config.chapters.length;
map.once('moveend', () => {
document.querySelectorAll('[data-scrollama-index="' + next_chapter.toString() + '"]')[0].scrollIntoView();
});
}
})
.onStepExit(response => {
var chapter = config.chapters.find(chap => chap.id === response.element.id);
response.element.classList.remove('active');
if (chapter.onChapterExit.length > 0) {
chapter.onChapterExit.forEach(setLayerOpacity);
}
});
if (config.auto) {
document.querySelectorAll('[data-scrollama-index="0"]')[0].scrollIntoView();
}
});
//Helper functions for insetmap
function getInsetBounds() {
let bounds = map.getBounds();
let boundsJson = {
"type": "FeatureCollection",
"features": [{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
bounds._sw.lng,
bounds._sw.lat
],
[
bounds._ne.lng,
bounds._sw.lat
],
[
bounds._ne.lng,
bounds._ne.lat
],
[
bounds._sw.lng,
bounds._ne.lat
],
[
bounds._sw.lng,
bounds._sw.lat
]
]
]
}
}]
}
if (initLoad) {
addInsetLayer(boundsJson);
initLoad = false;
} else {
updateInsetLayer(boundsJson);
}
}
function addInsetLayer(bounds) {
insetMap.addSource('boundsSource', {
'type': 'geojson',
'data': bounds
});
insetMap.addLayer({
'id': 'boundsLayer',
'type': 'fill',
'source': 'boundsSource', // reference the data source
'layout': {},
'paint': {
'fill-color': '#fff', // blue color fill
'fill-opacity': 0.2
}
});
// // Add a black outline around the polygon.
insetMap.addLayer({
'id': 'outlineLayer',
'type': 'line',
'source': 'boundsSource',
'layout': {},
'paint': {
'line-color': '#000',
'line-width': 1
}
});
}
function updateInsetLayer(bounds) {
insetMap.getSource('boundsSource').setData(bounds);
}
// setup resize event
window.addEventListener('resize', scroller.resize);
</script>
</body>
</html>