-
Notifications
You must be signed in to change notification settings - Fork 0
/
async.html
89 lines (82 loc) · 2.65 KB
/
async.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Async</title>
<meta
name="viewport"
content="initial-scale=1,maximum-scale=1,user-scalable=no"
/>
<script src="https://api.mapbox.com/mapbox-gl-js/v1.9.0/mapbox-gl.js"></script>
<link
href="https://api.mapbox.com/mapbox-gl-js/v1.9.0/mapbox-gl.css"
rel="stylesheet"
/>
<script src="https://unpkg.com/@turf/turf/turf.min.js"></script>
<style>
body {
margin: 10;
padding: 10;
}
#map {
position: absolute;
top: 0;
bottom: 0;
/* height: 800px; */
width: 95%;
}
</style>
</head>
<body>
<div id="map"></div>
<script type="module">
mapboxgl.accessToken =
'pk.eyJ1IjoiYmFja3NwYWNlcyIsImEiOiJjanVrbzI4dncwOXl3M3ptcGJtN3oxMmhoIn0.x9iSCrtm0iADEqixVgPwqQ'
const center = [-106.16, 34.185]
const json = turf.featureCollection([turf.point(center)])
const map = new mapboxgl.Map({
container: 'map', // container id
style: 'mapbox://styles/mapbox/streets-v11',
center: center,
zoom: 5.5,
})
function mapPromise(map) {
return new Promise((resolve, reject) => {
map.on('load', () => resolve())
})
}
async function run() {
await mapPromise(map)
map.addLayer({
id: 'center',
type: 'circle',
source: {
type: 'geojson',
data: json,
// data: './data/centroids.json',
},
paint: {
'circle-color': 'red',
'circle-radius': 20,
},
})
}
run()
// map.on('load', function () {
// console.log('vanilla load')
// map.addLayer({
// id: 'center',
// type: 'circle',
// source: {
// type: 'geojson',
// data: json,
// },
// paint: {
// 'circle-color': 'red',
// 'circle-radius': 20,
// },
// })
// })
</script>
</body>
</html>