WP-Geo icon indicating copy to clipboard operation
WP-Geo copied to clipboard

Map zoomed out too far

Open clay123 opened this issue 12 years ago • 3 comments

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()?

clay123 avatar Jul 26 '13 15:07 clay123

What $args are you currently using?

benhuson avatar Dec 13 '13 22:12 benhuson

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 );

benhuson avatar Jan 07 '14 20:01 benhuson

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.

clay123 avatar Jan 23 '14 01:01 clay123