I have a map with many markers.
After resizing the map, it looks like this:
and I want this:
How can I zoom in and center the map on the markers after resizing?
I have the following code;
var map;
var GoogleMaps = {
setMarkers: function(stores){
map = new google.maps.Map(document.getElementById('map-canvas'));
$.each(stores, function (key, store) {
/* (..) */
bounds.extend(latLng);
});
map.fitBounds(bounds);
// This part is never triggered
google.maps.event.addDomListener(window, 'resize', function() {
var center = map.getCenter();
google.maps.event.trigger(map, "resize");
map.setCenter(center);
});
}
}
HTML
When I click the resize icon, I add a css class to map-canvas
<div class="map-container alt-row row-spacer clearfix">
<section class="column12">
<div id="map-canvas" class=""></div>
</section>
</div>
I've looked at similar questions (here and here), but they do not solve my problem.
Does anyone know how I can accomplish this? You can look at my JSFiddle here.