|
84 | 84 |
|
85 | 85 | <select id="type" onchange="filterMarkers(this.value);"> |
86 | 86 | <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> |
89 | 89 | <option value="third">third</option> |
90 | 90 | </select> |
91 | 91 |
|
| 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 | + |
92 | 100 | </body> |
93 | 101 |
|
94 | 102 | <script type="text/javascript"> |
95 | 103 | var map, infoWindow; |
96 | 104 | var spots = {{{spots}}}; // this is the location data from the database |
97 | | -var gmarkers1 = []; |
98 | | -var markers1 = []; |
| 105 | +var allMarkers = []; |
99 | 106 |
|
100 | 107 | function initMap() { |
101 | 108 | latLng = new google.maps.LatLng(49, 123) |
@@ -130,7 +137,6 @@ function initMap() { |
130 | 137 | }); */ |
131 | 138 |
|
132 | 139 | for (var i = 0; i < spots.length; i++) { // loop through all the locations and render a marker |
133 | | - console.log(spots[i].coords); |
134 | 140 | var outlet = "No"; |
135 | 141 | if (spots[i].isOutlet) { outlet = "Yes"; } |
136 | 142 | 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) { |
179 | 185 |
|
180 | 186 | var marker = new google.maps.Marker({ |
181 | 187 | position: coords, |
182 | | - map: map |
| 188 | + map: map, |
| 189 | + type: type, |
| 190 | + goodFor: goodFor |
183 | 191 | }); |
184 | 192 |
|
| 193 | + allMarkers.push(marker); |
| 194 | +
|
185 | 195 | marker.addListener('click', function() { |
186 | 196 | infowindow.open(map, marker); |
187 | 197 | }); |
188 | 198 |
|
189 | 199 | } |
190 | 200 |
|
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 | + } |
193 | 214 | } |
194 | 215 |
|
| 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 | +
|
195 | 232 | </script> |
196 | 233 |
|
197 | 234 | <!-- Reference javascripts for Google Maps API --> |
|
0 commit comments