Chr*_*isO 2 ios mapbox mapbox-gl
我在不同屏幕尺寸的ios中使用Mapbox在显示爱尔兰固定地图时遇到了一些麻烦。MGLMapView.setVisibleCoordinates似乎是我需要的,但是却没有我期望的那样。我希望传递左下角的坐标和右上角的坐标,并定义一个要显示的矩形,而不管屏幕尺寸如何。
mapView.setVisibleCoordinates([CLLocationCoordinate2D(latitude: 50.347676, longitude: -11.444362), CLLocationCoordinate2D(latitude: 56.375322, longitude: -4.128659)], count: 2, edgePadding: UIEdgeInsets.zero, animated: false)
我也尝试过
mapView.setVisibleCoordinateBounds(MGLCoordinateBounds(sw: CLLocationCoordinate2D(latitude: 50.347676, longitude: -11.444362), ne: CLLocationCoordinate2D(latitude: 56.375322, longitude: -4.128659)), edgePadding: UIEdgeInsets.zero, animated: false)
得到的结果如下图所示。如您所见,iphone 5s的布局是完美的,但我希望上面的代码在ipad上显示相同的视图,但是会缩小太多。如何在设备之间显示相同的视图?
好的,我已经开始工作了。MGLMapView上有一个camera方法,该方法将返回一个摄像机,该摄像机在显示您指定的矩形的同时会尽可能放大。只需确保在didFinishLoading委托方法中完成此操作即可。
let northeast = CLLocationCoordinate2D(latitude: 55.499130, longitude: -5.945938)
let southwest = CLLocationCoordinate2D(latitude: 51.133369, longitude: -10.531064)
let ireland = MGLCoordinateBounds(sw: southwest, ne: northeast)
let camera = mapView.camera(mapView.camera, fitting: ireland, edgePadding: UIEdgeInsets.zero)
mapView.setCamera(camera, animated: false)
Run Code Online (Sandbox Code Playgroud)