-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathindex.ts
More file actions
61 lines (55 loc) · 1.77 KB
/
index.ts
File metadata and controls
61 lines (55 loc) · 1.77 KB
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
/**
* @license
* Copyright 2019 Google LLC. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/
// [START maps_advanced_markers_zoom]
const mapElement = document.querySelector('gmp-map') as google.maps.MapElement;
async function initMap() {
// Request needed libraries.
const { Map } = (await google.maps.importLibrary(
'maps'
)) as google.maps.MapsLibrary;
const { AdvancedMarkerElement } = (await google.maps.importLibrary(
'marker'
)) as google.maps.MarkerLibrary;
const markerOptions = [
{
position: { lat: 37.4239163, lng: -122.094 },
title: 'This marker is visible at zoom level 15 and higher.',
minZoom: 14,
},
{
position: { lat: 37.4245, lng: -122.096 },
title: 'This marker is visible at zoom level 16 and higher.',
minZoom: 15,
},
{
position: { lat: 37.4249, lng: -122.095 },
title: 'This marker is visible at zoom level 17 and higher.',
minZoom: 16,
},
{
position: { lat: 37.425, lng: -122.0955 },
title: 'This marker is visible at zoom level 18 and higher.',
minZoom: 17,
},
];
const markers: google.maps.marker.AdvancedMarkerElement[] = [];
for (const { position, title } of markerOptions) {
const marker = new AdvancedMarkerElement({ position, title });
mapElement.append(marker);
markers.push(marker);
}
// [START maps_advanced_markers_zoom_listener]
mapElement.innerMap.addListener('zoom_changed', () => {
let zoom = mapElement.innerMap.getZoom();
for (let i = 0; i < markers.length; i++) {
const { position, minZoom } = markerOptions[i];
markers[i].position = zoom! > minZoom ? position : null;
}
});
// [END maps_advanced_markers_zoom_listener]
}
initMap();
// [END maps_advanced_markers_zoom]