1 #pragma once 2 3 #include <mbgl/util/optional.hpp> 4 #include <mbgl/util/chrono.hpp> 5 #include <mbgl/map/map_observer.hpp> 6 #include <mbgl/map/mode.hpp> 7 #include <mbgl/util/noncopyable.hpp> 8 #include <mbgl/util/size.hpp> 9 #include <mbgl/annotation/annotation.hpp> 10 #include <mbgl/map/camera.hpp> 11 #include <mbgl/util/geometry.hpp> 12 13 #include <cstdint> 14 #include <string> 15 #include <functional> 16 #include <vector> 17 #include <memory> 18 19 namespace mbgl { 20 21 class FileSource; 22 class Scheduler; 23 class RendererFrontend; 24 25 namespace style { 26 class Image; 27 class Style; 28 } // namespace style 29 30 class Map : private util::noncopyable { 31 public: 32 explicit Map(RendererFrontend&, 33 MapObserver&, 34 Size size, 35 float pixelRatio, 36 FileSource&, 37 Scheduler&, 38 MapMode mapMode = MapMode::Continuous, 39 ConstrainMode constrainMode = ConstrainMode::HeightOnly, 40 ViewportMode viewportMode = ViewportMode::Default); 41 ~Map(); 42 43 // Register a callback that will get called (on the render thread) when all resources have 44 // been loaded and a complete render occurs. 45 using StillImageCallback = std::function<void (std::exception_ptr)>; 46 void renderStill(StillImageCallback); 47 void renderStill(const CameraOptions&, MapDebugOptions, StillImageCallback); 48 49 // Triggers a repaint. 50 void triggerRepaint(); 51 52 style::Style& getStyle(); 53 const style::Style& getStyle() const; 54 55 void setStyle(std::unique_ptr<style::Style>); 56 57 // Transition 58 void cancelTransitions(); 59 void setGestureInProgress(bool); 60 bool isGestureInProgress() const; 61 bool isRotating() const; 62 bool isScaling() const; 63 bool isPanning() const; 64 65 // Camera 66 CameraOptions getCameraOptions(const EdgeInsets&) const; 67 void jumpTo(const CameraOptions&); 68 void easeTo(const CameraOptions&, const AnimationOptions&); 69 void flyTo(const CameraOptions&, const AnimationOptions&); 70 CameraOptions cameraForLatLngBounds(const LatLngBounds&, const EdgeInsets&, optional<double> bearing = {}, optional<double> pitch = {}) const; 71 CameraOptions cameraForLatLngs(const std::vector<LatLng>&, const EdgeInsets&, optional<double> bearing = {}, optional<double> pitch = {}) const; 72 CameraOptions cameraForGeometry(const Geometry<double>&, const EdgeInsets&, optional<double> bearing = {}, optional<double> pitch = {}) const; 73 LatLngBounds latLngBoundsForCamera(const CameraOptions&) const; 74 75 // Position 76 void moveBy(const ScreenCoordinate&, const AnimationOptions& = {}); 77 void setLatLng(const LatLng&, optional<ScreenCoordinate>, const AnimationOptions& = {}); 78 void setLatLng(const LatLng&, const EdgeInsets&, const AnimationOptions& = {}); 79 void setLatLng(const LatLng&, const AnimationOptions& = {}); 80 LatLng getLatLng(const EdgeInsets& = {}) const; 81 void resetPosition(const EdgeInsets& = {}); 82 83 // Zoom 84 void setZoom(double zoom, const AnimationOptions& = {}); 85 void setZoom(double zoom, optional<ScreenCoordinate>, const AnimationOptions& = {}); 86 void setZoom(double zoom, const EdgeInsets&, const AnimationOptions& = {}); 87 double getZoom() const; 88 void setLatLngZoom(const LatLng&, double zoom, const AnimationOptions& = {}); 89 void setLatLngZoom(const LatLng&, double zoom, const EdgeInsets&, const AnimationOptions& = {}); 90 void resetZoom(); 91 92 // Bounds 93 void setLatLngBounds(optional<LatLngBounds>); 94 optional<LatLngBounds> getLatLngBounds() const; 95 void setMinZoom(double); 96 double getMinZoom() const; 97 void setMaxZoom(double); 98 double getMaxZoom() const; 99 void setMinPitch(double); 100 double getMinPitch() const; 101 void setMaxPitch(double); 102 double getMaxPitch() const; 103 104 // Rotation 105 void rotateBy(const ScreenCoordinate& first, const ScreenCoordinate& second, const AnimationOptions& = {}); 106 void setBearing(double degrees, const AnimationOptions& = {}); 107 void setBearing(double degrees, optional<ScreenCoordinate>, const AnimationOptions& = {}); 108 void setBearing(double degrees, const EdgeInsets&, const AnimationOptions& = {}); 109 double getBearing() const; 110 void resetNorth(const AnimationOptions& = {{mbgl::Milliseconds(500)}}); 111 void resetNorth(const EdgeInsets&, const AnimationOptions& = {{mbgl::Milliseconds(500)}}); 112 113 // Pitch 114 void setPitch(double pitch, const AnimationOptions& = {}); 115 void setPitch(double pitch, optional<ScreenCoordinate>, const AnimationOptions& = {}); 116 double getPitch() const; 117 118 // North Orientation 119 void setNorthOrientation(NorthOrientation); 120 NorthOrientation getNorthOrientation() const; 121 122 // Constrain mode 123 void setConstrainMode(ConstrainMode); 124 ConstrainMode getConstrainMode() const; 125 126 // Viewport mode 127 void setViewportMode(ViewportMode); 128 ViewportMode getViewportMode() const; 129 130 // Projection mode 131 void setAxonometric(bool); 132 bool getAxonometric() const; 133 void setXSkew(double ySkew); 134 double getXSkew() const; 135 void setYSkew(double ySkew); 136 double getYSkew() const; 137 138 // Size 139 void setSize(Size); 140 Size getSize() const; 141 142 // Projection 143 ScreenCoordinate pixelForLatLng(const LatLng&) const; 144 LatLng latLngForPixel(const ScreenCoordinate&) const; 145 146 // Annotations 147 void addAnnotationImage(std::unique_ptr<style::Image>); 148 void removeAnnotationImage(const std::string&); 149 double getTopOffsetPixelsForAnnotationImage(const std::string&); 150 151 AnnotationID addAnnotation(const Annotation&); 152 void updateAnnotation(AnnotationID, const Annotation&); 153 void removeAnnotation(AnnotationID); 154 155 // Tile prefetching 156 // 157 // When loading a map, if `PrefetchZoomDelta` is set to any number greater than 0, the map will 158 // first request a tile for `zoom = getZoom() - delta` in a attempt to display a full map at 159 // lower resolution as quick as possible. It will get clamped at the tile source minimum zoom. 160 // The default `delta` is 4. 161 void setPrefetchZoomDelta(uint8_t delta); 162 uint8_t getPrefetchZoomDelta() const; 163 164 // Debug 165 void setDebug(MapDebugOptions); 166 void cycleDebugOptions(); 167 MapDebugOptions getDebug() const; 168 169 bool isFullyLoaded() const; 170 void dumpDebugLogs() const; 171 172 private: 173 class Impl; 174 const std::unique_ptr<Impl> impl; 175 }; 176 177 } // namespace mbgl 178