| 1 | #pragma once |
| 2 | |
| 3 | #include <mbgl/util/geo.hpp> |
| 4 | #include <mbgl/util/chrono.hpp> |
| 5 | #include <mbgl/util/unitbezier.hpp> |
| 6 | #include <mbgl/util/optional.hpp> |
| 7 | |
| 8 | #include <functional> |
| 9 | |
| 10 | namespace mbgl { |
| 11 | |
| 12 | /** Various options for describing the viewpoint of a map. All fields are |
| 13 | optional. */ |
| 14 | struct CameraOptions { |
| 15 | /** Coordinate at the center of the map. */ |
| 16 | optional<LatLng> center; |
| 17 | |
| 18 | /** Padding around the interior of the view that affects the frame of |
| 19 | reference for `center`. */ |
| 20 | EdgeInsets padding; |
| 21 | |
| 22 | /** Point of reference for `zoom` and `angle`, assuming an origin at the |
| 23 | top-left corner of the view. */ |
| 24 | optional<ScreenCoordinate> anchor; |
| 25 | |
| 26 | /** Zero-based zoom level. Constrained to the minimum and maximum zoom |
| 27 | levels. */ |
| 28 | optional<double> zoom; |
| 29 | |
| 30 | /** Bearing, measured in radians counterclockwise from true north. Wrapped |
| 31 | to [−π rad, π rad). */ |
| 32 | optional<double> angle; |
| 33 | |
| 34 | /** Pitch toward the horizon measured in radians, with 0 rad resulting in a |
| 35 | two-dimensional map. */ |
| 36 | optional<double> pitch; |
| 37 | }; |
| 38 | |
| 39 | constexpr bool operator==(const CameraOptions& a, const CameraOptions& b) { |
| 40 | return a.center == b.center |
| 41 | && a.padding == b.padding |
| 42 | && a.anchor == b.anchor |
| 43 | && a.zoom == b.zoom |
| 44 | && a.angle == b.angle |
| 45 | && a.pitch == b.pitch; |
| 46 | } |
| 47 | |
| 48 | constexpr bool operator!=(const CameraOptions& a, const CameraOptions& b) { |
| 49 | return !(a == b); |
| 50 | } |
| 51 | |
| 52 | /** Various options for describing a transition between viewpoints with |
| 53 | animation. All fields are optional; the default values depend on how this |
| 54 | struct is used. */ |
| 55 | struct AnimationOptions { |
| 56 | /** Time to animate to the viewpoint defined herein. */ |
| 57 | optional<Duration> duration; |
| 58 | |
| 59 | /** Average velocity of a flyTo() transition, measured in screenfuls per |
| 60 | second, assuming a linear timing curve. |
| 61 | |
| 62 | A <i>screenful</i> is the visible span in pixels. It does not correspond |
| 63 | to a fixed physical distance but rather varies by zoom level. */ |
| 64 | optional<double> velocity; |
| 65 | |
| 66 | /** Zero-based zoom level at the peak of the flyTo() transition’s flight |
| 67 | path. */ |
| 68 | optional<double> minZoom; |
| 69 | |
| 70 | /** The easing timing curve of the transition. */ |
| 71 | optional<mbgl::util::UnitBezier> easing; |
| 72 | |
| 73 | /** A function that is called on each frame of the transition, just before a |
| 74 | screen update, except on the last frame. The first parameter indicates |
| 75 | the elapsed time as a percentage of the duration. */ |
| 76 | std::function<void(double)> transitionFrameFn; |
| 77 | |
| 78 | /** A function that is called once on the last frame of the transition, just |
| 79 | before the corresponding screen update. */ |
| 80 | std::function<void()> transitionFinishFn; |
| 81 | |
| 82 | /** Creates an animation with no options specified. */ |
| 83 | AnimationOptions() {} |
| 84 | |
| 85 | /** Creates an animation with the specified duration. */ |
| 86 | AnimationOptions(Duration d) |
| 87 | : duration(d) {} |
| 88 | }; |
| 89 | |
| 90 | } // namespace mbgl |
| 91 | |