I am trying to get the updated polygon paths when the polygon is edited and dragged. I tried to do it like the code below.
In my Typescript:
@ViewChild(AgmPolygon) polygon: any;
this.polygon.getPaths().then((x: any[]) => {
x.forEach(y => {
console.log('-');
y.forEach(z => console.log(z.lat(), z.lng()));
});
});
I followed the following links also 1st link 2nd link.
In my html:
<agm-map [latitude]="lat" [fullscreenControl]="true"
(mapClick)="mapClicked($event)" [longitude]="lng" [zoom]="8" [mapTypeControl]="true">
<agm-polygon [fillColor]="item.fillColor" (polyMouseOut)="polyMouseOut($event)"
(polyMouseMove)="polyMouseMove($event)" [fillOpacity]="item.fillOpacity"
*ngFor="let item of zonesPath; let i=index" [editable]="item.ZoneID==ZoneID"
(polyMouseUp)="polyMouseUp(item,$event)" (polyMouseDown)="polyMouseDown($event)"
(polyDblClick)="polyDblClick($event)" (polyDragStart)="polyDragStart($event)"
(polyDragEnd)="polyDragEnd($event,item)" (polyDrag)="polyDrag($event)"
[polyDraggable]="false" [paths]="item.ZonePaths" (polyClick)="polyclick($event)">
</agm-polygon>
<agm-polygon [paths]="paths"></agm-polygon>
</agm-map>
i am doing *ngFor for polygon.and my json data is:
{
"ZoneID": "594dff0ee10452d8567b23c6",
"strokeColor" : "#038063",
"strokeOpacity" : 0.2,
"strokeWeight" : 2,
"fillColor" : "#038063",
"fillOpacity" : 0.35,
"draggable" : false,
"editable" : false,
"visible" : true,
"ZonePaths": [
{
"lat" : 17.535107299215,
"lng" : 78.2346725463869
},
{
"lat" : 17.541981926489,
"lng" : 78.240509033203
},
{
"lat" : 17.54460076354,
"lng" : 78.249778747559
},
{
"lat" : 17.55082034986,
"lng" : 78.284454345703
}]}
this.polygon.getPaths is not a function
– Stancil