How to refresh the map when you resize your div
It's not enough just to call google.maps.event.trigger(map, 'resize');
You should reset the center of the map as well.
var map;
var initialize= function (){
...
}
var resize = function () {
if (typeof(map) == "undefined") {) {
// initialize the map. You only need this if you may not have initialized your map when resize() is called.
initialize();
} else {
// okay, we've got a map and we need to resize it
var center = map.getCenter();
google.maps.event.trigger(map, 'resize');
map.setCenter(center);
}
}
How to listen for the resize event
Angular (ng-show or ui-bootstrap collapse)
Bind directly to the element's visibility rather than to the value bound to ng-show, because the $watch can fire before the ng-show is updated (so the div will still be invisible).
scope.$watch(function () { return element.is(':visible'); },
function () {
resize();
}
);
jQuery .show()
Use the built in callback
$("#myMapDiv").show(speed, function() { resize(); });
Bootstrap 3 Modal
$('#myModal').on('shown.bs.modal', function() {
resize();
})