-
Notifications
You must be signed in to change notification settings - Fork 822
/
index.js
38 lines (36 loc) · 1.03 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
/**
* @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() {
const map = new google.maps.Map(document.getElementById("map"), {
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 });
});
});
}
window.initMap = initMap;
// [END maps_user_editable_shapes]