1 #pragma once 2 3 #include <mbgl/annotation/annotation.hpp> 4 #include <mbgl/annotation/symbol_annotation_impl.hpp> 5 #include <mbgl/style/image.hpp> 6 #include <mbgl/util/noncopyable.hpp> 7 8 #include <mutex> 9 #include <string> 10 #include <vector> 11 #include <unordered_set> 12 #include <unordered_map> 13 14 namespace mbgl { 15 16 class LatLngBounds; 17 class AnnotationTile; 18 class AnnotationTileData; 19 class SymbolAnnotationImpl; 20 class ShapeAnnotationImpl; 21 22 namespace style { 23 class Style; 24 } // namespace style 25 26 class AnnotationManager : private util::noncopyable { 27 public: 28 AnnotationManager(style::Style&); 29 ~AnnotationManager(); 30 31 AnnotationID addAnnotation(const Annotation&); 32 bool updateAnnotation(const AnnotationID&, const Annotation&); 33 void removeAnnotation(const AnnotationID&); 34 35 void addImage(std::unique_ptr<style::Image>); 36 void removeImage(const std::string&); 37 double getTopOffsetPixelsForImage(const std::string&); 38 39 void setStyle(style::Style&); 40 void onStyleLoaded(); 41 42 void updateData(); 43 44 void addTile(AnnotationTile&); 45 void removeTile(AnnotationTile&); 46 47 static const std::string SourceID; 48 static const std::string PointLayerID; 49 static const std::string ShapeLayerID; 50 51 private: 52 void add(const AnnotationID&, const SymbolAnnotation&); 53 void add(const AnnotationID&, const LineAnnotation&); 54 void add(const AnnotationID&, const FillAnnotation&); 55 56 void update(const AnnotationID&, const SymbolAnnotation&); 57 void update(const AnnotationID&, const LineAnnotation&); 58 void update(const AnnotationID&, const FillAnnotation&); 59 60 void remove(const AnnotationID&); 61 62 void updateStyle(); 63 64 std::unique_ptr<AnnotationTileData> getTileData(const CanonicalTileID&); 65 66 std::reference_wrapper<style::Style> style; 67 68 std::mutex mutex; 69 70 bool dirty = false; 71 72 AnnotationID nextID = 0; 73 74 using SymbolAnnotationTree = boost::geometry::index::rtree<std::shared_ptr<const SymbolAnnotationImpl>, boost::geometry::index::rstar<16, 4>>; 75 // Unlike std::unordered_map, std::map is guaranteed to sort by AnnotationID, ensuring that older annotations are below newer annotations. 76 // <https://github.com/mapbox/mapbox-gl-native/issues/5691> 77 using SymbolAnnotationMap = std::map<AnnotationID, std::shared_ptr<SymbolAnnotationImpl>>; 78 using ShapeAnnotationMap = std::map<AnnotationID, std::unique_ptr<ShapeAnnotationImpl>>; 79 using ImageMap = std::unordered_map<std::string, style::Image>; 80 81 SymbolAnnotationTree symbolTree; 82 SymbolAnnotationMap symbolAnnotations; 83 ShapeAnnotationMap shapeAnnotations; 84 ImageMap images; 85 86 std::unordered_set<AnnotationTile*> tiles; 87 88 friend class AnnotationTile; 89 }; 90 91 } // namespace mbgl 92