AngularJS 谷歌地图指令地图实例 [英] AngularJS Google Map directive map instance
问题描述
我正在使用 http://angular-google-maps.org/ 这是一个很好的角度谷歌地图库.但我想使用这样的地图实例,它不是在 angularjs 上下文中加载的:
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;
});
}
}
}
好的,我有 mapInstance 并且我可以以编程方式使用它.但是在应用程序生命周期中,这个火到晚了 - 换句话说,我想在其他代码之前加载整个指令(并获取地图实例) - 我只是不想使用其他地图事件.
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.
推荐答案
最近在寻找从文档页面上的示例中获取地图实例的方法时,我遇到了这个:
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().
确保在您的 google-maps HTML 标记上,您的 options 属性设置为 control="map.control"
,并在您的 $scope.map
中设置了一个空对象代码>对象.
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.
享受 Angular 吧!!!
Enjoy Angular!!!
这篇关于AngularJS 谷歌地图指令地图实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!