make more things const and refs, and add mutexes
This commit is contained in:
@@ -2,7 +2,6 @@
|
||||
#define MBGL_MAP_ANNOTATIONS
|
||||
|
||||
#include <mbgl/map/tile.hpp>
|
||||
#include <mbgl/map/live_tile.hpp>
|
||||
#include <mbgl/util/geo.hpp>
|
||||
#include <mbgl/util/noncopyable.hpp>
|
||||
#include <mbgl/util/std.hpp>
|
||||
@@ -18,55 +17,38 @@ namespace mbgl {
|
||||
|
||||
class Annotation;
|
||||
class Map;
|
||||
class LiveTile;
|
||||
|
||||
typedef std::vector<LatLng> AnnotationSegment;
|
||||
|
||||
enum class AnnotationType : uint8_t {
|
||||
Point,
|
||||
Shape
|
||||
};
|
||||
using AnnotationIDs = std::vector<uint32_t>;
|
||||
|
||||
class AnnotationManager : private util::noncopyable {
|
||||
public:
|
||||
AnnotationManager();
|
||||
~AnnotationManager();
|
||||
|
||||
void setDefaultPointAnnotationSymbol(std::string& symbol) { defaultPointAnnotationSymbol = symbol; }
|
||||
std::pair<std::vector<Tile::ID>, std::vector<uint32_t>> addPointAnnotations(std::vector<LatLng>, std::vector<std::string>& symbols, const Map&);
|
||||
std::vector<Tile::ID> removeAnnotations(std::vector<uint32_t>);
|
||||
std::vector<uint32_t> getAnnotationsInBounds(LatLngBounds, const Map&) const;
|
||||
LatLngBounds getBoundsForAnnotations(std::vector<uint32_t>) const;
|
||||
void setDefaultPointAnnotationSymbol(const std::string& symbol);
|
||||
std::pair<std::vector<Tile::ID>, AnnotationIDs> addPointAnnotations(
|
||||
const std::vector<LatLng>&, const std::vector<std::string>& symbols, const Map&);
|
||||
std::vector<Tile::ID> removeAnnotations(const AnnotationIDs&);
|
||||
AnnotationIDs getAnnotationsInBounds(const LatLngBounds&, const Map&) const;
|
||||
LatLngBounds getBoundsForAnnotations(const AnnotationIDs&) const;
|
||||
|
||||
const std::unique_ptr<LiveTile>& getTile(Tile::ID const& id);
|
||||
const LiveTile* getTile(Tile::ID const& id);
|
||||
|
||||
static const std::string layerID;
|
||||
|
||||
private:
|
||||
uint32_t nextID() { return nextID_++; }
|
||||
static vec2<double> projectPoint(LatLng& point);
|
||||
inline uint32_t nextID();
|
||||
static vec2<double> projectPoint(const LatLng& point);
|
||||
|
||||
private:
|
||||
std::mutex mtx;
|
||||
mutable std::mutex mtx;
|
||||
std::string defaultPointAnnotationSymbol;
|
||||
std::map<uint32_t, std::unique_ptr<Annotation>> annotations;
|
||||
std::map<Tile::ID, std::pair<std::vector<uint32_t>, std::unique_ptr<LiveTile>>> annotationTiles;
|
||||
std::unique_ptr<LiveTile> nullTile;
|
||||
std::map<Tile::ID, std::pair<AnnotationIDs, std::unique_ptr<LiveTile>>> annotationTiles;
|
||||
uint32_t nextID_ = 0;
|
||||
};
|
||||
|
||||
class Annotation : private util::noncopyable {
|
||||
friend class AnnotationManager;
|
||||
public:
|
||||
Annotation(AnnotationType, std::vector<AnnotationSegment>);
|
||||
|
||||
private:
|
||||
LatLng getPoint() const;
|
||||
LatLngBounds getBounds() const { return bounds; }
|
||||
|
||||
private:
|
||||
const AnnotationType type = AnnotationType::Point;
|
||||
const std::vector<AnnotationSegment> geometry;
|
||||
std::map<Tile::ID, std::vector<std::weak_ptr<const LiveTileFeature>>> tileFeatures;
|
||||
LatLngBounds bounds;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -142,13 +142,14 @@ public:
|
||||
inline const LatLng latLngForPixel(const vec2<double> pixel) const { return state.latLngForPixel(pixel); }
|
||||
|
||||
// Annotations
|
||||
void setDefaultPointAnnotationSymbol(std::string&);
|
||||
uint32_t addPointAnnotation(LatLng, std::string& symbol);
|
||||
std::vector<uint32_t> addPointAnnotations(std::vector<LatLng>, std::vector<std::string>& symbols);
|
||||
void setDefaultPointAnnotationSymbol(const std::string&);
|
||||
uint32_t addPointAnnotation(const LatLng&, const std::string& symbol);
|
||||
std::vector<uint32_t> addPointAnnotations(const std::vector<LatLng>&,
|
||||
const std::vector<std::string>& symbols);
|
||||
void removeAnnotation(uint32_t);
|
||||
void removeAnnotations(std::vector<uint32_t>);
|
||||
std::vector<uint32_t> getAnnotationsInBounds(LatLngBounds) const;
|
||||
LatLngBounds getBoundsForAnnotations(std::vector<uint32_t>) const;
|
||||
void removeAnnotations(const std::vector<uint32_t>&);
|
||||
std::vector<uint32_t> getAnnotationsInBounds(const LatLngBounds&) const;
|
||||
LatLngBounds getBoundsForAnnotations(const std::vector<uint32_t>&) const;
|
||||
|
||||
// Debug
|
||||
void setDebug(bool value);
|
||||
@@ -181,7 +182,7 @@ private:
|
||||
// the stylesheet.
|
||||
void prepare();
|
||||
|
||||
void updateAnnotationTiles(std::vector<Tile::ID>&);
|
||||
void updateAnnotationTiles(const std::vector<Tile::ID>&);
|
||||
|
||||
enum class Mode : uint8_t {
|
||||
None, // we're not doing any processing
|
||||
@@ -230,7 +231,7 @@ private:
|
||||
const std::unique_ptr<LineAtlas> lineAtlas;
|
||||
util::ptr<TexturePool> texturePool;
|
||||
const std::unique_ptr<Painter> painter;
|
||||
util::ptr<AnnotationManager> annotationManager;
|
||||
const std::unique_ptr<AnnotationManager> annotationManager;
|
||||
|
||||
std::string styleURL;
|
||||
std::string styleJSON = "";
|
||||
|
||||
@@ -16,8 +16,6 @@ extern const double M2PI;
|
||||
extern const double EARTH_RADIUS_M;
|
||||
extern const double LATITUDE_MAX;
|
||||
|
||||
extern const std::string ANNOTATIONS_POINTS_LAYER_ID;
|
||||
|
||||
}
|
||||
|
||||
namespace debug {
|
||||
|
||||
Reference in New Issue
Block a user