javascript - How to initiate Gmaps in hidden element -


i have 1 element (#hidden-element) hidden default. when click on button (#btn-toggle) want make element visible. now, fine. element shows up, if click on button first time, maps won't shows up. click hide element, again show hidden element second time , map here.

so, question is, how can shure map shows first time (i thing have initialize maps or that) , can somehow destroy map object? , destroying map object necessary?

$(document).ready(function(){    // function showing map markers - gmaps4rails gem   function showmap(){     var handler = gmaps.build('google');       handler.buildmap({ internal: {id: 'multi_markers'}}, function(){         var markers = handler.addmarkers([           { lat: 43, lng: 3.5},           { lat: 45, lng: 4},           { lat: 47, lng: 3.5},           { lat: 49, lng: 4},           { lat: 51, lng: 3.5}         ]);         handler.bounds.extendwith(markers);         handler.fitmaptobounds();       });   }    // hide element when document ready   $("#hidden-element").hide();   // if click on button id btn-toggle, element shows or hide   $("#btn-toggle").click(function(){     if ($('#hidden-element').is(':hidden')){       // necesarry have condition , check if element hidden or visible?     } else if ($('#hidden-element').is(':visible')){       // element hidden? show it!       showmap();     }       $("#hidden-element").toggle(1000);    }); }); 

so not error of library. think gmaps4rails don't know precise position of element when element showing up. have ensure element visible , show map:

$("#hidden-element").toggle(1000).promise().done(function(){       if ($('#hidden-element').is(':visible')){         showmap();       } }); 

this means maps load after element visible , took place on screen.


Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -