generated from huanglii/vite-lib-template
-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.html
86 lines (78 loc) · 2.38 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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>@naivemap/mapbox-gl-polygon-morpher</title>
<meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no" />
</head>
<body>
<div id="map" style="position: absolute; top: 0; right: 0; bottom: 0; left: 0"></div>
<!-- <script src="./dist/index.umd.js"></script> -->
<script type="module">
import mapboxgl from 'mapbox-gl'
import 'mapbox-gl/dist/mapbox-gl.css'
import PolygonMorpher from './dist'
mapboxgl.accessToken =
'pk.eyJ1IjoiaHVhbmdsaWkiLCJhIjoiY2wwM2E4a2drMDVrZjNrcGRucHIxOHo0cyJ9.0ecG5KGQE6R-SmhxvLvhHg'
const map = new mapboxgl.Map({
container: 'map',
style: 'mapbox://styles/huanglii/ckqt08oxg1kcc18ub9vowurqd?optimize=true',
hash: true,
center: [-73.950543, 40.7611],
zoom: 11
})
const buildGeoJSONDistricts = (results) => {
return results.map((row, i) => {
return {
type: 'Feature',
geometry: JSON.parse(row.boundary_simple)
}
})
}
map.on('load', () => {
map.addSource('geojson-source', {
type: 'geojson',
data: {
type: 'FeatureCollection',
features: []
}
})
map.addLayer(
{
id: 'poly-layer',
type: 'fill',
source: 'geojson-source',
paint: {
'fill-color': 'rgba(152, 224, 173, 0.5)'
}
},
'aeroway-line'
)
map.addLayer({
id: 'line-layer',
type: 'line',
source: 'geojson-source',
paint: {
'line-width': 2,
'line-color': 'rgba(255, 178, 125, 1)'
}
})
const geojsonSource = map.getSource('geojson-source')
const polygonMorpher = new PolygonMorpher(geojsonSource, {
// maxDuration: 100
})
fetch(
'https://us-congress-districts.api.aclu.org/pip?min_session=86&lat=40.7306&lng=-73.9866'
)
.then((res) => res.json())
.then((data) => {
const features = buildGeoJSONDistricts(data.results)
polygonMorpher.morph(features[1])
setTimeout(() => {
polygonMorpher.morph(features[2])
}, 1000)
})
})
</script>
</body>
</html>