-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmapanimation.js
74 lines (55 loc) · 1.71 KB
/
mapanimation.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
63
64
console.log('mapanimation.js connected');
const busURL = 'https://api-v3.mbta.com/vehicles?filter[route]=1&include=trip';
let map;
const getLocations = async ()=>{
const response = await fetch(busURL);
const json = await response.json();
return json.data;
};
const busMarkers =[];
async function initMap() {
const { Map } = await google.maps.importLibrary("maps");
const { AdvancedMarkerElement, PinElement } = await google.maps.importLibrary("marker");
map = new Map(document.getElementById("map"), {
center: { lat: 42.355001, lng: -71.099003 },
zoom: 14,
mapTypeId: "satellite",
mapId: 'DEMO_MAP_ID',
disableDefaultUI: true,
zoomControl: true,
});
map.setTilt(45);
const handleMarkers = async ()=>{
let locations = await getLocations();
while(busMarkers.length > 0){
let bus = busMarkers.pop();
bus.position = null;
}
const busIcon = document.createElement('img');
busIcon.src = './bus-icon.svg';
const pinElement = new PinElement({
glyph: busIcon
});
locations.forEach((location)=>{
const busIcon = document.createElement('img');
busIcon.src = './bus-icon.svg';
const pinElement = new PinElement({
glyph: busIcon,
scale: 1.5,
background: '#257FD2',
borderColor: '#d9d9d9'
});
const marker = new AdvancedMarkerElement({
map,
position: {lat: location.attributes.latitude, lng: location.attributes.longitude},
content: pinElement.element,
title: location.attributes.label,
});
busMarkers.push(marker);
});
console.log('handler called');
setTimeout(handleMarkers, 15000);
}
handleMarkers();
}
initMap();