[Fixed] Is there any way to fit agm-polyline inside map in angular 7

Issue

I want to fit the polylines inside my map and want to set the zoom level dynamically according to polylines size and location of the polylines
My code is here:

  <agm-map style="height: 500px" [latitude]='selectedLatitude' [longitude]='selectedLongitude'
    *ngIf='xPolyline.length'>
    <agm-polyline *ngFor='let polyline of xPolyline' [strokeColor]="'#0000ff'" [strokeOpacity]="0.9">
      <agm-polyline-point *ngFor="let point of polyline;let i = index;" [latitude]="point.latitude"
        [longitude]="point.longitude">
      </agm-polyline-point>
    </agm-polyline>
  </agm-map>

Solution

<agm-map ... [fitBounds]="true"></agm-map>

<agm-polyline-point ... [agmFitBounds]="true"></agm-polyline-point>

No further calculations or extra calls are necessary. AGM is going to calculate this for you on the fly.

Leave a Reply

(*) Required, Your email will not be published