-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmap.html
More file actions
331 lines (292 loc) · 12.1 KB
/
Copy pathmap.html
File metadata and controls
331 lines (292 loc) · 12.1 KB
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Student Stop Locator</title>
<link rel="shortcut icon" href="favicon.ico">
<style>
html,
body {
height: 100%;
margin: 0;
padding: 0;
overflow: hidden;
}
#map {
height: 100%;
width: 100%;
}
#search-input {
width: 70%;
padding: 8px;
font-size: 16px;
border: 1px solid black;
border-radius: 5px;
}
#search-and-manage {
display: flex;
justify-content: space-between;
align-items: center;
padding: 0 10px;
position: absolute;
top: 3%;
width: 100%;
z-index: 5;
transition: top 0.5s;
}
#back-arrow {
height: 23px;
width: 23px;
}
#clear-button {
margin-right: 5%;
height: 28px;
width: 28px;
}
#coordinates-save-container {
position: absolute;
display: flex;
justify-content: center;
/* Center items horizontally */
align-items: center;
/* Center items vertically */
padding: 5px;
bottom: 2%;
width: 100%;
box-sizing: border-box;
}
#coordinates {
padding: 10px;
font-size: 16px;
background-color: white;
border: 1px solid black;
border-radius: 5px;
margin-left: 10px;
/* Adjust margin as needed */
margin-right: 10px;
/* Adjust margin as needed */
}
#save-button {
padding: 10px 20px;
font-size: 16px;
background-color: white;
color: black;
border: 1px solid black;
/* Adding 1px black border */
border-radius: 5px;
font-weight: bold;
}
.gm-style .gm-style-cc,
.gmnoprint .gmnoprint {
display: none !important;
}
.gm-style .gm-style-mtc,
.gm-style .gm-style-mtc div,
.gm-style .gm-style-mtc span {
display: none !important;
}
#buttons-container {
position: absolute;
bottom: 25%;
right: 0%;
display: flex;
flex-direction: column;
align-items: center;
z-index: 5;
}
#buttons-container img {
height: 32px;
width: 32px;
margin-bottom: 10px;
margin-right: 10px;
}
#my-location-button {
background-color: white;
border-radius: 5px;
}
#map {
background-color: white;
}
</style>
</head>
<body>
<div id="search-and-manage">
<img id="back-arrow" src="img/backArrow.svg" alt="Back Arrow">
<input id="search-input" type="text" placeholder="Search for places...">
<img id="clear-button" src="img/clear_street.svg" alt="Clear">
</div>
<div id="map"></div>
<div id="coordinates-save-container">
<div id="coordinates">Loading...</div>
<button id="save-button">Save</button>
</div>
<div id="buttons-container">
<img id="refreshButton" src="img/refresh_street.svg" alt="refresh">
<img id="my-location-button" src="img/myLocation.svg" alt="My Location">
<img id="toggleButton" src="img/toSatellite.svg" alt="Satellite View">
</div>
<script>
let map;
let marker;
document.getElementById('back-arrow').addEventListener('click', function () {
window.parent.postMessage('closeMap', '*');
});
document.getElementById('clear-button').addEventListener('click', function () {
document.getElementById('search-input').value = '';
});
document.getElementById('refreshButton').addEventListener('click', function () {
// Remove the map instance and reinitialize it
initMap();
document.getElementById('toggleButton').src = 'img/toSatellite.svg';
document.getElementById('back-arrow').src = 'img/backArrow_street.svg';
document.getElementById('clear-button').src = 'img/clear_street.svg';
document.getElementById('refreshButton').src = 'img/refresh_street.svg';
});
function updateCoordinates(lat, lng) {
lat = lat.toFixed(6);
lng = lng.toFixed(6);
document.getElementById('coordinates').innerText = `[ ${lat} , ${lng}]`;
}
function initMap() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(
function (position) {
var pos = {
lat: position.coords.latitude,
lng: position.coords.longitude
};
updateCoordinates(pos.lat, pos.lng);
map = new google.maps.Map(document.getElementById('map'), {
center: pos,
zoom: 18,
fullscreenControl: false,
gestureHandling: 'greedy' // Enables single-finger map movement
});
marker = new google.maps.Marker({
position: pos,
map: map,
draggable: true,
icon: {
url: 'img/studentStop.svg',
scaledSize: new google.maps.Size(50, 50)
}
});
marker.addListener('dragend', function (event) {
updateCoordinates(event.latLng.lat(), event.latLng.lng());
});
map.addListener('click', function (event) {
marker.setPosition(event.latLng);
updateCoordinates(event.latLng.lat(), event.latLng.lng());
});
marker.addListener('click', function () {
map.setCenter(marker.getPosition());
map.setZoom(18);
});
initAutocomplete();
// Listen for the visibility change of the street view
map.getStreetView().addListener('visible_changed', function () {
if (map.getStreetView().getVisible()) {
document.getElementById('search-and-manage').style.top = '10%';
document.getElementById('back-arrow').src = 'img/backArrow_satellite.svg';
document.getElementById('clear-button').src = 'img/clear_satellite.svg';
} else {
document.getElementById('search-and-manage').style.top = '3%';
document.getElementById('back-arrow').src = 'img/backArrow_street.svg';
document.getElementById('clear-button').src = 'img/clear_street.svg';
}
});
},
function () {
handleLocationError(true, map.getCenter());
},
{
// enableHighAccuracy: true,
// timeout: 2000,
// maximumAge: 0
}
);
} else {
handleLocationError(false, map.getCenter());
}
}
function initAutocomplete() {
const input = document.getElementById('search-input');
const autocomplete = new google.maps.places.Autocomplete(input);
autocomplete.bindTo('bounds', map);
autocomplete.addListener('place_changed', function () {
const place = autocomplete.getPlace();
if (!place.geometry) {
alert("No details available for input: '" + place.name + "'");
return;
}
map.setCenter(place.geometry.location);
map.setZoom(18);
marker.setPosition(place.geometry.location);
updateCoordinates(place.geometry.location.lat(), place.geometry.location.lng());
});
}
function handleLocationError(browserHasGeolocation, pos) {
alert(browserHasGeolocation ? 'Error: The Geolocation service failed.' : 'Error: Your browser doesn\'t support geolocation.');
}
document.getElementById('save-button').addEventListener('click', function () {
const coordinatesElement = document.getElementById('coordinates').innerText;
window.parent.postMessage(coordinatesElement, '*');
const saveButton = document.getElementById('save-button');
saveButton.innerText = "Saved!";
setTimeout(() => {
saveButton.innerText = "Save";
}, 2000);
});
window.addEventListener('message', function (event) {
console.log('Coordinates received:', event.data);
});
document.getElementById('my-location-button').addEventListener('click', function () {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function (position) {
var pos = {
lat: position.coords.latitude,
lng: position.coords.longitude
};
map.panTo(pos);
marker.setPosition(pos);
map.setZoom(18);
}, function (error) {
handleLocationError(true, map.getCenter(), error.message);
}, {
enableHighAccuracy: true
});
} else {
handleLocationError(false, map.getCenter());
}
});
let flag = false;
document.getElementById('toggleButton').addEventListener('click', function () {
if (flag === false) {
map.setMapTypeId(google.maps.MapTypeId.HYBRID);
document.getElementById('toggleButton').src = 'img/toStreet.svg';
document.getElementById('back-arrow').src = 'img/backArrow_satellite.svg';
document.getElementById('clear-button').src = 'img/clear_satellite.svg';
document.getElementById('refreshButton').src = 'img/refresh_satellite.svg';
flag = true;
} else {
map.setMapTypeId(google.maps.MapTypeId.ROADMAP);
document.getElementById('toggleButton').src = 'img/toSatellite.svg';
document.getElementById('back-arrow').src = 'img/backArrow_street.svg';
document.getElementById('clear-button').src = 'img/clear_street.svg';
document.getElementById('refreshButton').src = 'img/refresh_street.svg';
flag = false;
}
});
window.onload = initMap;
</script>
<script
src="https://maps.googleapis.com/maps/api/js?key=AIzaSyDKquK0_Fe8Wr51YDrxghVdxebwHqG3ik4&libraries=places&callback=initMap"
async defer></script>
<script>
if (window.location.hostname !== '127.0.0.1' && window.location.hostname !== 'localhost') {
document.write('<script defer src="/_vercel/insights/script.js"><\/script>');
}
</script>
</body>
</html>