April 26, 2018 Patch
I'm not sure, but it seems that Angular Google Maps already supports polygon drawing. You can check more .
Check the working piston:
Basic version (only for drawing a polygon) https://stackblitz.com/edit/angular-draw-polygon-google-maps
Updated version (draw polygons and check intersections) ( plunker does not work now ) https://embed.plnkr.co/3sNWwX/
AGM is the best library for Angular 2 at the moment, but it still needs to be updated to reflect all the Google Maps APIs. Therefore, it is best to follow the Google Maps document and use it immediately before the Angular community supports it.
https://developers.google.com/maps/documentation/javascript/examples/drawing-tools
Please note that this is a very simple way to draw a polygon and get the coordinate after finishing. You can also move all the code associated with the card to the service.
ngOnInit() { this.map = new google.maps.Map(document.getElementById('map'), { center: { lat: -34.397, lng: 150.644 }, zoom: 8 }); this.drawingManager = new google.maps.drawing.DrawingManager({ drawingMode: google.maps.drawing.OverlayType.POLYGON, drawingControl: true, drawingControlOptions: { position: google.maps.ControlPosition.TOP_CENTER, drawingModes: ['polygon'] } }); this.drawingManager.setMap(this.map); google.maps.event.addListener(this.drawingManager, 'overlaycomplete', (event) => { // Polygon drawn if (event.type === google.maps.drawing.OverlayType.POLYGON) { //this is the coordinate, you can assign it to a variable or pass into another function. alert(event.overlay.getPath().getArray()); } }); }
trungk18
source share