Add function to filter markers by Traveler

This commit is contained in:
Markus Ankenbrand 2017-02-19 18:58:24 +01:00
parent ec1865e9e8
commit 1e9b9ab987

View file

@ -63,13 +63,13 @@
</div> <!-- /content -->
<?php
query_posts( 'category_name=urlaub&posts_per_page=1000' );
query_posts( 'category_name=urlaub&posts_per_page=10000' );
$locations = array();
while ( have_posts() ) : the_post();
$places = get_field('orte');
if($places){
foreach ($places as $place){
$locations[] = array_merge(array("post" => $post->ID, "title" => $post->post_title), $place);
$locations[] = array_merge(array("post" => $post->ID, "title" => $post->post_title, "traveler" => get_field('mitreisende')), $place);
}
}
endwhile;
@ -80,7 +80,9 @@
var places = <?php echo json_encode($locations); ?>;
var map;
var map_center = {lat: parseFloat(places[0]['lat']), lng: parseFloat(places[0]['lng']) };
var markers = [];
function initMap() {
markers = [];
map = new google.maps.Map(document.getElementById('map-stats'), {
center: map_center,
zoom: 15
@ -94,6 +96,7 @@
map: map
});
marker.setVisible(true);
markers.push(marker);
google.maps.event.addListener(marker, 'click', function() {
window.location.href = this.url;
});
@ -106,6 +109,15 @@
}
}, 500);
}
function filterMarkersByTraveler(traveler){
for(var i=0; i<markers.length; i++){
if(markers[i]['traveler'].index(traveler) > -1){
markers[i].setVisible(true);
} else {
markers[i].setVisible(false);
}
}
}
</script>