Google maps 如何在谷歌地图3上删除多边形

Google maps 如何在谷歌地图3上删除多边形,google-maps,cordova,ionic-framework,polygon,Google Maps,Cordova,Ionic Framework,Polygon,我对使用Ionic 3的本地Google Maps API和Cordova是新手,我想知道如何使用按钮删除多边形、标记、圆等 实际上,我在一个名为loadMap()的方法中包含了创建多边形的部分,它可以工作。但我希望能够从另一种方法,如removePolygon(),删除多边形 我的loadMap()代码如下: loadMap() { let mapOptions: GoogleMapOptions = { camera: { target: {

我对使用Ionic 3的本地Google Maps API和Cordova是新手,我想知道如何使用按钮删除多边形、标记、圆等

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

我的
loadMap()
代码如下:

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()
上:


任何帮助都将不胜感激

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

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

通用多边形:任意

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

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

就这样

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