我想要在地图中拟合折线,并根据折线的大小和位置动态设置缩放级别。我的代码如下:
<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>发布于 2021-03-22 13:34:39
<agm-map ... [fitBounds]="true"></agm-map>
<agm-polyline-point ... [agmFitBounds]="true"></agm-polyline-point>
不需要进一步的计算或额外的调用。年度股东大会将为您即时计算这一点。
发布于 2020-04-22 12:11:18
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);
});这里的标记是所有可用纬度和经度的数组。这将设置缩放级别以适合地图中的所有多段线点。
https://stackoverflow.com/questions/61357066
复制相似问题