-
Notifications
You must be signed in to change notification settings - Fork 824
/
Copy pathindex.js
51 lines (48 loc) · 1.53 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
49
50
51
/**
* @license
* Copyright 2019 Google LLC. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/
// [START maps_layer_data_dynamic]
let map;
function initMap() {
map = new google.maps.Map(document.getElementById("map"), {
zoom: 4,
center: { lat: -28, lng: 137 },
});
// Load GeoJSON.
map.data.loadGeoJson(
"https://storage.googleapis.com/mapsdevsite/json/google.json",
);
// [START maps_layer_data_dynamic_snippet]
// Color each letter gray. Change the color when the isColorful property
// is set to true.
map.data.setStyle((feature) => {
let color = "gray";
if (feature.getProperty("isColorful")) {
color = feature.getProperty("color");
}
return /** @type {!google.maps.Data.StyleOptions} */ {
fillColor: color,
strokeColor: color,
strokeWeight: 2,
};
});
// When the user clicks, set 'isColorful', changing the color of the letters.
map.data.addListener("click", (event) => {
event.feature.setProperty("isColorful", true);
});
// When the user hovers, tempt them to click by outlining the letters.
// Call revertStyle() to remove all overrides. This will use the style rules
// defined in the function passed to setStyle()
map.data.addListener("mouseover", (event) => {
map.data.revertStyle();
map.data.overrideStyle(event.feature, { strokeWeight: 8 });
});
map.data.addListener("mouseout", (event) => {
map.data.revertStyle();
});
// [END maps_layer_data_dynamic_snippet]
}
window.initMap = initMap;
// [END maps_layer_data_dynamic]