8

I'm using http://angular-google-maps.org/ it's nice angular google maps library. But i want use map instance which is loaded not in angularjs context by something like this:

$scope.map = {
events: {
    tilesloaded: function (map) {
            $scope.$apply(function () {
                $scope.mapInstance = map;           
            });
        }
    }
}

Ok nice i have mapInstance and I CAN use it programmatically. But in application lifecycle this fire to late- so in other words I want to load whole directive (and get map instance) before other code- where I just wan't to use other map events.

Nicramus
  • 606
  • 1
  • 6
  • 19

1 Answers1

26

In recently looking up ways to get the map instance from the example on the docs page, I came across this instead:

$scope.map.control.getGMap().

Make sure on your google-maps HTML markup, you have the options attribute set as control="map.control" and an empty object set in your $scope.map object.

$scope.map= { control : {}, ...other map options...};

That empty objects is filled when google map is initiated. I hope this helps and isn't too late.

Enjoy Angular!!!

Jessedc
  • 12,320
  • 3
  • 50
  • 63
EdwinA
  • 276
  • 3
  • 3
  • How do you promisify the map loading to ensure you don't try to render markers before for instance? – sgimeno Jan 13 '15 at 19:50
  • I'm not sure this is best practice, but im using $timeout,0 pattern to ensure that the map is actually instantiated (not necessarily tiles loaded) before referencing map.control. – Derek Mar 03 '15 at 16:31
  • I used the following code to ensure that map was instantiated: uiGmapGoogleMapApi.then(function() {// your code here}). Angular-google-maps also have IsReady service in their API – Olga Gnatenko Jun 09 '15 at 13:42
  • @OlgaGnatenko, Please explain how you get the map object from that function. – T.Coutlakis Jan 07 '16 at 22:28