angularjs - Angular Google Maps inside accordion is getting blank first time -
i'm using angular google maps bootstrap3
, html5
. i'm using angular google maps inside accordion.
the problem when write angular google maps inside accordion showed blank first time when come page (state)by browse page (state) works normal. if don't use accordion works fine always.
here code accordion show blank first time.
<accordion close-others="true"> <accordion-group heading="karta" is-open="map.open"> <div class="panel-body"> <div class="col-sm-12 col-xs-10 angular-google-map-container"> <ui-gmap-google-map center="localmap.center" zoom="localmap.zoom" events="localmap.events" draggable="true" refresh="localmap.refreshmap" ng-class="{'crosshair': waitingforinput}"> <ui-gmap-markers idkey="id" models="localmap.markers" coords="'self'" fit="'true'" options="'options'"> </ui-gmap-markers> </ui-gmap-google-map> </div> </div> </accordion-group> </accordion>
and if remove accordion works time.
<div class="panel-body"> <div class="col-sm-12 col-xs-10 angular-google-map-container"> <ui-gmap-google-map center="localmap.center" zoom="localmap.zoom" events="localmap.events" draggable="true" refresh="localmap.refreshmap" ng-class="{'crosshair': waitingforinput}"> <ui-gmap-markers idkey="id" models="localmap.markers" coords="'self'" fit="'true'" options="'options'"> </ui-gmap-markers> </ui-gmap-google-map> </div> </div>
please me solve issue.
i had same problem had div ng-show
directive evaluated false
on view-load , google maps map element initialized on view-load, too. div passed google maps api initialize map element inside ng-show='false'
div , blank map show.
i solved changing initializing of map element when ng-show
directive evaluated true
.
i think best if created google maps map element, when accordion got opened.
i had in custom directive easy put scope-watch inside link
method of directive. posting code future users might come across same problem.
angular.app('module').directive('customdirective', function ($timeout) { return { template: '...', link: function(scope, element) { var mapinitialized = false; # track if map has been initialized. var mapoptions = {...}; var initmap = function() { map = new google.maps.map(element.find(".map-elem")[0], mapoptions); mapinitialized = true; }; scope.$watch 'ismapelemcontainershown', function(newvalue, oldvalue) { if (newvalue == oldvalue) return; if (newvalue && !mapinitialized) { $timeout(initmap, 100); # allow delay view element update visible. } } } } }
Comments
Post a Comment