dylanfprice / angular-gm

AngularJS Google Maps Directives
MIT License
197 stars 47 forks source link

Refresh the map #42

Closed LordZombi closed 10 years ago

LordZombi commented 10 years ago

Hello I want to know if is there ani option to refresh the map ? For example when is my map hidden and then shown I need to redraw the map because it renders wrong (dont see all the map, half map is gray). Thanks a lot.

dylanfprice commented 10 years ago

Yeah, try $scope.$broadcast('gmMapResize', 'myMapId'). It's in the docs but I noticed it doesn't say what the event is used for. I'll fix that.

LordZombi commented 10 years ago

Hello,

I meanwhile do this with gmapPromise and google.maps.event.trigger(gmap, 'resize')

var gmapPromise = angulargmContainer.getMapPromise('myMapId');
gmapPromise.then(function(gmap) {
    window.setTimeout(function(){
        google.maps.event.trigger(gmap, 'resize');
        // or
        // $scope.$broadcast('gmMapResize', 'myMapId');
    },100);
});

But look at the setTimeout function, it is quite important because for some reason you need to wait for a while before calling resize when you show hidden map. I dont know why but without setTimeout it doesnt work :/