-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
147 lines (129 loc) · 3.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Scrollama Basic Example</title>
<link href="https://unpkg.com/maplibre-gl/dist/maplibre-gl.css" rel="stylesheet" />
<style>
body { margin: 0; padding: 0; }
#map {
width: 100vw;
height: 100vh;
position: fixed;
top: 0;
}
#steps {
position: relative;
}
.step {
height: 100vh;
}
.textbox {
width: 300px;
background-color: #201b1b;
color: aliceblue;
font-size: 1.2em;
padding: 20px;
margin: 20px;
}
</style>
</head>
<body>
<div id="map"></div>
<div id="steps">
<div class="step">
<div class="textbox">
Introduction
</div>
</div>
<div class="step">
<div class="textbox">
Phnom Penh
</div>
</div>
<div class="step">
<div class="textbox">
Battambang
</div>
</div>
<div class="step">
<div class="textbox">
Siem Reap
</div>
</div>
</div>
<!-- Scrollama library -->
<script src="https://unpkg.com/scrollama"></script>
<!-- Maplibre library -->
<script src="https://unpkg.com/maplibre-gl/dist/maplibre-gl.js"></script>
<script>
const map = new maplibregl.Map({
container: 'map',
style: 'https://basemaps.cartocdn.com/gl/positron-gl-style/style.json',
center: [104.9282, 11.5564],
zoom: 6
})
// City data with population
const cities = [
{ name: 'Phnom Penh', coordinates: [104.9282, 11.5564], population: 2282000 },
{ name: 'Battambang', coordinates: [103.1996, 13.0957], population: 119251 },
{ name: 'Siem Reap', coordinates: [103.8552, 13.3671], population: 245494 }
];
let citiesGeoJsonFeatures = cities.map(city => {
return {
type: "Feature",
geometry: {
type: "Point",
coordinates: city.coordinates
},
properties: {
name: city.name,
population: city.population
}
}
})
console.log("cities",cities);
console.log("cities GeoJSON format",citiesGeoJsonFeatures)
map.scrollZoom.disable();
map.on('load', function () {
map.addSource('cities', {
type: 'geojson',
data: {
type: 'FeatureCollection',
features: citiesGeoJsonFeatures
}
})
map.addLayer({
id: 'city-circles',
type: 'circle',
source: 'cities',
paint: {
'circle-radius': ['interpolate', ['linear'], ['get', 'population'], 100000, 5, 10000000, 100],
'circle-color': '#ff0000',
'circle-opacity': 0.8
}
})
})
// Initilise Scrollama
const scoller = scrollama();
// Set up Scrollama
scoller
.setup({
step: ".step",
offset: 0.5
})
.onStepEnter(response => {
if (response.index === 1) {
map.flyTo({ center: [104.9282, 11.5564], zoom: 12 }); // Phnom Penh
} else if (response.index === 2) {
map.flyTo({ center: [103.1996, 13.0957], zoom: 12 }); // Battambang
} else if (response.index === 3) {
map.flyTo({ center: [103.8552, 13.3671], zoom: 12 }); // Siem Reap
} else {
map.flyTo({center: [104.9282, 11.5564], zoom: 6 }); // Zoom Out})
}
})
</script>
</body>
</html>