【问题标题】:How can delete a polygon on google maps Ionic 3如何在谷歌地图 Ionic 3 上删除多边形
【发布时间】:2018-12-27 13:29:53
【问题描述】:

我是使用 Ionic 3 使用 Cordova 的 Native Google Maps API 的新手,我想知道使用按钮删除多边形、标记、圆形等的方法,例如。

实际上,我在一个名为loadMap() 的方法中创建了一个多边形并且它可以工作。但我希望能够通过另一种方法,如removePolygon(),删除多边形。

我的loadMap()code 如下:

loadMap() {

    let mapOptions: GoogleMapOptions = {
        camera: {
            target: {
                lat: 39.695263,
                lng: 3.017571
            },
            zoom: 8,
        }
    };

    this.map = GoogleMaps.create('map_canvas', mapOptions);

    let myPolygonCoord: ILatLng[] = [

        {
            lat: 39.81952717082459,
            lng: 3.1078016219598794
        },
        {
            lat: 39.7794339492445,
            lng: 3.0212842879755044
        },
        {
            lat: 39.66007130788319,
            lng: 3.1476270614130044
        },
        {
            lat: 39.72030660365558,
            lng: 3.2739698348505044
        }
    ];
    let myPolygon: PolylineOptions = {
        'points': myPolygonCoord,
        'strokeColor': '#89c3eb',
        'fillColor': '#89c3eb',
        'strokeWidth': 2
    };

    this.map.addPolygon(myPolygon).then((polygon: Polygon) => {});

}

另一方面,关于removePolygon()的方法:

 removePolygon(){
   //how to call the map and remove the polygon? 
 }

任何帮助将不胜感激。

【问题讨论】:

    标签: google-maps cordova ionic-framework polygon


    【解决方案1】:

    好吧,在尝试了不同的东西之后,我可以找到解决这个问题的方法。

    声明一个变量,用来存储创建多边形后返回的值,之后,只需使用remove方法即可:

    generalPolygon : any;

    this.map.addPolygon(myPolygon).then((polygon: Polygon) => {this.generalPolygon = polygon});

    removePolygon(){ this.generalPolygon.remove(); }

    就是这样。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-07-22
      • 2019-11-12
      • 2012-07-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多