-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmap-script.js
268 lines (230 loc) · 8.48 KB
/
map-script.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
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
var searchInput;
var properties = []
var markers = []; // keep tracker of markers created from search
var infoWindows = []; // show info when you click on a marker
var map;
var lastOpenedWindow = null;
var mapCenter = { lat: 34.4133, lng: -119.8610 };
//var landlords = ["Wolfe","Sierra","SFM","The Hive"];
var resultArray = [];
// I think we don't want reviews making this page too busy
var resultTemplate =
`
<div class="row">
<div class="col-sm-3">
<img src={{imageUrl}} class="img-rounded" style="max-width:300px">
<div class="review-block-name"><a href={{landlordPage}} target=”_blank”>{{landlord}}</a></div>
<div class="review-block-date">{{address}}</div>
</div>
<div class="col-sm-9">
<div class=" col review-block-rate">
<span class="fa fa-star {{star1}}"></span>
<span class="fa fa-star {{star2}}"></span>
<span class="fa fa-star {{star3}}"></span>
<span class="fa fa-star {{star4}}"></span>
<span class="fa fa-star {{star5}}"></span>
</div>
<div class="review-block-title">{{reviewHeader}}</div>
<div class="review-block-description">{{reviewBody}}</div>
</div>
</div>
<hr>
`;
function Result(imgUrl,stars,address,landlord,landlordPage){
this.imageUrl = imgUrl;
this.star1 = (stars >= 1)?"checked-star":"";
this.star2 =(stars >= 2)?"checked-star":"";
this.star3= (stars >= 3)?"checked-star":"";
this.star4 = (stars >= 4)?"checked-star":"";
this.star5 =(stars >= 5)?"checked-star":"";
this.address = address;
this.landlord = landlord;
this.landlordPage = landlordPage;
}
/*
var reviewTest = {
"imageUrl": "http://dummyimage.com/60x60/666/ffffff&text=No+Image",
"username": "Bobby",
"reviewDate": "January 29, 2016",
"star1": (landlordRating >= 1)?"checked-star":"",
"star2": (landlordRating >= 2)?"checked-star":"",
"star3": (landlordRating >= 3)?"checked-star":"",
"star4": (landlordRating >= 4)?"checked-star":"",
"star5": (landlordRating >= 5)?"checked-star":"",
"reviewHeader": "Great Management",
"reviewBody": "his was nice in buy. this was nice in buy. this was nice in buy.this was nice in buy this was nice in buy this was nice in buy this was nice in buy this was nice in buy"
};
*/
//var geocoder = new google.maps.Geocoder;
function loadReviews() {
document.getElementById("reviews").innerHTML = "";
for (i = 0; i < results.length; i++) {
var reviewHTML = Mustache.render(resultTemplate, results[i]);
document.getElementById("reviews").innerHTML += reviewHTML;
}
}
function getLandlordInformation(searchForm) {
getProperties().then(function(properties){
Object.keys(properties).forEach(function(propertyID){
var request = {
location: map.getCenter(),
radius: '2000',
query: properties[propertyID].placeID,
};
var service = new google.maps.places.PlacesService(map);
service.textSearch(request, function callback(results, status) {
if (status == google.maps.places.PlacesServiceStatus.OK) {
var marker = new google.maps.Marker({ map: map, place: { placeId: results[0].place_id, location: results[0].geometry.location } });
}
});
});
});
setFilters();
// CLEAR MARKERS ON MAP
deleteMarkers();
// CLEAR PROPERTIES ARRAY
results = [];
properties = [];
document.getElementById("reviews").innerHTML = "";
getProperties().then(function(propertiesMap){
var properties = Object.values(propertiesMap);
var resultsMap = {};
for (i = 0; i < properties.length; ++i) {
if ((!searchInput || searchInput == properties[i].landlord) &&
(!minRent || properties[i].rent >= minRent) &&
(!maxRent || properties[i].rent <= maxRent) &&
(!minOccupants || properties[i].occupants >= minOccupants) &&
(!maxOccupants || properties[i].occupants <= maxOccupants)) {
results.push(new Result(properties[i].imageURL, 0, properties[i].address + " Unit " + properties[i].unit, "See property", "PropertyDetails.html?id='" + properties[i].placeID + "'"));
}
}
loadReviews();
});
//TODO: PUT RETRIEVED DATA INTO PROPERTIES ARRAY
properties = [{ title: "property 5", lat: 34.4133, lng: -119.8610 },
{ title: "property 6", lat: 34.4139, lng: -119.8612 },
{ title: "property 7", lat: 34.4131, lng: -119.8614 },
{ title: "property 8", lat: 34.4132, lng: -119.8616 },
{ title: "property 9", lat: 34.4134, lng: -119.8619 }] // FAKE RETRIEVED DATA
// SHOW NEW MARKERS
showMarkers();
// Display dummy results
}
var minRent = null;
var maxRent = null;
var minOccupants = null;
var maxOccupants = null;
function setFilters(){
minRent = null;
maxRent = null;
minOccupants = null;
maxOccupants = null;
searchInput = document.getElementById("landlord-dropdown").value;
if(document.getElementById("min-rent").value != ''){
minRent = document.getElementById("min-rent").value;
}
if(document.getElementById("max-rent").value != ''){
maxRent = document.getElementById("max-rent").value;
}
if(document.getElementById("min-occupants").value != ''){
minOccupants = document.getElementById("min-occupants").value;
}
if(document.getElementById("max-occupants").value != ''){
maxOccupants = document.getElementById("max-occupants").value;
}
console.log("min rent " + minRent + " max rent " + maxRent + " min occupants " + minOccupants + " max occupants " + maxOccupants);
}
/*function validate() {
if (searchInput === '') {
alert('Please Input Landlord You Want To Search');
return false;
}
else {
return true;
}
}*/
function myMap() {
map = new google.maps.Map(document.getElementById('googleMap'), {
zoom: 16,
center: mapCenter
});
}
function showMarkers() {
for (i = 0; i < properties.length; i++) {
var myLatLng = { lat: properties[i].lat, lng: properties[i].lng };
// create marker
markers[i] = new google.maps.Marker({
position: myLatLng,
map: map,
title: properties[i].title,
});
// add marker onclick listner
markers[i].addListener('click', function () {
if (lastOpenedWindow != null) {
lastOpenedWindow.close(map, this)
}
infoWindows[i] = new google.maps.InfoWindow();
infoWindows[i].setContent(this.get('title'));
infoWindows[i].open(map, this);
lastOpenedWindow = infoWindows[i];
});
}
}
// Removes the markers from the map, but keeps them in the array.
function clearMarkers() {
setMapOnAll(null);
}
// Deletes all markers in the array by removing references to them.
function deleteMarkers() {
clearMarkers();
markers = [];
}
// Sets the map on all markers in the array.
function setMapOnAll(map) {
for (var i = 0; i < markers.length; i++) {
markers[i].setMap(map);
}
infoWindows = [];
}
/*function drawRatingsGraph() {
var data = new google.visualization.DataTable();
data.addColumn('number', 'Year');
data.addColumn('number', 'Rating');
data.addRows(landlordRatings);
var options = {
title: "Landlord Ratings Over Time",
format: 'none',
legend: 'none',
hAxis: {
title: 'Year'
},
vAxis: {
title: 'Rating'
}
};
var chart = new google.visualization.LineChart(document.getElementById('ratingsGraph'));
chart.draw(data, options);
}*/
// Obtain the type (landlord or property) and the value (name of landlord or address of property) that was clicked from the URL
var queryString = decodeURIComponent(window.location.search);
queryString = queryString.substring(1);
var queries = queryString.split("'");
// The variable 'type' will either be 'landlord' or 'property'
var type = queries[1];
// The variable 'value' will either be the name of a landlord or the address of a property, as described by the 'type' variable.
var value = queries[3];
$(document).ready(function () {
getLandlordsInfo().then(function(landlords){
var landlordDropdown = document.getElementById("landlord-dropdown");
for (i = 0; i < landlords.length; i++){
var optElement = document.createElement("option");
optElement.textContent = landlords[i].name;
optElement.value = landlords[i].id;
landlordDropdown.appendChild(optElement);
}
});
//var result = new Result("house9.jpg",5,"555 Storke Rd","UCSB Housing","https://www.rlwa.com/");
//resultArray = [result,result,result,result,result];
//console.log(resultArray);
myMap();
});