Re: Using a map in a div that is initially hidden.
I came across this problem with openlayers: http://trac.openlayers.org/ticket/2350
Basically, if a map starts off in a hidden div, then you show it later only part of a Google map layer will show. The area to the right and bottom will just show a grey panel.
The trick I discovered is to not create the map until the point in time at which is actually appears. You can apply the fixes in the ticket above if you prefer, but that means a hack to the OL source code so I did not fancy that.
In my case, I have a radio group, and when a certain radio item is selected want the map to show. I put the radio buttons in a div with id radios so that I can use a jQuery selector to respond to the click. The trick is to insert JavaScript before and after the call to create the map that wraps it so it does not get called until the radio button is clicked. Also we use jQuery("#map")[0].map which returns the openlayers map object or undefined if it does not already exist.
$r .= '<div id="map_wrapper" style="display:none;">';
data_entry_helper::$javascript .= 'jQuery("#radios input").click(
function() {
var $radioId = jQuery("input[name=smpAttr\\\\:'.$args['platform_attr_id'].']:checked").val();
if ($radioId == 1) {
jQuery("#map_wrapper").show();
// Following is inserted here to fix issue http://trac.openlayers.org/ticket/2350
if (typeof jQuery("#map")[0].map=="undefined") {
';
$r .= data_entry_helper::map_panel($options);
data_entry_helper::$javascript .= '}
} else {
jQuery("#map_wrapper").hide();
}
}
);'."\n";
$r .= '</div>';
Biodiverse IT