-
Notifications
You must be signed in to change notification settings - Fork 817
/
index.js
48 lines (42 loc) · 1.13 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
/**
* @license
* Copyright 2019 Google LLC. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/
// [START maps_polyline_remove]
// This example adds a UI control allowing users to remove the polyline from the
// map.
let flightPath;
let map;
function initMap() {
map = new google.maps.Map(document.getElementById("map"), {
zoom: 3,
center: { lat: 0, lng: -180 },
mapTypeId: "terrain",
});
const flightPathCoordinates = [
{ lat: 37.772, lng: -122.214 },
{ lat: 21.291, lng: -157.821 },
{ lat: -18.142, lng: 178.431 },
{ lat: -27.467, lng: 153.027 },
];
flightPath = new google.maps.Polyline({
path: flightPathCoordinates,
strokeColor: "#FF0000",
strokeOpacity: 1.0,
strokeWeight: 2,
});
// add event listener for click event
document.getElementById("add-line").addEventListener("click", addLine);
document.getElementById("remove-line").addEventListener("click", removeLine);
// initialize with line
addLine();
}
function addLine() {
flightPath.setMap(map);
}
function removeLine() {
flightPath.setMap(null);
}
window.initMap = initMap;
// [END maps_polyline_remove]