嗨,到目前为止,您一直热爱您的工作,但很好奇,该库是否会授予对整个google.maps对象的访问权限,类似于angular1对google-maps的实现? (请参见此处:http://angular-ui.github.io/angular-google-maps/#!/api/GoogleMapApi)
例如,获取google.maps对象可让您创建...
用于创建新DirectionsRenderer和DirectionsService的A1代码:
uiGmapGoogleMapApi.then(function(maps) {
vm.gmaps = maps;
vm.map.directionsDisplay = new vm.gmaps.DirectionsRenderer();
vm.map.directionsService = new vm.gmaps.DirectionsService();
});
或创建一个新的LatLng对象:
var latlng = new vm.gmaps.LatLng(lat, lng);
这个库有可能吗?
编辑:我确实看到Google对象在全球范围内可用。 但是,防止google对象污染全局名称空间不是该项目的目标之一吗?
编辑到编辑:现在也可以使用LatLngLiteral接口,这样可以解决一个问题:
import {LatLngLiteral} from 'angular2-google-maps/core';
...
var latlng = <LatLngLiteral>{lat: this.latitude, lng: this.longitude};
this.map.setCenter(latlng);
嗨cviccaro,
请参考下面提到的注释,以访问google.maps对象。
https://github.com/SebastianM/angular2-google-maps/issues/139#issuecomment -187343516
@ parmod-arora,
谢谢。 我设法获取了地图对象,但是我指的是整个SDK的API。 DirectionsRenderer和DirectionsService不在地图对象本身上,而是在google.maps命名空间上。
但是,在重新考虑这一点时,我认为直接访问完整的google.maps命名空间在设计上是不可用的,但是稍后可以使用它们周围的包装器。
@cviccaro ,
如果我错了,请纠正我,您想访问google.maps并想使用DirectionsRenderer和DirectionsService服务。
下面是代码。
declare var google: any;
@Directive({
selector: 'my-comp', // <home></home>
})
export class MyComp {
constructor(private _mapsWrapper:GoogleMapsAPIWrapper){
_mapsWrapper.getMap().then((m: mapTypes.GoogleMap) => {
console.log(google.maps);
});
}
}
确实是@ parmod-arora。 正如我在对原始帖子的编辑中所写的那样,我看到全局google对象确实可用,所以我猜我的问题有所偏离。 这个项目最终会从全局名称空间中删除google对象,提供导入模块以初始化DirectionsRenderer或DirectionsService吗?
该项目最终将从全局命名空间中删除google对象吗?
不,这不是该项目的目标。 它应该为angular2 / google地图提供易于使用的抽象层。 我们可以考虑如何使用Google Maps API的某些服务,例如DirectionsRenderer或DirectionsService。 我让这个开放式讨论Angular 2的良好API的外观
如果我正确理解了这里的所有内容,那么处理此问题的最有角度的方法不是拥有返回全局对象的服务吗? 这将启用模拟以进行测试,并避免全局依赖性。
嗨@cviccaro,您提到您已使google.maps对象正常工作,您能告诉我您是如何做到的吗? 是通过GoogleMapsAPIWrapper吗?
由于此问题最近没有活动,因此已被自动标记为陈旧。 如果没有其他活动发生,它将关闭。 感谢你的贡献。
最有用的评论
如果我正确理解了这里的所有内容,那么处理此问题的最有角度的方法不是拥有返回全局对象的服务吗? 这将启用模拟以进行测试,并避免全局依赖性。