我在地图框地图上有一条MGLPolyline,我想这样做的是,当用户点击该行时,它将围绕该行居中并尽可能放大,以便显示整条线。目前,我可以使居中工作正常,但缩放可以随机进行:
我只是将其设置为最大缩放,但是,这当然不是我想要的。
下面是我要添加缩放量的地方:
func mapView(_ mapView: MGLMapView, didSelect annotation: MGLAnnotation) {
print("Tapped")
mapView.setCenter(CLLocationCoordinate2D(latitude: annotation.coordinate.latitude, longitude: annotation.coordinate.longitude), zoomLevel: mapView.zoomLevel, animated: true)
mapView.deselectAnnotation(annotation, animated: false)
}
答案 0 :(得分:2)
MGLMapView
实际上具有专门用于此目的的引入方法。您应该能够使用-showAnnotations:animated
来实现该功能。如果您想弄乱折线周围的填充,还可以使用该方法的showAnnotations:edgePadding:animated
风格。
如下所示:
func mapView(_ mapView: MGLMapView, didSelect annotation: MGLAnnotation) {
mapView.showAnnotations(pointAnnotations, animated: true)
}