设置地图坐标边界默认为显示(0,0)
问题描述:
我正在构建我想在MGLMapView
中显示的MGLCoordinateBounds
。一切都很好,直到我尝试使用边缘插槽来提供一些填充。在所有边上调用setVisibleCoordinateBounds(_:, edgePadding:, animated:)
以及100px的边缘插图都很好。如果我尽可能将边缘插图设置为200px,则地图视图将移至(0,0)。我曾预计地图缩放因子会改变,以使一切都合适。 FWIW,在我使用的iPhone 6上,地图视图为653x750像素,插图不超过地图视图大小。设置地图坐标边界默认为显示(0,0)
我可以使用100px填充,但是我担心的是我不知道何时或为什么会出现这个问题。 MGLCoordinateBounds
的某些值与100px填充有相同的问题吗?有什么方法可以预测和避免这个问题吗?
答
Deep down将MGLCoordinateBounds
转换成CLLocationCoordinate2D
。一直是单位度。
只是为了验证,您正在将100px
和200px
转换为度数,是否正确?
对不起,这个明显的问题。将Mapview重置为(0,0)令人费解。
您可能需要计算填充基于缩放级别度
一种用于填充,其中一些数学涉及的topBottom
和leftRight
let topBottom = // computation based on Zoom level, and horizontal screen resolution
let leftRight = // computation based on Zoom level, and vertical screen resolution
let edgeOffset = UIEdgeInsetsMake(top: topBottom,
left: leftRight,
bottom: topBottom,
right: leftRight)
我不转化的建议100px和200px的度量,因为我使用的方法 - 'setVisibleCoordinateBounds(_ :, edgePadding :, animated:)' - 特别使用'UIEdgeInsets'进行填充。如果我转换为度数,我可以使用'setVisibleCoordinateBounds(_ :, animated:)',但它看起来并不像我使用的方法那样需要。 –
然后可能不会实现EdgeInsets。测试代码仅测试零边缘。您可以通过https://github.com/mapbox/mapbox-gl-native/ – RobLabs
提交功能请求或问题,只是碰到了这个答案。它与你在找什么有关? http://*.com/questions/38946722/how-to-zoom-mapbox-using-swift-to-a-given-radius-in-kilometers/38946880#38946880 – RobLabs