I'm using on my angular project this version of Angular Google Maps "@agm/core": "1.0.0-beta.2" . My concern is about how to re-draw the polygon I have drawn on my google Map, I'm storing the latitude and longitude, How can I redraw my polygon ?
<agm-map [latitude]="latitudeMapUpdate"
[longitude]="longitudeMapUpdate"
[disableDefaultUI]="false"
[zoom]="13"
(mapReady)="onMapReady($event)">
</agm-map>
onMapReady(map) {
this.initDrawingManager(map);
}
initDrawingManager(map: any) {
const self = this;
const options = {
drawingControl: true,
drawingControlOptions: {
drawingModes: ["polygon"]
},
polygonOptions: {
draggable: true,
editable: true
},
drawingMode: google.maps.drawing.OverlayType.POLYGON
};
const drawingManager = new google.maps.drawing.DrawingManager(options);
drawingManager.setMap(map);
google.maps.event.addListener(
drawingManager,
'overlaycomplete',
(event) => {
alert(event.overlay.getPath().getArray());
const paths = event.overlay.getPaths();
drawingManager.setDrawingMode(null);
self.updatePointList(event.overlay.getPath());
const newShape = event.overlay;
newShape.type = event.type;
google.maps.event.addListener(newShape, 'click', () => {
this.setSelectionPolygons(newShape)
});
this.setSelectionPolygons(newShape)
});
google.maps.event.addListener(drawingManager, 'drawingmode_changed', this.clearSelection);
google.maps.event.addListener(map, 'click', this.clearSelection);
google.maps.event.addDomListener(document.getElementById('delete-map-button'), 'click', this.deleteSelectedShape);
console.log({map});
}
Instead of relying on 3rd party libraries/modules to implement the map for you, you can load the script directly so that you can use the google map's official documentations like this simple polygon sample. To do this, simply load the JS map script in the index.html.
Here is a working sample for your reference: https://stackblitz.com/edit/angular-simple-map-64456023
index.html
style.css
simple-map.component.html
simple-map.component.ts