Skip to content

Instantly share code, notes, and snippets.

@webaware
Created May 18, 2016 23:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save webaware/3393b3ec78af8b302135bfb1d4956dd8 to your computer and use it in GitHub Desktop.
Save webaware/3393b3ec78af8b302135bfb1d4956dd8 to your computer and use it in GitHub Desktop.
Add a traffic layer to maps in Flexible Map; specify an ID so that the code can match the map requiring traffic layer. e.g. `[flexiblemap address="Wickham train station, Wickham NSW Australia" width="100%" region="au" id="with_traffic"]`
<?php
/*
Plugin Name: Flxmap Traffic Layer example
Plugin URI: https://gist.github.com/webaware/3393b3ec78af8b302135bfb1d4956dd8
Description: add a traffic layer to map that has id="with_traffic"
Version: 1
Author: WebAware
Author URI: http://webaware.com.au/
*/
if (!defined('ABSPATH')) {
exit;
}
add_action('wp_enqueue_scripts', function() {
wp_enqueue_script('jquery');
});
add_action('wp_footer', function() {
?>
<script>
jQuery(window).load(function($) {
if ("flxmap_with_traffic" in window) {
var map = flxmap_with_traffic.getMap();
var trafficLayer = new google.maps.TrafficLayer();
trafficLayer.setMap(map);
}
});
</script>
<?php
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment