Mapbox-gl-native: Public API to convert between zoom levels and altitudes

Created on 5 Jul 2016  Â·  7Comments  Â·  Source: mapbox/mapbox-gl-native

Internally, the iOS and macOS SDKs use MGLAltitudeForZoomLevel() to convert from a zoom level to an altitude given the map view’s current state. This functionality would be useful for developers who want to animate to a given zoom level and pitch or perform other zoom-level-dependent calculations.

Not sure whether MGLAltitudeForZoomLevel() is the best API to expose publicly or whether we should design a wrapper around it in MGLMapCamera.

/cc @dapetcu21

feature iOS macOS navigation

Most helpful comment

Are there any plans to implement this? 😅

All 7 comments

I noticed that function. Not sure if it's the best thing to expose publicly. It had a difficult signature. Though an API in that direction would be needed.

Just some perspective from an iOS SDK newbie: I recently made some local changes to the iOS bench app, and I got hung up on the altitude-based API while trying to do what I thought would be a simple 10 second zoom animation. The solution I ended up with is obviously non-optimal:

// Set target zoom without animation
[self.mapView setCenterCoordinate:self.mapView.centerCoordinate zoomLevel:location.endZoom animated:NO];
// Save altitude of the target zoom
CLLocationDistance targetAltitude = self.mapView.camera.altitude;
// Put the original zoom back in place
[self.mapView setCenterCoordinate:self.mapView.centerCoordinate zoomLevel:location.zoom animated:NO];
// Animate to the target altitude
MGLMapCamera *camera = [MGLMapCamera cameraLookingAtCenterCoordinate:self.mapView.centerCoordinate fromDistance:targetAltitude pitch:location.pitch heading:location.endBearing];
[self.mapView setCamera:camera withDuration:10 animationTimingFunction:nil];

I saw MGLAltitudeForZoomLevel existed but didn't take the time to look up how best to satisfy all of its dependencies.

Ah, the ol’ set-and-revert dance (also described in https://github.com/mapbox/ios-sdk-examples/pull/65#pullrequestreview-21907456). It’s worth noting that it’s sometimes possible to avoid this issue entirely by reconsidering whether a zoom level is the best way to express the target viewport. Sometimes an altitude or coordinate bounds better captures the intent. But in cases where you really do want to show tiles at a specific zoom level (perhaps in order to reach a certain camera function stop), MGLAltitudeForZoomLevel() would certainly be useful as a public API.

Are there any plans to implement this? 😅

What's the current status of this? Need a pull request?

If you have a pull request, we would be happy to review it @datwelk !

Hi, any updates on this feature?

Was this page helpful?
0 / 5 - 0 ratings