2016-07-01 52 views
0

我正在構建我想在MGLMapView中顯示的MGLCoordinateBounds。一切都很好,直到我嘗試使用邊緣插槽來提供一些填充。在所有邊上調用setVisibleCoordinateBounds(_:, edgePadding:, animated:)以及100px的邊緣插圖都很好。如果我儘可能將邊緣插圖設置爲200px,則地圖視圖將移至(0,0)。我曾預計地圖縮放因子會改變,以使一切都合適。 FWIW,在我使用的iPhone 6上,地圖視圖爲653x750像素,插圖不超過地圖視圖大小。設置地圖座標邊界默認爲顯示(0,0)

我可以使用100px填充,但是我擔心的是我不知道何時或爲什麼會出現這個問題。 MGLCoordinateBounds的某些值與100px填充有相同的問題嗎?有什麼方法可以預測和避免這個問題嗎?

回答

0

Deep downMGLCoordinateBounds轉換成CLLocationCoordinate2D。一直是單位度。

只是爲了驗證,您正在將100px200px轉換爲度數,是否正確?

對不起,這個明顯的問題。將Mapview重置爲(0,0)令人費解。

您可能需要計算填充基於縮放級別度


一種用於填充,其中一些數學涉及的topBottomleftRight

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) 
+0

我不轉化的建議100px和200px的度量,因爲我使用的方法 - 'setVisibleCoordinateBounds(_ :, edgePadding :, animated:)' - 特別使用'UIEdgeInsets'進行填充。如果我轉換爲度數,我可以使用'setVisibleCoordinateBounds(_ :, animated:)',但它看起來並不像我使用的方法那樣需要。 –

+0

然後可能不會實現EdgeInsets。測試代碼僅測試零邊緣。您可以通過https://github.com/mapbox/mapbox-gl-native/ – RobLabs

+0

提交功能請求或問題,只是碰到了這個答案。它與你在找什麼有關? http://stackoverflow.com/questions/38946722/how-to-zoom-mapbox-using-swift-to-a-given-radius-in-kilometers/38946880#38946880 – RobLabs