Created
April 25, 2018 01:18
-
-
Save stegel/aa1563778bf5022eb7a696bdb6ff0478 to your computer and use it in GitHub Desktop.
mapbox header template for Avada child
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$interactive = (is_page("home")) ? 0 : true; | |
$features = []; | |
$args = array( | |
"post_type" => 'asd_operation', | |
"facetwp" => false | |
); | |
$testQuery = new WP_Query( $args); | |
if ( $testQuery->have_posts() ) : while ( $testQuery->have_posts() ) : $testQuery->the_post(); | |
$terms = wp_get_post_terms( get_the_ID(),"asd_threats"); | |
$tag = $terms[0]->slug; | |
$location = get_field("location"); | |
$features[] = array( | |
"type" => "Feature", | |
"properties" => array( | |
"description" => get_the_title(), | |
"tags" => $tag, | |
"threats" => $tag, | |
"country" => str_replace(" ","-",strtolower(get_field("country"))), | |
"start_date" => get_field("start_date"), | |
"end_date" => get_field("end_date"), | |
"date_text" => get_field("date_text") | |
), | |
"geometry" => array( | |
"type" => "Point", | |
"coordinates" => [$location['lng'], $location['lat']] | |
) | |
); | |
endwhile; endif; | |
$features = json_encode($features); | |
?> | |
<div id='map' style='width: 1280px; height: 714px;'></div> | |
<script> | |
mapboxgl.accessToken = '###'; | |
var operations = { | |
"type" : "FeatureCollection", | |
"features": | |
<?php | |
echo $features; | |
?> | |
}; | |
var tagFull = { | |
malign : "Malign Finance", | |
political : "Social & Political Influence", | |
state : "State Influence", | |
cyber : "Cyber", | |
disinformation : "Disinformation" | |
}; | |
var layerIDs = []; // Will contain a list used to filter against. | |
var map = new mapboxgl.Map({ | |
container: 'map', | |
style: "mapbox://styles/stegel/cjep1g46z9krt2rqcvw6sou5g", | |
center: [-35.8408, 46.6878], | |
zoom: 1.9, | |
dragPan: <?php echo $interactive ?>, | |
scrollZoom: <?php echo $interactive ?>, | |
boxZoom: <?php echo $interactive ?>, | |
dragRotate: <?php echo $interactive ?>, | |
doubleClickZoom: <?php echo $interactive ?>, | |
touchZoomRotate: <?php echo $interactive ?>, | |
keyboard: <?php echo $interactive ?> | |
}); | |
map.on("load", function() { | |
map.addSource("operations", { | |
"type" : "geojson", | |
"data" : operations | |
}); | |
map.addLayer({ | |
"id" : "ops", | |
"type": "circle", | |
"source" : "operations", | |
"paint" : { | |
"circle-radius": 10, | |
"circle-stroke-width" : 8, | |
"circle-stroke-color" : [ | |
'match', | |
['get', 'tags'], | |
'malign', '#519462', | |
'political', '#643eb2', | |
'disinformation', '#ff6347', | |
'cyber', '#5194c0', | |
"state", "#ffdf47", | |
/* other */ '#ccc' | |
], | |
"circle-stroke-opacity" : 0.5, | |
"circle-color" : [ | |
'match', | |
['get', 'tags'], | |
'malign', '#519462', | |
'political', '#643eb2', | |
'disinformation', '#ff6347', | |
'cyber', '#5194c0', | |
"state", "#ffdf47", | |
/* other */ '#ccc' | |
] | |
} | |
}); | |
jQuery(document).on('facetwp-loaded', function() { | |
var threatFilter, countryFilter, newFilter; | |
// get filters | |
threatFilter = (FWP.facets.threat[0]) ? FWP.facets.threat[0] : "" ; | |
threatFilter = (FWP.facets.threat[0]) ? ["==","threats", FWP.facets.threat[0]] : ["!=","threats", '""'] ; | |
countryFilter = (FWP.facets.country[0]) ? ["==","country", FWP.facets.country[0]] : ["!=","country", '""'] ; | |
newFilter = ["all", threatFilter, countryFilter]; | |
console.log(newFilter); | |
console.log(operations); | |
map.setFilter('ops', newFilter); | |
}); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment