我想将折线放置在地图中,并希望根据折线的大小和折线的位置动态设置缩放级别我的代码在这里:
<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>
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);
});
此处标记是所有可用纬度和经度的数组。这将设置缩放级别以适合地图中的所有折线点。