summaryrefslogtreecommitdiff
path: root/src/mbgl/map/transform.hpp
blob: d708d45fafe50adb9216a85e16e09a7dbb6100cd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#ifndef MBGL_MAP_TRANSFORM
#define MBGL_MAP_TRANSFORM

#include <mbgl/map/camera.hpp>
#include <mbgl/map/mode.hpp>
#include <mbgl/map/transform_state.hpp>
#include <mbgl/map/update.hpp>
#include <mbgl/util/chrono.hpp>
#include <mbgl/util/geo.hpp>
#include <mbgl/util/noncopyable.hpp>

#include <cstdint>
#include <cmath>
#include <functional>

namespace mbgl {

class View;

class Transform : private util::noncopyable {
public:
    Transform(View&, ConstrainMode);

    // Map view
    bool resize(std::array<uint16_t, 2> size);

    // Camera
    
    /** Instantaneously, synchronously applies the given camera options. */
    void jumpTo(const CameraOptions&);
    /** Asynchronously transitions all specified camera options linearly along
        an optional time curve. */
    void easeTo(const CameraOptions&, const AnimationOptions& = {});
    /** Asynchronously zooms out, pans, and zooms back into the given camera
        along a great circle, as though the viewer is riding a supersonic
        jetcopter. */
    void flyTo(const CameraOptions&, const AnimationOptions& = {});

    // Position
    
    /** Pans the map by the given amount.
        @param offset The distance to pan the map by, measured in pixels from
            top to bottom and from left to right. */
    void moveBy(const PrecisionPoint& offset, const Duration& = Duration::zero());
    void setLatLng(const LatLng&, const Duration& = Duration::zero());
    void setLatLng(const LatLng&, const PrecisionPoint&, const Duration& = Duration::zero());
    void setLatLngZoom(const LatLng&, double zoom, const Duration& = Duration::zero());
    LatLng getLatLng() const { return state.getLatLng(); }

    // Zoom

    /** Scales the map, keeping the given point fixed within the view.
        @param ds The difference in scale factors to scale the map by.
        @param anchor A point relative to the top-left corner of the view. */
    void scaleBy(double ds, const PrecisionPoint& anchor = {NAN, NAN}, const Duration& = Duration::zero());
    /** Sets the scale factor, keeping the given point fixed within the view.
        @param scale The new scale factor.
        @param anchor A point relative to the top-left corner of the view. */
    void setScale(double scale, const PrecisionPoint& anchor = {NAN, NAN}, const Duration& = Duration::zero());
    /** Sets the zoom level.
        @param zoom The new zoom level. */
    void setZoom(double zoom, const Duration& = Duration::zero());
    /** Returns the zoom level. */
    double getZoom() const;
    /** Returns the scale factor. */
    double getScale() const;

    // Angle

    void rotateBy(const PrecisionPoint& first, const PrecisionPoint& second, const Duration& = Duration::zero());
    /** Sets the angle of rotation.
        @param angle The new angle of rotation, measured in radians
            counterclockwise from true north. */
    void setAngle(double angle, const Duration& = Duration::zero());
    /** Sets the angle of rotation, keeping the given point fixed within the view.
        @param angle The new angle of rotation, measured in radians
            counterclockwise from true north.
        @param anchor A point relative to the top-left corner of the view. */
    void setAngle(double angle, const PrecisionPoint& anchor, const Duration& = Duration::zero());
    /** Returns the angle of rotation.
        @return The angle of rotation, measured in radians counterclockwise from
            true north. */
    double getAngle() const;

    // Pitch
    void setPitch(double pitch, const Duration& = Duration::zero());
    double getPitch() const;

    // North Orientation
    void setNorthOrientation(NorthOrientation);
    NorthOrientation getNorthOrientation() const;

    // Transitions
    bool inTransition() const;
    Update updateTransitions(const TimePoint& now);
    void cancelTransitions();

    // Gesture
    void setGestureInProgress(bool);
    bool isGestureInProgress() const { return state.isGestureInProgress(); }

    // Transform state
    TransformState getState() const { return state; }
    bool isRotating() const { return state.isRotating(); }
    bool isScaling() const { return state.isScaling(); }
    bool isPanning() const { return state.isPanning(); }

private:
    void moveLatLng(const LatLng&, const PrecisionPoint&);
    
    View &view;

    TransformState state;

    void startTransition(std::function<double(double)> easing,
                         std::function<Update(double)> frame,
                         std::function<void()> finish,
                         const Duration& duration);

    TimePoint transitionStart;
    Duration transitionDuration;
    std::function<Update(const TimePoint)> transitionFrameFn;
    std::function<void()> transitionFinishFn;
};

} // namespace mbgl

#endif