-
Notifications
You must be signed in to change notification settings - Fork 823
/
index.ts
46 lines (39 loc) · 1.13 KB
/
index.ts
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
/**
* @license
* Copyright 2019 Google LLC. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/
// [START maps_event_simple]
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 myLatlng = { lat: -25.363, lng: 131.044 };
const map = new google.maps.Map(
document.getElementById("map") as HTMLElement,
{
zoom: 4,
center: myLatlng,
mapId: "DEMO_MAP_ID",
}
);
const marker = new google.maps.marker.AdvancedMarkerElement({
position: myLatlng,
map,
title: "Click to zoom",
});
map.addListener("center_changed", () => {
// 3 seconds after the center of the map has changed, pan back to the
// marker.
window.setTimeout(() => {
map.panTo(marker.position as google.maps.LatLng);
}, 3000);
});
marker.addListener("click", () => {
map.setZoom(8);
map.setCenter(marker.position as google.maps.LatLng);
});
}
initMap();
// [END maps_event_simple]
export { };