-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmap.js
85 lines (67 loc) · 3 KB
/
map.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
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
window.onload = function() {
var leftContainerGroup = document.querySelector('.left-container-group');
var bigContainer = document.querySelector('.big-container');
// Calculate the number of left containers
var numLeftContainers = leftContainerGroup.children.length;
// Add event listener to resize containers on window resize
window.addEventListener('resize', function() {
var windowWidth = window.innerWidth;
var containerWidth = windowWidth / 5 * 4; // 4 columns for left containers
var bigContainerWidth = windowWidth - containerWidth;
leftContainerGroup.style.width = containerWidth + 'px';
bigContainer.style.width = bigContainerWidth + 'px';
for (var i = 0; i < numLeftContainers; i++) {
leftContainerGroup.children[i].style.width = containerWidth / numLeftContainers + 'px';
}
});
// Initialize the containers on page load
var windowWidth = window.innerWidth;
var containerWidth = windowWidth / 5 * 4;
var bigContainerWidth = windowWidth - containerWidth;
leftContainerGroup.style.width = containerWidth + 'px';
bigContainer.style.width = bigContainerWidth + 'px';
for (var i = 0; i < numLeftContainers; i++) {
leftContainerGroup.children[i].style.width = containerWidth / numLeftContainers + 'px';
}
};
function initAutocomplete() {
var map = new google.maps.Map(document.getElementById('map'), {
center: {lat: -33.8688, lng: 151.2093},
zoom: 8
});
// Create the autocomplete objects.
var originField = document.getElementById('origin');
var destinationField = document.getElementById('destination');
var originAutocomplete = new google.maps.places.Autocomplete(originField);
var destinationAutocomplete = new google.maps.places.Autocomplete(destinationField);
// Add a listener for the user selecting a place.
originAutocomplete.addListener('place_changed', function() {
var place = originAutocomplete.getPlace();
if (!place.place_id) {
return;
}
'geocode' in map.options ?
map.geocode({'placeId': place.place_id}) :
map.setOptions({'geocode': true});
});
destinationAutocomplete.addListener('place_changed', function() {
var place = destinationAutocomplete.getPlace();
if (!place.place_id) {
return;
}
'geocode' in map.options ?
map.geocode({'placeId': place.place_id}) :
map.setOptions({'geocode': true});
});
}
google.maps.event.addDomListener(window, 'load', initAutocomplete);
function showSafePlaces() {
// Display the popup
var popup = document.getElementById('popup');
popup.style.display = 'block';
}
function closePopup() {
// Close the popup
var popup = document.getElementById('popup');
popup.style.display = 'none';
}