/
inline.html
executable file
·178 lines (166 loc) · 5.53 KB
/
inline.html
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
<!DOCTYPE html>
<html>
<head>
<title>Marker Collision Management</title>
<script src="https://polyfill.io/v3/polyfill.min.js?features=default"></script>
<link
href="https://unpkg.com/material-components-web@6.0.0/dist/material-components-web.css"
rel="stylesheet"
/>
<script src="https://unpkg.com/material-components-web@6.0.0/dist/material-components-web.min.js"></script>
<link
rel="stylesheet"
href="https://fonts.googleapis.com/icon?family=Material+Icons"
/>
<script
src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&callback=initMap&libraries=&v=beta&map_ids=3a3b33f0edd6ed2a"
defer
></script>
<style type="text/css">
:root {
--mdc-theme-primary: #1a73e8;
--mdc-theme-secondary: #rgb(225, 245, 254);
--mdc-theme-on-primary: #fff;
--mdc-theme-on-secondary: rgb(1, 87, 155);
}
.mdc-select--focused .mdc-select__dropdown-icon {
background: url(data:image/svg+xml,%3Csvg%20width%3D%2210px%22%20height%3D%225px%22%20viewBox%3D%227%2010%2010%205%22%20version%3D%221.1%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20xmlns%3Axlink%3D%22http%3A%2F%2Fwww.w3.org%2F1999%2Fxlink%22%3E%0A%20%20%20%20%3Cpolygon%20id%3D%22Shape%22%20stroke%3D%22none%22%20fill%3D%22%23000%22%20fill-rule%3D%22evenodd%22%20opacity%3D%220.54%22%20points%3D%227%2010%2012%2015%2017%2010%22%3E%3C%2Fpolygon%3E%0A%3C%2Fsvg%3E)
no-repeat center;
}
.mdc-select:not(.mdc-select--disabled).mdc-select--focused
.mdc-floating-label {
color: var(--mdc-theme-primary);
}
/* Optional: Makes the sample page fill the window. */
html,
body {
height: 100%;
margin: 0;
padding: 0;
}
#container {
height: 100%;
display: flex;
}
#sidebar {
flex-basis: 15rem;
flex-grow: 1;
padding: 1rem;
max-width: 30rem;
height: 100%;
box-sizing: border-box;
display: flex;
}
#map {
flex-basis: 0;
flex-grow: 4;
height: 100%;
}
.mdc-select__anchor,
.mdc-select__menu {
width: 100%;
}
</style>
<script>
"use strict";
// eslint-disable no-undef
let map; // Initialize and add the map
function initMap() {
let markers = [];
let collisionBehavior = google.maps.CollisionBehavior.REQUIRED;
map = new google.maps.Map(document.getElementById("map"), {
mapId: "3a3b33f0edd6ed2a",
center: {
lat: 47.609414458375674,
lng: -122.33897030353548
},
zoom: 17
});
const menuList = document.querySelector(".mdc-list"); // Add the behaviors to the select options
for (const [key, value] of Object.entries(
google.maps.CollisionBehavior
)) {
const item = document.createElement("LI");
item.classList.add("mdc-list-item");
item.setAttribute("data-value", key);
const itemText = document.createElement("SPAN");
itemText.classList.add("mdc-list-item__text");
itemText.innerText = value;
item.appendChild(itemText);
menuList.appendChild(item);
}
const select = new mdc.select.MDCSelect(
document.querySelector(".mdc-select")
);
select.listen("MDCSelect:change", () => {
collisionBehavior = select.value;
markers.forEach(marker => {
marker.set("collisionBehavior", collisionBehavior);
});
});
select.value = collisionBehavior; // Create some markers on the map
markers = [
[-122.3402, 47.6093],
[-122.3402, 47.6094],
[-122.3403, 47.6094],
[-122.3384, 47.6098],
[-122.3389, 47.6095],
[-122.3396, 47.6095],
[-122.3379, 47.6097],
[-122.3378, 47.6097],
[-122.3396, 47.6091],
[-122.3383, 47.6089],
[-122.3379, 47.6093],
[-122.3381, 47.6095],
[-122.3378, 47.6095]
].map(
([lng, lat]) =>
new google.maps.Marker({
position: new google.maps.LatLng({
lat,
lng
}),
map,
collisionBehavior: collisionBehavior
})
);
}
</script>
</head>
<body>
<div id="container">
<div id="map"></div>
<div id="sidebar">
<div class="mdc-select mdc-select--outlined">
<div
class="mdc-select__anchor"
aria-labelledby="outlined-select-label"
>
<input
type="text"
disabled
readonly
id="demo-selected-text"
class="mdc-select__selected-text"
/>
<i class="mdc-select__dropdown-icon"></i>
<span class="mdc-notched-outline">
<span class="mdc-notched-outline__leading"></span>
<span class="mdc-notched-outline__notch">
<span
id="outlined-select-label"
class="mdc-floating-label mdc-theme--primary"
>Pick a Collision Behavior</span
>
</span>
<span class="mdc-notched-outline__trailing"></span>
</span>
</div>
<div class="mdc-select__menu mdc-menu mdc-menu-surface">
<ul class="mdc-list"></ul>
</div>
</div>
</div>
</div>
</body>
</html>