【发布时间】:2022-07-08 08:22:56
【问题描述】:
在 Mapbox v10 iOS SDK 中,许多 API 发生了变化,包括拖动和相机选项。基本上,当使用 v6 时,只需使用 mapView.setCenter 并传入 screenCoordinates(请检查代码 sn-p),将注释视图(子类 MGLAnnotationView)拖动到地图边界之外时,一切都可以正常工作。
从 v10 开始,不再有 MGLAnnotationView,我使用 ViewAnnotations(https://docs.mapbox.com/ios/maps/guides/annotations/view-annotations/) 来显示我的自定义注释。此外,我们需要创建一个相机选项实例并传入屏幕坐标并使用它来设置相机。
问题在于使用 v10,每当我将注释视图拖到地图/屏幕边界之外时,它都会快速移动。有人在使用 v10 时遇到过这种情况吗?您做了什么修复?
感谢任何帮助。
使用 Mapbox iOS SDK v6
func handleDragging(_ annotationView: AnnotationView) { // AnnotationView is a subclass of MGLAnnotationView
guard let gesture = annotationView.gestureRecognizers?.first as? UIPanGestureRecognizer else { return }
let gesturePoint = gesture.location(in: view)
let screenCoordinate = mapView.convert(gesturePoint, toCoordinateFrom: nil)
let mapBounds = CGRect(x: UIScreen.main.bounds.origin.x + 30, y: UIScreen.main.bounds.origin.y + 30, width: UIScreen.main.bounds.size.width - 60, height: UIScreen.main.bounds.size.height - 60)
if !mapBounds.contains(gesturePoint) {
mapView.setCenter(screenCoordinate, zoomLevel: 15, animated: true)
}
}
使用 Mapbox iOS SDK v10.4.3
func handleDragging(_ annotationView: AnnotationView) { // AnnotationView is a subclass of UIView only
guard let gesture = annotationView.gestureRecognizers?.first as? UIPanGestureRecognizer else { return }
let gesturePoint = gesture.location(in: view)
let screenCoordinate = self.mapView.mapboxMap.coordinate(for: gesturePoint)
let mapBounds = CGRect(x: UIScreen.main.bounds.origin.x + 30, y: UIScreen.main.bounds.origin.y + 30, width: UIScreen.main.bounds.size.width - 60, height: UIScreen.main.bounds.size.height - 60)
if !mapBounds.contains(gesturePoint) {
let cameraOptions = CameraOptions(center: screenCoordinate, zoom: self.mapView.cameraState.zoom, bearing: self.mapView.cameraState.bearing, pitch: self.mapView.cameraState.pitch)
self.mapView.mapboxMap.setCamera(to: cameraOptions)
}
}
【问题讨论】:
标签: mapbox mapbox-ios