2

I am using AGM to get the LatLng of the selected area in the form of a polygon. Now I draw the polygon I successfully get the LatLng points according to the polygon. But when I drag the pointer to polygon from any point of polygon its LatLng points do not change. I want to change them on drag.

Component.html:-

<agm-map [latitude]="options.lat" [longitude]="options.lng" (mapClick)="onMapClick($event)">
   <agm-polygon [paths]="paths" [editable]=options.editable  [visible]="options.visible" [draggable]=options.draggable [fillColor]=options.fillColor>
   </agm-polygon>
</agm-map>

Component.ts:-

paths : Array<LatLngLiteral> = [];

options : any = {
  lat          : 33.5362475,
  lng          : -111.9267386,
  zoom         : 10,
  fillColor    : '#DC143C',
  draggable    : true,
  editable     : true,
  visible      : true
};

public onMapClick(evt) {
   let clickCrd = { lat: evt.coords.lat, lng: evt.coords.lng };
   this.paths.push(clickCrd);
   let newArray = Array<LatLngLiteral>();
   this.paths.forEach((item) => {
     newArray.push(item);
  });
  this.paths = newArray;
}

here is stackblitz

Please tell me how it is possible?

Saurabh Agrawal
  • 7,581
  • 2
  • 27
  • 51
Harleen Kaur Arora
  • 1,949
  • 2
  • 23
  • 55

0 Answers0