Created
December 28, 2013 09:13
-
-
Save webaware/8157590 to your computer and use it in GitHub Desktop.
Valter wants to centre a KML map in WP Flexible Map; this plugin will do that for a map with id=kml_centred on a post/page with custom field 'flxmap-centre' that has the centre coordinate. e.g. `[flexiblemap id="kml_centred" src="http://goo.gl/pDG8hl" width="100%" zoom="10" maptype="satellite"]`
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 Valter KML map | |
Description: Valter wants to centre/zoom KML maps | |
Version: 1 | |
Author: WebAware | |
Author URI: http://wordpress.org/support/topic/testing-sometimes-it-does-not-work?replies=5#post-5040741 | |
*/ | |
add_action('wp_enqueue_scripts', function() { | |
wp_enqueue_script('jquery'); | |
}); | |
add_action('wp_print_footer_scripts', function() { | |
global $post; | |
if ($post) { | |
$centre = get_post_meta($post->ID, 'flxmap-centre', true); | |
if ($centre) { | |
?> | |
<script> | |
jQuery(window).on("load", function() { | |
if (window.flxmap_kml_centred) { | |
var flxmap = window.flxmap_kml_centred, | |
map = flxmap.getMap(), | |
centre = new google.maps.LatLng(<?php echo esc_js($centre); ?>); | |
flxmap.setCenter(centre); | |
google.maps.event.addListenerOnce(map, "zoom_changed", function() { | |
map.setCenter(centre); | |
}); | |
} | |
}); | |
</script> | |
<?php | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment