有没有办法在角度7中将agm折线拟合到地图内部

问题描述 投票:0回答:1

我想将折线放置在地图中,并希望根据折线的大小和折线的位置动态设置缩放级别我的代码在这里:

  <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>
angular typescript angular7 angular-google-maps
1个回答
1
投票
this.agmMap.mapReady.subscribe(map => {
   const bounds: LatLngBounds = new google.maps.LatLngBounds();
   for (const mm of polyline) {
      bounds.extend(new google.maps.LatLng(mm.lat, mm.lng));
   }
   map.fitBounds(bounds);
});

此处标记是所有可用纬度和经度的数组。这将设置缩放级别以适合地图中的所有折线点。

© www.soinside.com 2019 - 2024. All rights reserved.