如何在 MGL mapView 中缩放,以便视图包含地图上的一个 "object"
How to zoom, in MGL mapView, so that the view encompasses one "object" on the map
我在 mapbox 地图上有一个 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)
}
MGLMapView
实际上有一个专门用于此目的的内置方法。您应该能够使用 -showAnnotations:animated
. If you want to fiddle around with the padding around your polyline, you can also use the showAnnotations:edgePadding:animated
风格的方法来实现功能。
这看起来像下面这样:
func mapView(_ mapView: MGLMapView, didSelect annotation: MGLAnnotation) {
mapView.showAnnotations(pointAnnotations, animated: true)
}
我在 mapbox 地图上有一个 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)
}
MGLMapView
实际上有一个专门用于此目的的内置方法。您应该能够使用 -showAnnotations:animated
. If you want to fiddle around with the padding around your polyline, you can also use the showAnnotations:edgePadding:animated
风格的方法来实现功能。
这看起来像下面这样:
func mapView(_ mapView: MGLMapView, didSelect annotation: MGLAnnotation) {
mapView.showAnnotations(pointAnnotations, animated: true)
}