Skip to content

Unify camera API into a single method #2801

Closed

Description

@lucaswoj

As part of the v1 effort, we should consider refactoring the camera API

  • the names of methods like panBy, panTo, flyTo, jumpTo, easeTo don't make their behaviour obvious (I need to reference the docs regularly)
  • there is an opportunity to express the camera API in terms of fewer methods (maybe even a single method 😄)

Activity

  1. added this to the milestone on Jun 29, 2016
  2. 1ec5 commented on Jun 29, 2016

    @1ec5
    Contributor

    👍 on unifying panTo, flyTo, jumpTo, and easeTo for sure: it’d be nice if AnimationOptions were the one-stop shop for specifying how you get to the destination camera, and the default were to have no animation at all.

    On the other hand, panBy is quite handy. It isn’t always obvious how to pan by a relative pixel distance, especially when bearing and pitch are involved. Could it be generalized to accept a options object that could vary the zoom level or bearing instead?

  3. lucaswoj commented on Jul 8, 2016

    @lucaswoj
    ContributorAuthor

    Combining this ticket with #2820, "Support overlapping and/or queued Camera animations." See also mapbox/mapbox-gl-native#3625

  4. 1ec5 commented on Jul 8, 2016

    @1ec5
    Contributor

    The equivalent gl-native ticket is mapbox/mapbox-gl-native#3625.

  5. removed this from the milestone on Jul 28, 2016
  6. added
    breaking change ⚠️
    and removed on Aug 25, 2016
  7. changed the title [-]Consider redesigning the camera API[/-] [+]Redesign the camera API[/+] on Nov 1, 2016
  8. changed the title [-]Redesign the camera API[/-] [+]Unify camera API into a single method[/+] on Nov 1, 2016
  9. mapsam commented on Nov 1, 2016

    @mapsam
    Contributor

    Brainstorming:

    moveTo

    Everything within the current available animation methods involve moving the map based on a set of options (i.e. bearing, speed, zoom, etc.). What if we were to integrate all of them into a single method, called moveTo that includes an additional option animationType, which specifies how to animate the motion.

    Example usage:

    map.moveTo({
      animationType: 'ease', // 'fly', 'none', 'something-new'
      center: [0, 0],
      // more options
    });

    This would allow us to set the moveTo animation default (possibly no animation whatsoever, replacing jumpTo). Internally we can update all motion to moveTo and extend their options to include animationType, which would reduce the number of methods used internally.

  10. 22 remaining items

  11. mourner commented on Nov 3, 2016

    @mourner
    Member

    @jfirebaugh it's not obvious, but I'd prefer making the docs clearer rather than removing it altogether. Makes transition from Leaflet/etc. easier.

  12. 1ec5 commented on Nov 3, 2016

    @1ec5
    Contributor

    With the addition of cameraForBounds (or boundsToCamera), is a setBounds or fitBounds really needed? #2801 (comment) Could we complement it with a more flexible boundsForCamera (or cameraToBounds)?

  13. mourner commented on Nov 3, 2016

    @mourner
    Member

    @1ec5 I would keep map.fitBounds(bounds, options) as a shortcut for map.setCamera(map.cameraForBounds(bounds, 0), options) (small things like this matter for beginners), but not a strong opinion.

  14. mapsam commented on Nov 3, 2016

    @mapsam
    Contributor

    @mourner running into some .bind errors with the navigation controls.

    Example: currently when creating the "zoom in" button we pass map.zoomIn.bind(map) as the function to execute. This worked previously since zoomIn was a wrapper around the easeTo function, so we had space to set defaults for the zooming functionality. Now we can pass in our cameraOptions and animationOptions with the .bind function like this:

    map.setCamera.bind(map, {zoom: map.getZoom() + 1}, {type: 'ease'})

    The problem: the values in .bind (i.e. map.getZoom()) are only calculated once, so the function doesn't recalculate every time you click the button. This means you can only zoom in/out once.

    Any suggestions?

  15. mapsam commented on Nov 3, 2016

    @mapsam
    Contributor

    I'm able to get around the above ^ by building in a private functions for NavigationControl that are called like:

    this._zoomIn.bind(map)

    And are just implementations of setCamera

    _zoomIn() { map.setCamera({zoom: map.getZoom() + 1}, {type: 'ease'}); }
  16. mapsam commented on Nov 4, 2016

    @mapsam
    Contributor

    Can we get rid of the duration: 0 workaround now that we are specifying animation types? With no animation specified, setCamera defaults to no animation. We could also build in a check like:

    if (duration === 0) animationOptions.type = 'none';

    This would allow us to remove the duration !== 0 and animationOptions.animate checks within the ease and fly animation code.

  17. 1ec5 commented on Nov 4, 2016

    @1ec5
    Contributor

    Can we get rid of the duration: 0 workaround now that we are specifying animation types?

    Yes, I think so. Also, per #1473, we should make sure unanimated camera changes are synchronous, in addition to taking no time to complete.

  18. mapsam commented on Nov 7, 2016

    @mapsam
    Contributor

    get rid of the duration: 0

    Realizing there are quite a few tests that rely on duration: 0 to get themselves within the ease/fly transforms, which handle more camera options than the "no animation" transform. Example:

    map.setCamera({offset: [100, 0]});

    This will run through the non-animation code, which doesn't even check for the offset parameter.

  19. mapsam commented on Nov 8, 2016

    @mapsam
    Contributor

    get rid of the duration: 0

    More-so, there is a good amount of duration: 0 in scroll animations, where smooth ease is desired over a ton of non-animated transitions. Removing duration zero means a lot of these interactions aren't as smooth as before. See how duration is set to 0 in the scroll zoom if a wheel isn't used.

    Two options:

    1. Keep all instances of duration: 0 within the ease function
    2. Set duration: 1 for quick ease animations, which leads to a similarly smooth experience
  20. jwangler commented on Apr 26, 2017

    @jwangler

    +1

    Definitely would like to see merging the concepts of bounds and camera options together into something like a BoundCameraOptions where bounding box takes the place of center and zoom, and center and zoom are then derived when flyTo/jumpTo/easeTo are called with those BoundCameraOptions..

  21. tuukka commented on Feb 20, 2018

    @tuukka

    What's the status of this work? I would need getCamera and cameraForBounds for a map I'm working on, and they could be implemented without breaking backward-compatibility, but is that ok?

  22. asheemmamoowala commented on Jul 7, 2021

    @asheemmamoowala
    Contributor

    With v2 we added a free camera with options to get and set the camera directly, and Map#cameraForBounds.

    The existing jumpTo and easeTo will be kept for API compatibility.

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

    api 📝breaking change ⚠️medium priority

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions