How to ensure map download

getGMap () returns an instance of a Map object. If the map is not ready, this function returns undefined. Is there an event or way that says the Map is ready and that the getGMap call will surely return a Google Map?

thank

Yash

+3


source to share


2 answers


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

+11


source


You can hook up to a chunked event by passing it to the events property of the map parameters. Tile fire after the tile is loaded onto the map (hence the map is loaded).



+1


source







All Articles