summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2015-06-26 18:49:06 -0700
committerJohn Firebaugh <john.firebaugh@gmail.com>2015-06-29 10:54:17 -0700
commit42c06e70392941a9c07b842f019c4b060f716ff7 (patch)
tree18dfc09adcabc7239a738a416d7bac98b0ef50f9 /src
parentf675d233142bbbfbe77c0145128c3eedfb18e824 (diff)
downloadqtlocation-mapboxgl-42c06e70392941a9c07b842f019c4b060f716ff7.tar.gz
Use array of structs rather than parallel arrays for annotations
Diffstat (limited to 'src')
-rw-r--r--src/mbgl/map/annotation.cpp186
-rw-r--r--src/mbgl/map/annotation.hpp30
-rw-r--r--src/mbgl/map/map.cpp24
3 files changed, 104 insertions, 136 deletions
diff --git a/src/mbgl/map/annotation.cpp b/src/mbgl/map/annotation.cpp
index 68491bb985..5b857e9b59 100644
--- a/src/mbgl/map/annotation.cpp
+++ b/src/mbgl/map/annotation.cpp
@@ -1,5 +1,6 @@
#include <mbgl/map/annotation.hpp>
-#include <mbgl/map/map.hpp>
+#include <mbgl/annotation/point_annotation.hpp>
+#include <mbgl/annotation/shape_annotation.hpp>
#include <mbgl/map/tile_id.hpp>
#include <mbgl/map/live_tile.hpp>
#include <mbgl/util/constants.hpp>
@@ -77,94 +78,6 @@ vec2<double> AnnotationManager::projectPoint(const LatLng& point) {
return { x, y };
}
-std::pair<std::unordered_set<TileID, TileID::Hash>, AnnotationIDs>
-AnnotationManager::addAnnotations(const AnnotationType type,
- const std::vector<AnnotationSegments>& segments,
- const std::vector<StyleProperties>& styleProperties,
- const AnnotationsProperties& annotationsProperties,
- const uint8_t maxZoom) {
- std::lock_guard<std::mutex> lock(mtx);
-
- assert(type != AnnotationType::Any);
-
- // We pre-generate tiles to contain each annotation up to the map's max zoom.
- // We do this for fast rendering without projection conversions on the fly, as well as
- // to simplify bounding box queries of annotations later. Tiles get invalidated when
- // annotations are added or removed in order to refresh the map render without
- // touching the base map underneath.
-
- AnnotationIDs annotationIDs;
- annotationIDs.reserve((type == AnnotationType::Shape ?
- segments.size() : // shapes
- segments[0][0].size())); // points
-
- std::unordered_set<TileID, TileID::Hash> affectedTiles;
-
- for (size_t s = 0; s < segments.size(); ++s) {
-
- if (type == AnnotationType::Point) {
-
- for (size_t l = 0; l < segments[s].size(); ++l) {
-
- for (size_t p = 0; p < segments[s][l].size(); ++p) {
-
- auto& point = segments[s][l][p];
-
- // projection conversion into unit space
- const auto pp = projectPoint(point);
-
- const uint32_t pointAnnotationID = nextID();
-
- // at render time we style the point according to its {sprite} field
- std::unordered_map<std::string, std::string> pointFeatureProperties;
- const std::string& symbol = annotationsProperties.at("symbols")[p];
- if (symbol.length()) {
- pointFeatureProperties.emplace("sprite", symbol);
- } else {
- pointFeatureProperties.emplace("sprite", defaultPointAnnotationSymbol);
- }
-
- // add individual point tile feature
- auto featureAffectedTiles = addTileFeature(
- pointAnnotationID,
- AnnotationSegments({{ point }}),
- std::vector<std::vector<vec2<double>>>({{ pp }}),
- AnnotationType::Point,
- {{ }},
- pointFeatureProperties,
- maxZoom
- );
-
- std::copy(featureAffectedTiles.begin(), featureAffectedTiles.end(), std::inserter(affectedTiles, affectedTiles.begin()));
-
- annotationIDs.push_back(pointAnnotationID);
- }
- }
- } else {
-
- const uint32_t shapeAnnotationID = nextID();
-
- // current shape tiles are on-the-fly, so we don't get any "affected tiles"
- // and just expire all annotation tiles for shape adds
-
- addTileFeature(
- shapeAnnotationID,
- segments[s],
- {{ }},
- AnnotationType::Shape,
- styleProperties[s],
- {{ }},
- maxZoom
- );
-
- annotationIDs.push_back(shapeAnnotationID);
- }
- }
-
- // Tile:IDs that need refreshed and the annotation identifiers held onto by the client.
- return std::make_pair(affectedTiles, annotationIDs);
-}
-
std::unordered_set<TileID, TileID::Hash>
AnnotationManager::addTileFeature(const uint32_t annotationID,
const AnnotationSegments& segments,
@@ -346,26 +259,91 @@ AnnotationManager::addTileFeature(const uint32_t annotationID,
}
std::pair<std::unordered_set<TileID, TileID::Hash>, AnnotationIDs>
-AnnotationManager::addPointAnnotations(const AnnotationSegment& points,
- const AnnotationsProperties& annotationsProperties,
+AnnotationManager::addPointAnnotations(const std::vector<PointAnnotation>& points,
const uint8_t maxZoom) {
- return addAnnotations(AnnotationType::Point,
- {{ points }},
- {{ }},
- annotationsProperties,
- maxZoom);
+ std::lock_guard<std::mutex> lock(mtx);
+
+ // We pre-generate tiles to contain each annotation up to the map's max zoom.
+ // We do this for fast rendering without projection conversions on the fly, as well as
+ // to simplify bounding box queries of annotations later. Tiles get invalidated when
+ // annotations are added or removed in order to refresh the map render without
+ // touching the base map underneath.
+
+ AnnotationIDs annotationIDs;
+ annotationIDs.reserve(points.size());
+
+ std::unordered_set<TileID, TileID::Hash> affectedTiles;
+
+ for (const PointAnnotation& point : points) {
+ // projection conversion into unit space
+ const auto pp = projectPoint(point.position);
+ const uint32_t pointAnnotationID = nextID();
+
+ // at render time we style the point according to its {sprite} field
+ std::unordered_map<std::string, std::string> pointFeatureProperties;
+ if (point.icon.length()) {
+ pointFeatureProperties.emplace("sprite", point.icon);
+ } else {
+ pointFeatureProperties.emplace("sprite", defaultPointAnnotationSymbol);
+ }
+
+ // add individual point tile feature
+ auto featureAffectedTiles = addTileFeature(
+ pointAnnotationID,
+ AnnotationSegments({{ point.position }}),
+ std::vector<std::vector<vec2<double>>>({{ pp }}),
+ AnnotationType::Point,
+ {{ }},
+ pointFeatureProperties,
+ maxZoom
+ );
+
+ std::copy(featureAffectedTiles.begin(), featureAffectedTiles.end(), std::inserter(affectedTiles, affectedTiles.begin()));
+
+ annotationIDs.push_back(pointAnnotationID);
+ }
+
+ // Tile:IDs that need refreshed and the annotation identifiers held onto by the client.
+ return std::make_pair(affectedTiles, annotationIDs);
}
std::pair<std::unordered_set<TileID, TileID::Hash>, AnnotationIDs>
-AnnotationManager::addShapeAnnotations(const std::vector<AnnotationSegments>& shapes,
- const std::vector<StyleProperties>& styleProperties,
- const AnnotationsProperties& annotationsProperties,
+AnnotationManager::addShapeAnnotations(const std::vector<ShapeAnnotation>& shapes,
const uint8_t maxZoom) {
- return addAnnotations(AnnotationType::Shape,
- shapes,
- styleProperties,
- annotationsProperties,
- maxZoom);
+ std::lock_guard<std::mutex> lock(mtx);
+
+ // We pre-generate tiles to contain each annotation up to the map's max zoom.
+ // We do this for fast rendering without projection conversions on the fly, as well as
+ // to simplify bounding box queries of annotations later. Tiles get invalidated when
+ // annotations are added or removed in order to refresh the map render without
+ // touching the base map underneath.
+
+ AnnotationIDs annotationIDs;
+ annotationIDs.reserve(shapes.size());
+
+ std::unordered_set<TileID, TileID::Hash> affectedTiles;
+
+ for (const ShapeAnnotation& shape : shapes) {
+ const uint32_t shapeAnnotationID = nextID();
+
+ // current shape tiles are on-the-fly, so we don't get any "affected tiles"
+ // and just expire all annotation tiles for shape adds
+
+ addTileFeature(
+ shapeAnnotationID,
+ shape.segments,
+ {{ }},
+ AnnotationType::Shape,
+ shape.styleProperties,
+ {{ }},
+ maxZoom
+ );
+
+ annotationIDs.push_back(shapeAnnotationID);
+ }
+
+ // Tile:IDs that need refreshed and the annotation identifiers held onto by the client.
+ return std::make_pair(affectedTiles, annotationIDs);
}
std::unordered_set<TileID, TileID::Hash> AnnotationManager::removeAnnotations(const AnnotationIDs& ids,
diff --git a/src/mbgl/map/annotation.hpp b/src/mbgl/map/annotation.hpp
index 4296fea520..e75c57f1f0 100644
--- a/src/mbgl/map/annotation.hpp
+++ b/src/mbgl/map/annotation.hpp
@@ -21,12 +21,11 @@
namespace mbgl {
class Annotation;
-class Map;
+class PointAnnotation;
+class ShapeAnnotation;
class LiveTile;
class LiveTileFeature;
-using AnnotationsProperties = std::unordered_map<std::string, std::vector<std::string>>;
-
using GeoJSONVT = mapbox::util::geojsonvt::GeoJSONVT;
class Annotation : private util::noncopyable {
@@ -57,18 +56,19 @@ public:
std::unordered_set<TileID, TileID::Hash> resetStaleTiles();
void setDefaultPointAnnotationSymbol(const std::string& symbol);
- std::pair<std::unordered_set<TileID, TileID::Hash>, AnnotationIDs> addPointAnnotations(
- const AnnotationSegment&,
- const AnnotationsProperties&,
- const uint8_t maxZoom);
- std::pair<std::unordered_set<TileID, TileID::Hash>, AnnotationIDs> addShapeAnnotations(
- const std::vector<AnnotationSegments>&,
- const std::vector<StyleProperties>&,
- const AnnotationsProperties&,
- const uint8_t maxZoom);
+
+ std::pair<std::unordered_set<TileID, TileID::Hash>, AnnotationIDs>
+ addPointAnnotations(const std::vector<PointAnnotation>&,
+ const uint8_t maxZoom);
+
+ std::pair<std::unordered_set<TileID, TileID::Hash>, AnnotationIDs>
+ addShapeAnnotations(const std::vector<ShapeAnnotation>&,
+ const uint8_t maxZoom);
+
std::unordered_set<TileID, TileID::Hash> removeAnnotations(const AnnotationIDs&, const uint8_t maxZoom);
AnnotationIDs getOrderedShapeAnnotations() const { return orderedShapeAnnotations; }
const StyleProperties getAnnotationStyleProperties(uint32_t) const;
+
AnnotationIDs getAnnotationsInBounds(const LatLngBounds&, const uint8_t maxZoom, const AnnotationType& = AnnotationType::Any) const;
LatLngBounds getBoundsForAnnotations(const AnnotationIDs&) const;
@@ -80,12 +80,6 @@ public:
private:
inline uint32_t nextID();
static vec2<double> projectPoint(const LatLng& point);
- std::pair<std::unordered_set<TileID, TileID::Hash>, AnnotationIDs> addAnnotations(
- const AnnotationType,
- const std::vector<AnnotationSegments>&,
- const std::vector<StyleProperties>&,
- const AnnotationsProperties&,
- const uint8_t maxZoom);
std::unordered_set<TileID, TileID::Hash> addTileFeature(
const uint32_t annotationID,
const AnnotationSegments&,
diff --git a/src/mbgl/map/map.cpp b/src/mbgl/map/map.cpp
index 940ab82379..2097747bc5 100644
--- a/src/mbgl/map/map.cpp
+++ b/src/mbgl/map/map.cpp
@@ -4,12 +4,12 @@
#include <mbgl/map/transform.hpp>
#include <mbgl/map/transform_state.hpp>
#include <mbgl/map/map_data.hpp>
+#include <mbgl/annotation/point_annotation.hpp>
+#include <mbgl/annotation/shape_annotation.hpp>
#include <mbgl/util/projection.hpp>
#include <mbgl/util/thread.hpp>
-#include <unordered_map>
-
namespace mbgl {
Map::Map(View& view, FileSource& fileSource, MapMode mode)
@@ -292,26 +292,22 @@ double Map::getTopOffsetPixelsForAnnotationSymbol(const std::string& symbol) {
return context->invokeSync<double>(&MapContext::getTopOffsetPixelsForAnnotationSymbol, symbol);
}
-uint32_t Map::addPointAnnotation(const LatLng& point, const std::string& symbol) {
- return addPointAnnotations({ point }, { symbol }).front();
+uint32_t Map::addPointAnnotation(const PointAnnotation& annotation) {
+ return addPointAnnotations({ annotation }).front();
}
-AnnotationIDs Map::addPointAnnotations(const AnnotationSegment& points,
- const std::vector<std::string>& symbols) {
- AnnotationsProperties properties = { { "symbols", symbols } };
- auto result = data->annotationManager.addPointAnnotations(points, properties, getMaxZoom());
+AnnotationIDs Map::addPointAnnotations(const std::vector<PointAnnotation>& annotations) {
+ auto result = data->annotationManager.addPointAnnotations(annotations, getMaxZoom());
context->invoke(&MapContext::updateAnnotationTiles, result.first);
return result.second;
}
-uint32_t Map::addShapeAnnotation(const AnnotationSegments& shape,
- const StyleProperties& styleProperties) {
- return addShapeAnnotations({ shape }, { styleProperties }).front();
+uint32_t Map::addShapeAnnotation(const ShapeAnnotation& annotation) {
+ return addShapeAnnotations({ annotation }).front();
}
-AnnotationIDs Map::addShapeAnnotations(const std::vector<AnnotationSegments>& shapes,
- const std::vector<StyleProperties>& styleProperties) {
- auto result = data->annotationManager.addShapeAnnotations(shapes, styleProperties, {{}}, getMaxZoom());
+AnnotationIDs Map::addShapeAnnotations(const std::vector<ShapeAnnotation>& annotations) {
+ auto result = data->annotationManager.addShapeAnnotations(annotations, getMaxZoom());
context->invoke(&MapContext::updateAnnotationTiles, result.first);
return result.second;
}