javascript - 在 Angular 2 Google map 上移动 map 控件

标签 javascript google-maps angular angular2-google-maps

我正在寻找一种方法来使用常规谷歌地图中可用的 zoomControlOptiions 属性,如下所示:

zoomControlOptions: {
  style: google.maps.ZoomControlStyle.SMALL,
  position: google.maps.ControlPosition.LEFT_CENTER
},

Stackoverflow example showing code above
Same thing in the official google maps docs

不幸的是,我在 Angular 2 Google map 中看不到这个选项 API Docs .有办法吗?尽管使用了 Angular 2 包装器,有没有办法使用全部功能?

enter image description here

请注意,只要运行这段代码就可以正常工作:

    map.setOptions({
      zoom: 1,
      center: position,
      zoomControl: true
    });

    console.log(map.getZoom());

我能够获取 native 谷歌地图对象并在其上运行方法/设置属性。当我尝试使用直接来自 docszoomControlOptions 时出现问题。


编辑:所以,它确实有效,现在的问题是绕过 Typescript 编译器的提示。

编辑 2:我解决了这个问题,但如果有人想要赏金 - 请随时解释为什么 zoomControlOptions 不是本地可用的。

最佳答案

您可以获得对 native map 对象的引用,然后添加 zoomControlOptions。在 https://github.com/philipbrack/example-angular2-google-maps-getNativeMap 中可以找到获取 map 引用的完整示例。 :

import {Component, OnInit} from '@angular/core';

import {GoogleMapsAPIWrapper} from 'angular2-google-maps/core';

declare var google:any;

@Component({
  selector: 'app-map-content',
  template: ''
})
export class MapContentComponent implements OnInit {

  constructor(public mapApiWrapper:GoogleMapsAPIWrapper) {

  }

  ngOnInit() {

    this.mapApiWrapper.getNativeMap()
      .then((map)=> {

        // I have been manually updating core/services/google-maps-types.d.ts to include things they didn't include.
        console.log(map.getZoom());

        let position = new google.maps.LatLng(45.521, -122.677);

        var cityCircle = new google.maps.Circle({
          strokeColor: '#FF0000',
          strokeOpacity: 0.8,
          strokeWeight: 2,
          fillColor: '#FF0000',
          fillOpacity: 0.35,
          map: map,
          center: position,
          radius: 10000
        });


      });

  }

}

关于javascript - 在 Angular 2 Google map 上移动 map 控件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42372619/

相关文章:

javascript - 重复 MinifiedJS 函数 X 次?

javascript - 可拖动在 jqueryUI 中不起作用

google-maps - 用于地理编码的 map API key 不起作用

javascript - jQuery timpicker 方法内的 Angular2 组件上下文

Angular 6 如何在应用程序组件加载之前加载服务?

javascript - 如何在angular2中通过id引用模板?

javascript - <a> 为 :hover or <div> with hover event for buttons?

javascript - Google Maps API 将监听器添加到标记数组

java - 经纬度 : Check whether a given point of LatLng is within a 5km radius of another point

javascript - JSON.parse 后对象中的函数不再是函数