I'm using Google Maps API V3 in a .js file loaded by turbolinks.
The map rendering is triggered when the $('#google-map')
element is loaded:
function initGoogleMap() {
...
var map = new google.maps.Map($('#google-map').get(0), mapOptions);
...
}
$('#google-map').ready(function() {
initGoogleMap();
});
The problem is that when initGoogleMap()
runs, it uses the width and height of $('#google-map')
to render the map, and at this point the width and height are 0.
The width and height are defined in a .scss file named after the controller:
.map {
height: 300px;
width: 400px;
#google-map {
height: 300px;
width: 400px;
}
}
I'm using rails' conventions, so in my view template there is no mention of either the .js filename or the .scss filename.
How can I make sure the script only runs after the stylesheet is loaded?