Skip to content

Commit 2c822c8

Browse files
committed
add simple filtering system, needs to be improved
1 parent 077eedd commit 2c822c8

File tree

1 file changed

+45
-8
lines changed

1 file changed

+45
-8
lines changed

views/index.hbs

Lines changed: 45 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,18 +84,25 @@
8484

8585
<select id="type" onchange="filterMarkers(this.value);">
8686
<option value="">Please select category</option>
87-
<option value="second">second</option>
88-
<option value="car">car</option>
87+
<option value="Everything">Everything</option>
88+
<option value="Freestyle">Freestyle</option>
8989
<option value="third">third</option>
9090
</select>
9191

92+
93+
<select id="type" onchange="filterMarkersType(this.value);">
94+
<option value="">Please select category</option>
95+
<option value="Field">Field</option>
96+
<option value="Forest">Forest</option>
97+
<option value="Building(s)">Building(s)</option>
98+
</select>
99+
92100
</body>
93101

94102
<script type="text/javascript">
95103
var map, infoWindow;
96104
var spots = {{{spots}}}; // this is the location data from the database
97-
var gmarkers1 = [];
98-
var markers1 = [];
105+
var allMarkers = [];
99106
100107
function initMap() {
101108
latLng = new google.maps.LatLng(49, 123)
@@ -130,7 +137,6 @@ function initMap() {
130137
}); */
131138
132139
for (var i = 0; i < spots.length; i++) { // loop through all the locations and render a marker
133-
console.log(spots[i].coords);
134140
var outlet = "No";
135141
if (spots[i].isOutlet) { outlet = "Yes"; }
136142
addMarker(spots[i].coords, spots[i].address, spots[i]._id, spots[i].points, spots[i].type, spots[i].goodFor, outlet);
@@ -179,19 +185,50 @@ function addMarker(coords, address, id, points, type, goodFor, hasOutlet) {
179185
180186
var marker = new google.maps.Marker({
181187
position: coords,
182-
map: map
188+
map: map,
189+
type: type,
190+
goodFor: goodFor
183191
});
184192
193+
allMarkers.push(marker);
194+
185195
marker.addListener('click', function() {
186196
infowindow.open(map, marker);
187197
});
188198
189199
}
190200
191-
function filterMarkers(category) {
192-
console.log(category);
201+
function filterMarkers(goodFor) {
202+
console.log(goodFor);
203+
for (i = 0; i < spots.length; i++) {
204+
marker = allMarkers[i];
205+
// If is same category or category not picked
206+
if (marker.goodFor == goodFor || goodFor.length === 0) {
207+
marker.setVisible(true);
208+
}
209+
// Categories don't match
210+
else {
211+
marker.setVisible(false);
212+
}
213+
}
193214
}
194215
216+
function filterMarkersType(type) {
217+
console.log(type);
218+
for (i = 0; i < spots.length; i++) {
219+
marker = allMarkers[i];
220+
// If is same category or category not picked
221+
if (marker.type == type || type.length === 0) {
222+
marker.setVisible(true);
223+
}
224+
// Categories don't match
225+
else {
226+
marker.setVisible(false);
227+
}
228+
}
229+
}
230+
231+
195232
</script>
196233

197234
<!-- Reference javascripts for Google Maps API -->

0 commit comments

Comments
 (0)