-
Notifications
You must be signed in to change notification settings - Fork 821
/
index.ts
51 lines (45 loc) · 1.15 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
47
48
49
50
51
/**
* @license
* Copyright 2019 Google LLC. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/
// [START maps_user_editable_shapes]
// This example adds a user-editable rectangle to the map.
function initMap(): void {
const map = new google.maps.Map(
document.getElementById("map") as HTMLElement,
{
center: { lat: 44.5452, lng: -78.5389 },
zoom: 9,
}
);
// [START maps_user_editable_shapes_rectangle]
const bounds = {
north: 44.599,
south: 44.49,
east: -78.443,
west: -78.649,
};
// Define a rectangle and set its editable property to true.
const rectangle = new google.maps.Rectangle({
bounds: bounds,
editable: true,
draggable: true,
});
// [END maps_user_editable_shapes_rectangle]
rectangle.setMap(map);
// listen to changes
["bounds_changed", "dragstart", "drag", "dragend"].forEach((eventName) => {
rectangle.addListener(eventName, () => {
console.log({ bounds: rectangle.getBounds()?.toJSON(), eventName });
});
});
}
declare global {
interface Window {
initMap: () => void;
}
}
window.initMap = initMap;
// [END maps_user_editable_shapes]
export {};