-
Notifications
You must be signed in to change notification settings - Fork 821
/
index.js
68 lines (60 loc) · 1.78 KB
/
index.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
65
66
67
68
/**
* @license
* Copyright 2019 Google LLC. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/
// eslint-disable no-undef
// [START maps_advanced_markers_collision]
let map;
// Initialize and add the map
async function initMap() {
// Request needed libraries.
const { Map } = await google.maps.importLibrary("maps");
const { AdvancedMarkerElement } = await google.maps.importLibrary("marker");
let markers = [];
let collisionBehavior = google.maps.CollisionBehavior.REQUIRED;
map = new Map(document.getElementById("map"), {
mapId: "6ff586e93e18149f",
center: { lat: 47.609414458375674, lng: -122.33897030353548 },
zoom: 17,
});
// @ts-ignore
const select = new mdc.select.MDCSelect(
document.querySelector(".mdc-select"),
);
select.listen("MDCSelect:change", () => {
collisionBehavior = select.value;
markers.forEach((marker) => {
marker.collisionBehavior = collisionBehavior;
});
});
select.value = collisionBehavior;
// Create some markers on the map
let locations = [
[-122.3402, 47.6093],
[-122.3402, 47.6094],
[-122.3403, 47.6094],
[-122.3384, 47.6098],
[-122.3389, 47.6095],
[-122.3396, 47.6095],
[-122.3379, 47.6097],
[-122.3378, 47.6097],
[-122.3396, 47.6091],
[-122.3383, 47.6089],
[-122.3379, 47.6093],
[-122.3381, 47.6095],
[-122.3378, 47.6095],
];
locations.forEach(([lng, lat]) => {
// [START maps_advanced_markers_collision_create_marker]
const advancedMarker = new AdvancedMarkerElement({
position: new google.maps.LatLng({ lat, lng }),
map,
collisionBehavior: collisionBehavior,
});
// [END maps_advanced_markers_collision_create_marker]
markers.push(advancedMarker);
});
}
initMap();
// [END maps_advanced_markers_collision]