2017-03-16 39 views
4

如何從Google地圖中使用繪圖管理器移除繪製的圓形或多邊形。如何使用繪圖管理器從谷歌地圖中刪除繪製的圓形或多邊形 - ng2-map

組件:

import {Ng2MapComponent, DrawingManager, Polygon} from 'ng2-map'; 

export class CreateAlertComponent implements OnInit { 
    @ViewChild(Ng2MapComponent) mapObj: Ng2MapComponent; 
    @ViewChild(DrawingManager) drawingManager: DrawingManager; 

    polygonCompleteFunction(e) { 
     console.log(this.mapObj); 
    }; 

}); 

HTML:

<ng2-map [zoom]="mapOptions.zoom" [minZoom]="mapOptions.minZoom" [center]="mapOptions.center" clickable="false" (click)="mapClick($event)"> 
        <drawing-manager *ngIf = "selectedJurisdictions.length > 0" 
         [drawingMode]="'null'" 
         [drawingControl]="true" 
         [drawingControlOptions]="{ 
         position: 2, 
         drawingModes: ['circle', 'polygon'] 
         }" 
         [circleOptions]="{ 
         fillColor: 'red', 
         fillOpacity: 0.3, 
         strokeColor: 'black', 
         strokeWeight: 2, 
         editable: true, 
         draggable: true, 
         zIndex: 1 
         }" 
         [polygonOptions]="{ 
         fillColor: 'red', 
         fillOpacity: 0.3, 
         strokeColor: 'black', 
         strokeWeight: 2, 
         editable: true, 
         draggable: true, 
         zIndex: 1 
         }" 
         (polygoncomplete)="polygonCompleteFunction($event)" 
         (circlecomplete)="circleCompleteFunction($event)"> 
        </drawing-manager> 
</ng2-map> 

但在多邊形功能齊全或圓形完整,我無法從地圖對象

+0

請參閱此鏈接,它肯定會幫助你。 [點擊](http://stackoverflow.com/a/12006751/5725745) – 2017-03-27 06:15:33

+0

請參閱此鏈接,它一定會幫助你。 [點擊這裏](http://stackoverflow.com/a/12006751/5725745) – 2017-03-27 06:16:48

回答

1

你得到繪製的多邊形可以從CircleComplete/中找到繪製的多邊形或圓形事件的參數。或者通過event.overlay從OverlayComplete事件的參數中找到目標。 獲取目標對象後,您可以將它保留在某處以將其刪除。

polygonCompleteFunction(e) { 
    console.log(e); // this is the drawn Polygon you are looking for, and same for the circleComplete event 
}; 

overlayComplete(e) { 
    console.log(e.overlay); // here can also find the drawn shape(Polygon/Circle/Polyline/Rectangle) 
} 

雖然刪除目標多邊形或圓形,參照實例之前一直將其刪除。

target.setMap(null); 

這裏是關於OverlayComplete活動GooleMapApi文檔:

google.maps.event.addListener(DrawingManager會, 'circlecomplete',函數(圓形) { 變種半徑= circle.getRadius( ); });

google.maps.event.addListener(DrawingManager會, 'overlaycomplete',功能(事件) { 如果(event.type == '圓'){ VAR半徑= event.overlay.getRadius(); } });

以下是GoogleMapApi文檔中的link

希望它有幫助。這裏是你可以參考的plunker

+0

它的工作.... :) –

相關問題