html - JQuery FancyBox with Google Maps -
i able print map using drupal code in div. map appear inside fancybox , hidden on website. i've managed (fancybox works ok) map not displayed correctly - there no navigation , grey empty area inside map (though google logo there). have idea wrong here? guess might case id renders 1 element, renders background , rest ignored, honest have no idea(use class instead). advice appreciated. thanks
my code:
<script type="text/javascript"> $(document).ready(function() { $("a#inline").fancybox({ 'hideoncontentclick': true, 'overlaycolor' : '#ccffee', 'overlayopacity' : 0.8 }); }); </script> link show map:
<a id="inline" href="#mapcontainer" > show map </a> actual div prints map (works when set visible)
<div style="display:none"> <div id="mapcontainer"> <?php print $node->content['field_maploc']['field']['items']['#children'] ?> </div></div> the php code generates following html:
<div style="width: auto; height: 400px;" id="openlayers-container-openlayers-map-auto-id-0" class="openlayers-container openlayers-container-preset-question_map"> <div style="width: auto; height: 400px;" id="openlayers-map-auto-id-0" class="openlayers-map openlayers-preset-question_map"></div> </div> the current output - 
it seems issue (bug?) when google maps initialized in hidden div (can same case when using tabs) since display:none may set width , height 0.
when inline map visible, fancybox able compute dimensions, hence works when remove display:none.
the workaround should resizing map once fancybox opened map fit fancybox dimensions. can use oncomplete callback that.
other things bear in mind:
- you may need set
autodimensionseithertrueorfalsedepending on whether selector#mapcontainerhas css dimensions or not (setfalseif not, otherwise settrue.) think has dimensions since can display map inline initial valuetrue. - since using inline content (fancybox v1.3.x) beware of this bug. same link shows workaround.
so fancybox custom script should like:
$("a#inline").fancybox({ 'hideoncontentclick': false, // can handle map 'overlaycolor' : '#ccffee', 'overlayopacity' : 0.8, 'autodimensions': true, // selector #mapcontainer has css width , height 'oncomplete': function(){ google.maps.event.trigger(map, "resize"); }, 'oncleanup': function() { var mycontent = this.href; $(mycontent).unwrap(); } // fixes inline bug }); the method resize map might different depending on version of google maps api using
you can check https://stackoverflow.com/a/2590049/1055987 further reference.
update: have added demo here
Comments
Post a Comment