AngularJS Google Map directive map instance

微笑、不失礼 提交于 2019-12-18 05:53:57

问题


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.


回答1:


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!!!



来源:https://stackoverflow.com/questions/22786918/angularjs-google-map-directive-map-instance

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!