How to ensure map download
You can use the uiGmapIsReady
inside of your controller - cm. IsReady
In the docs .
uiGmapIsReady
returns:
- a promise when the card is loaded and ready. - an array of map information (which I named map_instances
)
- the length of the array depends on how many maps you have loaded on your page
- each object in the array includes a google map object
To use getGmap()
, ready for your control object would look like this:
Html
<div ng-app="myApp" ng-controller="myController">
<ui-gmap-google-map
center="map.center"
zoom="map.zoom"
control="map.control">
</ui-gmap-google-map>
</div>
CONTROLLER
myApp.controller('myController', function ($scope, uiGmapIsReady) {
$scope.map = {
center : {
latitude: 37.7749295,
longitude: -122.4194155
},
zoom : 14,
control : {}
};
uiGmapIsReady.promise()
.then(function (map_instances) {
var map1 = $scope.map.control.getGMap(); // get map object through $scope.map.control getGMap() function
var map2 = map_instances[0].map; // get map object through array object returned by uiGmapIsReady promise
});
});
Note how you can also access the map object in two ways:
- through an array map_instances
(which looks like [map1Instance, map2Instance, ...]
)
- through $scope.map.control.getGMap()
as long as you have defined it in your html and$scope
JSFIDDLE
source to share