如何在MGL mapView中缩放,以便视图包含地图上的一个“对象”

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

我在地图集地图上有一个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)
    }
ios swift zoom mapbox
1个回答
2
投票

MGLMapView实际上有一个专门用于此目的的烘焙方法。您应该能够使用-showAnnotations:animated实现该功能。如果你想摆弄折线周围的填充物,你也可以使用该方法的showAnnotations:edgePadding:animated风味。

这将如下所示:

 func mapView(_ mapView: MGLMapView, didSelect annotation: MGLAnnotation) {        
    mapView.showAnnotations(pointAnnotations, animated: true)
}
© www.soinside.com 2019 - 2024. All rights reserved.