-
Notifications
You must be signed in to change notification settings - Fork 0
/
site.js
98 lines (96 loc) · 2.93 KB
/
site.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
86
87
88
89
90
91
92
93
94
95
96
97
98
var sfMovies = new XMLHttpRequest();
var url = "http://localhost:8000/api/movies";
var markers = [];
function geocodeAddress(geocoder, map, arr, movieInfo) {
var address = arr[i][1] + " San Francisco, CA";
var actorOne = arr[i][2];
var actorTwo = arr[i][3];
var year = arr[i][4];
var movieTitle = arr[i][5];
geocoder.geocode({'address': address}, function(results, status) {
if (status === 'OK') {
map.setCenter({lat: 37.758207, lng: -122.413060});
var marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location
});
google.maps.event.addListener(marker, 'click', (function(marker, i) {
return function() {
movieInfo.setContent("<strong>" + movieTitle + "</strong><br/> Released " + year + "<br> Starring " + actorOne + " and " + actorTwo + "<br/>Scenes filmed at " + address);
movieInfo.open(map, marker);
}
})(marker, i));
} else {
//alert('Geocode was not successful for the following reason: ' + status + address);
}
});
}
function objs2Arr (arrayOfObjects, newArray) {
for (let obj of arrayOfObjects) {
obj = Array.from(Object.values(obj));
newArray.push(obj);
}
}
function removeBadArr (arrayOfArrays) {
for (var i = (arrayOfArrays.length - 1); i >= 0; i--) {
var specArr = arrayOfArrays[i]
var index = arrayOfArrays.indexOf(specArr);
if (specArr.length < 7 ) {
arrayOfArrays.splice(index, 1);
}
}
}
sfMovies.open("GET", url, true);
sfMovies.send();
sfMovies.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
var info = JSON.parse(this.responseText);
objs2Arr(info, markers);
removeBadArr(markers);
initMap(markers)
}
}
//do not edit above this comment
function initMap(arr = markers) {
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 13,
center: {lat: 37.758207, lng: -122.413060}
});
var movieInfo = new google.maps.InfoWindow();
for( i = 0; i < arr.length; i++ ) {
var geocoder = new google.maps.Geocoder();
geocodeAddress(geocoder, map, arr, movieInfo);
}
}
function filter (searchInput) {
var newMarker = [];
var search = searchInput
newSearch = search.toLowerCase()
for (let loc of markers) {
for (let info of loc) {
info = String(info);
info = info.toLowerCase();
var check = info.includes(newSearch);
if(check) {
newMarker.push(loc);
}
else {
//alert('we may have an issue')
}
}
}
initMap(newMarker);
}
function validateForm() {
var searchInput = document.forms["search"]["input"].value;
console.log(searchInput);
filter(searchInput);
var params = "search="+ searchInput;
var movieInput = new XMLHttpRequest();
movieInput.open("POST", "http://localhost:8000/api/google", true);
movieInput.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
movieInput.send(params);
return false;
}
//var searchBar = document.getElementById("search");
//searchBar.addEventListener("keyup", filter);