summaryrefslogtreecommitdiff
path: root/include/mbgl
diff options
context:
space:
mode:
authorJustin R. Miller <incanus@codesorcery.net>2015-03-17 17:30:24 -0700
committerJustin R. Miller <incanus@codesorcery.net>2015-03-17 17:30:24 -0700
commite049ce6df13c3ad77e9e2ecb2e1afe2992384a35 (patch)
tree17c21487d53639e3cdf3d6fa9cf78a249a8a67a1 /include/mbgl
parent1ce51a17e7de5d6a02346efce1539ff7f36e0a6d (diff)
downloadqtlocation-mapboxgl-e049ce6df13c3ad77e9e2ecb2e1afe2992384a35.tar.gz
refs #893 #992: point annotations API
Diffstat (limited to 'include/mbgl')
-rw-r--r--include/mbgl/map/annotation.hpp72
-rw-r--r--include/mbgl/map/map.hpp15
-rw-r--r--include/mbgl/util/constants.hpp3
-rw-r--r--include/mbgl/util/geo.hpp15
4 files changed, 104 insertions, 1 deletions
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 <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>
+#include <mbgl/util/vec.hpp>
+
+#include <string>
+#include <vector>
+#include <map>
+#include <mutex>
+#include <memory>
+
+namespace mbgl {
+
+class Annotation;
+class Map;
+
+typedef std::vector<LatLng> 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<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;
+
+ const std::unique_ptr<LiveTile>& getTile(Tile::ID const& id);
+
+private:
+ uint32_t nextID() { return nextID_++; }
+ static vec2<double> projectPoint(LatLng& point);
+
+private:
+ 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;
+ 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
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<double> pixelForLatLng(const LatLng latLng) const { return state.pixelForLatLng(latLng); }
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 removeAnnotation(uint32_t);
+ void removeAnnotations(std::vector<uint32_t>);
+ std::vector<uint32_t> getAnnotationsInBounds(LatLngBounds) const;
+ LatLngBounds getBoundsForAnnotations(std::vector<uint32_t>) 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<Tile::ID>&);
+
enum class Mode : uint8_t {
None, // we're not doing any processing
Continuous, // continually updating map
@@ -219,8 +232,8 @@ private:
util::ptr<Sprite> sprite;
const std::unique_ptr<LineAtlas> lineAtlas;
util::ptr<TexturePool> texturePool;
-
const std::unique_ptr<Painter> painter;
+ util::ptr<AnnotationManager> 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 <cmath>
+#include <string>
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