Map zoomed out too far
Hi Ben, I have a template integration calling wpgeo_map($args) on my site. It's working, but it's showing north america and markers twice because it's zoomed out too much. If there is no way to set zoom by argument can you suggest where in the code I should start to modify the zoom behavior of wpgeo_map()?
What $args are you currently using?
If you map shows multiple markers the map will automatically zoom out far enough to view them all. You can reset a different zoom using the 'wpgeo_map_js_preoverlays' filter. It needs to trigger on the bounds_changed event as well as immediately. You'll need to add the filter before your map and remove it afterwards:
function my_wpgeo_map_js_preoverlays_zoom( $content, $map_js_id ) {
$zoom = 3;
$content .= '
google.maps.event.addListenerOnce(' . $map_js_id . ', "bounds_changed", function() {
' . $map_js_id . '.setZoom(' . $zoom . ');
});
' . $map_js_id . '.setZoom(' . $zoom . ');
';
return $content;
}
add_filter( 'wpgeo_map_js_preoverlays', 'my_wpgeo_map_js_preoverlays_zoom', 10, 2 );
wpgeo_map($args)
remove_filter( 'wpgeo_map_js_preoverlays', 'my_wpgeo_map_js_preoverlays_zoom', 10, 2 );
Thank you Ben! However I didn't have luck with this. I put the function in my template functions.php file and added the filter calls before and after the map function as you indicated. The args I am making are numberposts, height, and cat.