From e049ce6df13c3ad77e9e2ecb2e1afe2992384a35 Mon Sep 17 00:00:00 2001 From: "Justin R. Miller" Date: Tue, 17 Mar 2015 17:30:24 -0700 Subject: refs #893 #992: point annotations API --- include/mbgl/map/annotation.hpp | 72 +++++++++++++++++++++++++++++++++++++++++ include/mbgl/map/map.hpp | 15 ++++++++- include/mbgl/util/constants.hpp | 3 ++ include/mbgl/util/geo.hpp | 15 +++++++++ 4 files changed, 104 insertions(+), 1 deletion(-) create mode 100644 include/mbgl/map/annotation.hpp (limited to 'include') diff --git a/include/mbgl/map/annotation.hpp b/include/mbgl/map/annotation.hpp new file mode 100644 index 0000000000..e88d98b5c6 --- /dev/null +++ b/include/mbgl/map/annotation.hpp @@ -0,0 +1,72 @@ +#ifndef MBGL_MAP_ANNOTATIONS +#define MBGL_MAP_ANNOTATIONS + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +namespace mbgl { + +class Annotation; +class Map; + +typedef std::vector AnnotationSegment; + +enum class AnnotationType : uint8_t { + Point, + Shape +}; + +class AnnotationManager : private util::noncopyable { +public: + AnnotationManager(); + + void setDefaultPointAnnotationSymbol(std::string& symbol) { defaultPointAnnotationSymbol = symbol; } + std::pair, std::vector> addPointAnnotations(std::vector, std::vector& symbols, const Map&); + std::vector removeAnnotations(std::vector); + std::vector getAnnotationsInBounds(LatLngBounds, const Map&) const; + LatLngBounds getBoundsForAnnotations(std::vector) const; + + const std::unique_ptr& getTile(Tile::ID const& id); + +private: + uint32_t nextID() { return nextID_++; } + static vec2 projectPoint(LatLng& point); + +private: + std::mutex mtx; + std::string defaultPointAnnotationSymbol; + std::map> annotations; + std::map, std::unique_ptr>> annotationTiles; + std::unique_ptr nullTile; + uint32_t nextID_ = 0; +}; + +class Annotation : private util::noncopyable { + friend class AnnotationManager; +public: + Annotation(AnnotationType, std::vector); + +private: + LatLng getPoint() const; + LatLngBounds getBounds() const { return bounds; } + +private: + const AnnotationType type = AnnotationType::Point; + const std::vector geometry; + std::map>> tileFeatures; + LatLngBounds bounds; +}; + +} + +#endif diff --git a/include/mbgl/map/map.hpp b/include/mbgl/map/map.hpp index 44a560a468..b03217570b 100644 --- a/include/mbgl/map/map.hpp +++ b/include/mbgl/map/map.hpp @@ -37,6 +37,7 @@ class GlyphAtlas; class SpriteAtlas; class LineAtlas; class Environment; +class AnnotationManager; class Map : private util::noncopyable { friend class View; @@ -140,6 +141,15 @@ public: inline const vec2 pixelForLatLng(const LatLng latLng) const { return state.pixelForLatLng(latLng); } inline const LatLng latLngForPixel(const vec2 pixel) const { return state.latLngForPixel(pixel); } + // Annotations + void setDefaultPointAnnotationSymbol(std::string&); + uint32_t addPointAnnotation(LatLng, std::string& symbol); + std::vector addPointAnnotations(std::vector, std::vector& symbols); + void removeAnnotation(uint32_t); + void removeAnnotations(std::vector); + std::vector getAnnotationsInBounds(LatLngBounds) const; + LatLngBounds getBoundsForAnnotations(std::vector) const; + // Debug void setDebug(bool value); void toggleDebug(); @@ -147,6 +157,7 @@ public: inline const TransformState &getState() const { return state; } inline std::chrono::steady_clock::time_point getTime() const { return animationTime; } + inline AnnotationManager& getAnnotationManager() const { return *annotationManager; } private: // This may only be called by the View object. @@ -170,6 +181,8 @@ private: // the stylesheet. void prepare(); + void updateAnnotationTiles(std::vector&); + enum class Mode : uint8_t { None, // we're not doing any processing Continuous, // continually updating map @@ -219,8 +232,8 @@ private: util::ptr sprite; const std::unique_ptr lineAtlas; util::ptr texturePool; - const std::unique_ptr painter; + util::ptr annotationManager; std::string styleURL; std::string styleJSON = ""; diff --git a/include/mbgl/util/constants.hpp b/include/mbgl/util/constants.hpp index 069e6e41ae..9e0856b68a 100644 --- a/include/mbgl/util/constants.hpp +++ b/include/mbgl/util/constants.hpp @@ -2,6 +2,7 @@ #define MBGL_UTIL_CONSTANTS #include +#include namespace mbgl { @@ -15,6 +16,8 @@ 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 { diff --git a/include/mbgl/util/geo.hpp b/include/mbgl/util/geo.hpp index 1d9986bd91..b99a6e6614 100644 --- a/include/mbgl/util/geo.hpp +++ b/include/mbgl/util/geo.hpp @@ -19,6 +19,21 @@ struct ProjectedMeters { : northing(n), easting(e) {} }; +struct LatLngBounds { + LatLng sw = {90, 180}; + LatLng ne = {-90, -180}; + + inline LatLngBounds(LatLng sw_ = {90, 180}, LatLng ne_ = {-90, -180}) + : sw(sw_), ne(ne_) {} + + inline void extend(const LatLng& point) { + if (point.latitude < sw.latitude) sw.latitude = point.latitude; + if (point.latitude > ne.latitude) ne.latitude = point.latitude; + if (point.longitude < sw.longitude) sw.longitude = point.longitude; + if (point.longitude > ne.longitude) ne.longitude = point.longitude; + } +}; + } #endif -- cgit v1.2.1