Skip to content
This repository was archived by the owner on Aug 8, 2023. It is now read-only.
This repository was archived by the owner on Aug 8, 2023. It is now read-only.

Public API to convert between zoom levels and altitudes #5583

Closed

Description

@1ec5

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

Activity

  1. added
    iOS
    macOS
    on Jul 5, 2016
  2. dapetcu21 commented on Jul 5, 2016

    @dapetcu21

    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.

  3. added this to the ios-v3.6.0 milestone on Mar 15, 2017
  4. modified the milestones: , ios-v3.6.0 on Jun 22, 2017
  5. ChrisLoer commented on Nov 9, 2017

    @ChrisLoer
    Contributor

    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.

  6. 1ec5 commented on Nov 10, 2017

    @1ec5
    ContributorAuthor

    Ah, the ol’ set-and-revert dance (also described in mapbox/ios-sdk-examples#65 (review)). 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.

  7. removed this from the milestone on Nov 29, 2017
  8. marcelofabri commented on May 2, 2018

    @marcelofabri

    Are there any plans to implement this? 😅

  9. datwelk commented on Jun 7, 2018

    @datwelk

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

  10. lilykaiser commented on Jun 12, 2018

    @lilykaiser

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

  11. jjjiia commented on Sep 10, 2018

    @jjjiia

    Hi, any updates on this feature?

  12. added
    navigation
    on Sep 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureiOSmacOSnavigation

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions