Created
May 18, 2016 23:40
-
-
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"]`
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 | |
/* | |
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