-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
62 lines (51 loc) · 1.75 KB
/
app.js
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
/* global document, google */
import {GoogleMapsOverlay as DeckOverlay} from '@deck.gl/google-maps';
import {GeoJsonLayer, ArcLayer} from '@deck.gl/layers';
// source: Natural Earth http://www.naturalearthdata.com/ via geojson.xyz
const AIR_PORTS =
'https://d2ad6b4ur7yvpq.cloudfront.net/naturalearth-3.3.0/ne_10m_airports.geojson';
const GOOGLE_MAPS_API_KEY =
import.meta.env.VITE_MAPS_API_KEY;
const GOOGLE_MAPS_API_URL = `https://maps.googleapis.com/maps/api/js?key=${GOOGLE_MAPS_API_KEY}&v=beta`;
function loadScript(url) {
const script = document.createElement('script');
script.type = 'text/javascript';
script.src = url;
const head = document.querySelector('head');
head.appendChild(script);
return new Promise(resolve => {
script.onload = resolve;
});
}
async function main() {
await loadScript(GOOGLE_MAPS_API_URL);
const map = new google.maps.Map(document.getElementById('map'), {
center: {lat: 50, lng: -5},
zoom: 3,
disableDefaultUI: true
});
const overlay = new DeckOverlay({
layers: [
new GeoJsonLayer({
id: 'airports',
data: AIR_PORTS,
// Styles
filled: true,
pointRadiusMinPixels: 2,
pointRadiusScale: 2000,
getPointRadius: f => 11 - f.properties.scalerank,
getFillColor: [200, 0, 80, 180]
})
]
});
overlay.setMap(map);
const mapContainer = document.querySelector('.map-container');
const buttonContainer = document.querySelector('.buttons');
buttonContainer.addEventListener('click', ev => {
const {mapSize, zoom = map.getZoom()} = ev.target.dataset;
mapContainer.style.width = mapSize === 'default' ? '' : `${mapSize}px`;
google.maps.event.trigger(map, 'resize');
map.setZoom(Number(zoom));
});
}
main();