Skip to content

Instantly share code, notes, and snippets.

@Fitoussi
Last active February 18, 2017 03:53
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 Fitoussi/6f30b80acba12a717f3dce9ffdbb83ae to your computer and use it in GitHub Desktop.
Save Fitoussi/6f30b80acba12a717f3dce9ffdbb83ae to your computer and use it in GitHub Desktop.
Trigger map resize when inside a tab.
function gmw_resize_tab_map() {
?>
<script type="text/javascript">
jQuery( 'document' ).ready( function($) {
// on click
jQuery( '.test_tab' ).on( 'click', function() {
setTimeout(function() {
// search for the map ID
var mapId = jQuery( '#tab-test' ).find( '.gmw-map' ).attr( 'id' ).replace(/[^0-9]/g, '');
if ( typeof gmwMapObjects[mapId] !== undefined ) {
// resize map
google.maps.event.trigger( gmwMapObjects[mapId].map, 'resize' );
// pan to marker
gmwMapObjects[mapId].map.panTo( gmwMapObjects[mapId]['markers'][0].getPosition() );
}
}, 100);
});
});
</script>
<?php
}
add_action( 'wp_footer', 'gmw_resize_tab_map', 99 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment