diff options
author | John Firebaugh <john.firebaugh@gmail.com> | 2016-05-31 17:34:11 -0700 |
---|---|---|
committer | John Firebaugh <john.firebaugh@gmail.com> | 2016-06-01 17:37:01 -0700 |
commit | 0fba70d5a8465499b0dce900e5aa74f7189e4594 (patch) | |
tree | 7902b9bd29d25de0de6d116fc3245b1b269477f4 /src/mbgl | |
parent | cfd6757ecc9bd4d9b1f4c5266d19da48c529f58b (diff) | |
download | qtlocation-mapboxgl-0fba70d5a8465499b0dce900e5aa74f7189e4594.tar.gz |
[all] Rationalize annotation API
Diffstat (limited to 'src/mbgl')
-rw-r--r-- | src/mbgl/annotation/annotation_manager.cpp | 85 | ||||
-rw-r--r-- | src/mbgl/annotation/annotation_manager.hpp | 31 | ||||
-rw-r--r-- | src/mbgl/annotation/fill_annotation_impl.cpp | 36 | ||||
-rw-r--r-- | src/mbgl/annotation/fill_annotation_impl.hpp | 19 | ||||
-rw-r--r-- | src/mbgl/annotation/line_annotation_impl.cpp | 37 | ||||
-rw-r--r-- | src/mbgl/annotation/line_annotation_impl.hpp | 19 | ||||
-rw-r--r-- | src/mbgl/annotation/shape_annotation_impl.cpp | 80 | ||||
-rw-r--r-- | src/mbgl/annotation/shape_annotation_impl.hpp | 18 | ||||
-rw-r--r-- | src/mbgl/annotation/style_sourced_annotation_impl.cpp | 38 | ||||
-rw-r--r-- | src/mbgl/annotation/style_sourced_annotation_impl.hpp | 19 | ||||
-rw-r--r-- | src/mbgl/annotation/symbol_annotation_impl.cpp (renamed from src/mbgl/annotation/point_annotation_impl.cpp) | 19 | ||||
-rw-r--r-- | src/mbgl/annotation/symbol_annotation_impl.hpp (renamed from src/mbgl/annotation/point_annotation_impl.hpp) | 21 | ||||
-rw-r--r-- | src/mbgl/map/map.cpp | 30 | ||||
-rw-r--r-- | src/mbgl/util/geometry.hpp | 37 |
14 files changed, 269 insertions, 220 deletions
diff --git a/src/mbgl/annotation/annotation_manager.cpp b/src/mbgl/annotation/annotation_manager.cpp index e5f43eb3b6..4d7059f80f 100644 --- a/src/mbgl/annotation/annotation_manager.cpp +++ b/src/mbgl/annotation/annotation_manager.cpp @@ -1,5 +1,9 @@ #include <mbgl/annotation/annotation_manager.hpp> #include <mbgl/annotation/annotation_tile.hpp> +#include <mbgl/annotation/symbol_annotation_impl.hpp> +#include <mbgl/annotation/line_annotation_impl.hpp> +#include <mbgl/annotation/fill_annotation_impl.hpp> +#include <mbgl/annotation/style_sourced_annotation_impl.hpp> #include <mbgl/source/source.hpp> #include <mbgl/style/style.hpp> #include <mbgl/layer/symbol_layer.hpp> @@ -18,63 +22,54 @@ AnnotationManager::AnnotationManager(float pixelRatio) AnnotationManager::~AnnotationManager() = default; -AnnotationIDs -AnnotationManager::addPointAnnotations(const std::vector<PointAnnotation>& points, const uint8_t) { - AnnotationIDs annotationIDs; - annotationIDs.reserve(points.size()); - - for (const auto& point : points) { - const uint32_t annotationID = nextID++; - auto annotation = std::make_shared<PointAnnotationImpl>(annotationID, point); - pointTree.insert(annotation); - pointAnnotations.emplace(annotationID, annotation); - annotationIDs.push_back(annotationID); - } - - return annotationIDs; +AnnotationID AnnotationManager::addAnnotation(const Annotation& annotation, const uint8_t maxZoom) { + AnnotationID id = nextID++; + updateAnnotation(id, annotation, maxZoom); + return id; } -AnnotationIDs -AnnotationManager::addShapeAnnotations(const std::vector<ShapeAnnotation>& shapes, const uint8_t maxZoom) { - AnnotationIDs annotationIDs; - annotationIDs.reserve(shapes.size()); +void AnnotationManager::updateAnnotation(const AnnotationID& id, const Annotation& annotation, const uint8_t maxZoom) { + removeAnnotation(id); + Annotation::visit(annotation, [&] (const auto& annotation_) { + this->add(id, annotation_, maxZoom); + }); +} - for (const auto& shape : shapes) { - const uint32_t annotationID = nextID++; - shapeAnnotations.emplace(annotationID, - std::make_unique<ShapeAnnotationImpl>(annotationID, shape, maxZoom)); - annotationIDs.push_back(annotationID); +void AnnotationManager::removeAnnotation(const AnnotationID& id) { + if (symbolAnnotations.find(id) != symbolAnnotations.end()) { + symbolTree.remove(symbolAnnotations.at(id)); + symbolAnnotations.erase(id); + } else if (shapeAnnotations.find(id) != shapeAnnotations.end()) { + obsoleteShapeAnnotationLayers.push_back(shapeAnnotations.at(id)->layerID); + shapeAnnotations.erase(id); } +} - return annotationIDs; +void AnnotationManager::add(const AnnotationID& id, const SymbolAnnotation& annotation, const uint8_t) { + auto impl = std::make_shared<SymbolAnnotationImpl>(id, annotation); + symbolTree.insert(impl); + symbolAnnotations.emplace(id, impl); } -void AnnotationManager::updatePointAnnotation(const AnnotationID& id, const PointAnnotation& point, const uint8_t) { - auto foundAnnotation = pointAnnotations.find(id); - if (foundAnnotation != pointAnnotations.end()) { - auto updatedAnnotation = std::make_shared<PointAnnotationImpl>(id, point); - pointTree.remove(foundAnnotation->second); - pointTree.insert(updatedAnnotation); - foundAnnotation->second = updatedAnnotation; - } +void AnnotationManager::add(const AnnotationID& id, const LineAnnotation& annotation, const uint8_t maxZoom) { + shapeAnnotations.emplace(id, + std::make_unique<LineAnnotationImpl>(id, annotation, maxZoom)); } -void AnnotationManager::removeAnnotations(const AnnotationIDs& ids) { - for (const auto& id : ids) { - if (pointAnnotations.find(id) != pointAnnotations.end()) { - pointTree.remove(pointAnnotations.at(id)); - pointAnnotations.erase(id); - } else if (shapeAnnotations.find(id) != shapeAnnotations.end()) { - obsoleteShapeAnnotationLayers.push_back(shapeAnnotations.at(id)->layerID); - shapeAnnotations.erase(id); - } - } +void AnnotationManager::add(const AnnotationID& id, const FillAnnotation& annotation, const uint8_t maxZoom) { + shapeAnnotations.emplace(id, + std::make_unique<FillAnnotationImpl>(id, annotation, maxZoom)); +} + +void AnnotationManager::add(const AnnotationID& id, const StyleSourcedAnnotation& annotation, const uint8_t maxZoom) { + shapeAnnotations.emplace(id, + std::make_unique<StyleSourcedAnnotationImpl>(id, annotation, maxZoom)); } AnnotationIDs AnnotationManager::getPointAnnotationsInBounds(const LatLngBounds& bounds) const { AnnotationIDs result; - pointTree.query(boost::geometry::index::intersects(bounds), + symbolTree.query(boost::geometry::index::intersects(bounds), boost::make_function_output_iterator([&](const auto& val){ result.push_back(val->id); })); @@ -83,7 +78,7 @@ AnnotationIDs AnnotationManager::getPointAnnotationsInBounds(const LatLngBounds& } std::unique_ptr<AnnotationTile> AnnotationManager::getTile(const CanonicalTileID& tileID) { - if (pointAnnotations.empty() && shapeAnnotations.empty()) + if (symbolAnnotations.empty() && shapeAnnotations.empty()) return nullptr; auto tile = std::make_unique<AnnotationTile>(); @@ -94,7 +89,7 @@ std::unique_ptr<AnnotationTile> AnnotationManager::getTile(const CanonicalTileID LatLngBounds tileBounds(tileID); - pointTree.query(boost::geometry::index::intersects(tileBounds), + symbolTree.query(boost::geometry::index::intersects(tileBounds), boost::make_function_output_iterator([&](const auto& val){ val->updateLayer(tileID, pointLayer); })); diff --git a/src/mbgl/annotation/annotation_manager.hpp b/src/mbgl/annotation/annotation_manager.hpp index aaa60278cf..6862739ebb 100644 --- a/src/mbgl/annotation/annotation_manager.hpp +++ b/src/mbgl/annotation/annotation_manager.hpp @@ -1,8 +1,7 @@ #pragma once #include <mbgl/annotation/annotation.hpp> -#include <mbgl/annotation/point_annotation_impl.hpp> -#include <mbgl/annotation/shape_annotation_impl.hpp> +#include <mbgl/annotation/symbol_annotation_impl.hpp> #include <mbgl/sprite/sprite_store.hpp> #include <mbgl/sprite/sprite_atlas.hpp> #include <mbgl/util/geo.hpp> @@ -11,13 +10,14 @@ #include <string> #include <vector> #include <set> +#include <unordered_map> namespace mbgl { -class PointAnnotation; -class ShapeAnnotation; class AnnotationTile; class AnnotationTileMonitor; +class SymbolAnnotationImpl; +class ShapeAnnotationImpl; class Style; class AnnotationManager : private util::noncopyable { @@ -25,10 +25,9 @@ public: AnnotationManager(float pixelRatio); ~AnnotationManager(); - AnnotationIDs addPointAnnotations(const std::vector<PointAnnotation>&, const uint8_t maxZoom); - AnnotationIDs addShapeAnnotations(const std::vector<ShapeAnnotation>&, const uint8_t maxZoom); - void updatePointAnnotation(const AnnotationID&, const PointAnnotation&, const uint8_t maxZoom); - void removeAnnotations(const AnnotationIDs&); + AnnotationID addAnnotation(const Annotation&, const uint8_t maxZoom); + void updateAnnotation(const AnnotationID&, const Annotation&, const uint8_t maxZoom); + void removeAnnotation(const AnnotationID&); AnnotationIDs getPointAnnotationsInBounds(const LatLngBounds&) const; @@ -46,12 +45,22 @@ public: static const std::string PointLayerID; private: + void add(const AnnotationID&, const SymbolAnnotation&, const uint8_t); + void add(const AnnotationID&, const LineAnnotation&, const uint8_t); + void add(const AnnotationID&, const FillAnnotation&, const uint8_t); + void add(const AnnotationID&, const StyleSourcedAnnotation&, const uint8_t); + std::unique_ptr<AnnotationTile> getTile(const CanonicalTileID&); AnnotationID nextID = 0; - PointAnnotationImpl::Tree pointTree; - PointAnnotationImpl::Map pointAnnotations; - ShapeAnnotationImpl::Map shapeAnnotations; + + using SymbolAnnotationTree = boost::geometry::index::rtree<std::shared_ptr<const SymbolAnnotationImpl>, boost::geometry::index::rstar<16, 4>>; + using SymbolAnnotationMap = std::unordered_map<AnnotationID, std::shared_ptr<SymbolAnnotationImpl>>; + using ShapeAnnotationMap = std::unordered_map<AnnotationID, std::unique_ptr<ShapeAnnotationImpl>>; + + SymbolAnnotationTree symbolTree; + SymbolAnnotationMap symbolAnnotations; + ShapeAnnotationMap shapeAnnotations; std::vector<std::string> obsoleteShapeAnnotationLayers; std::set<AnnotationTileMonitor*> monitors; diff --git a/src/mbgl/annotation/fill_annotation_impl.cpp b/src/mbgl/annotation/fill_annotation_impl.cpp new file mode 100644 index 0000000000..2555f90439 --- /dev/null +++ b/src/mbgl/annotation/fill_annotation_impl.cpp @@ -0,0 +1,36 @@ +#include <mbgl/annotation/fill_annotation_impl.hpp> +#include <mbgl/annotation/annotation_manager.hpp> +#include <mbgl/style/style.hpp> +#include <mbgl/layer/fill_layer.hpp> + +namespace mbgl { + +namespace geojsonvt = mapbox::geojsonvt; + +FillAnnotationImpl::FillAnnotationImpl(const AnnotationID id_, const FillAnnotation& annotation_, const uint8_t maxZoom_) + : ShapeAnnotationImpl(id_, maxZoom_), + annotation(annotation_) { +} + +void FillAnnotationImpl::updateStyle(Style& style) const { + if (style.getLayer(layerID)) + return; + + std::unique_ptr<FillLayer> layer = std::make_unique<FillLayer>(); + + layer->paint.fillOpacity = annotation.opacity; + layer->paint.fillColor = annotation.color; + layer->paint.fillOutlineColor = annotation.outlineColor; + + layer->id = layerID; + layer->source = AnnotationManager::SourceID; + layer->sourceLayer = layer->id; + + style.addLayer(std::move(layer), AnnotationManager::PointLayerID); +} + +const Geometry<double>& FillAnnotationImpl::geometry() const { + return annotation.geometry; +} + +} // namespace mbgl diff --git a/src/mbgl/annotation/fill_annotation_impl.hpp b/src/mbgl/annotation/fill_annotation_impl.hpp new file mode 100644 index 0000000000..1d98505c43 --- /dev/null +++ b/src/mbgl/annotation/fill_annotation_impl.hpp @@ -0,0 +1,19 @@ +#pragma once + +#include <mbgl/annotation/shape_annotation_impl.hpp> +#include <mbgl/annotation/annotation.hpp> + +namespace mbgl { + +class FillAnnotationImpl : public ShapeAnnotationImpl { +public: + FillAnnotationImpl(const AnnotationID, const FillAnnotation&, const uint8_t maxZoom); + + void updateStyle(Style&) const final; + const Geometry<double>& geometry() const final; + +private: + const FillAnnotation annotation; +}; + +} // namespace mbgl diff --git a/src/mbgl/annotation/line_annotation_impl.cpp b/src/mbgl/annotation/line_annotation_impl.cpp new file mode 100644 index 0000000000..e22c36bcbe --- /dev/null +++ b/src/mbgl/annotation/line_annotation_impl.cpp @@ -0,0 +1,37 @@ +#include <mbgl/annotation/line_annotation_impl.hpp> +#include <mbgl/annotation/annotation_manager.hpp> +#include <mbgl/style/style.hpp> +#include <mbgl/layer/line_layer.hpp> + +namespace mbgl { + +namespace geojsonvt = mapbox::geojsonvt; + +LineAnnotationImpl::LineAnnotationImpl(const AnnotationID id_, const LineAnnotation& annotation_, const uint8_t maxZoom_) + : ShapeAnnotationImpl(id_, maxZoom_), + annotation(annotation_) { +} + +void LineAnnotationImpl::updateStyle(Style& style) const { + if (style.getLayer(layerID)) + return; + + std::unique_ptr<LineLayer> layer = std::make_unique<LineLayer>(); + layer->layout.lineJoin = LineJoinType::Round; + + layer->paint.lineOpacity = annotation.opacity; + layer->paint.lineWidth = annotation.width; + layer->paint.lineColor = annotation.color; + + layer->id = layerID; + layer->source = AnnotationManager::SourceID; + layer->sourceLayer = layer->id; + + style.addLayer(std::move(layer), AnnotationManager::PointLayerID); +} + +const Geometry<double>& LineAnnotationImpl::geometry() const { + return annotation.geometry; +} + +} // namespace mbgl diff --git a/src/mbgl/annotation/line_annotation_impl.hpp b/src/mbgl/annotation/line_annotation_impl.hpp new file mode 100644 index 0000000000..05a79fc0c3 --- /dev/null +++ b/src/mbgl/annotation/line_annotation_impl.hpp @@ -0,0 +1,19 @@ +#pragma once + +#include <mbgl/annotation/shape_annotation_impl.hpp> +#include <mbgl/annotation/annotation.hpp> + +namespace mbgl { + +class LineAnnotationImpl : public ShapeAnnotationImpl { +public: + LineAnnotationImpl(const AnnotationID, const LineAnnotation&, const uint8_t maxZoom); + + void updateStyle(Style&) const final; + const Geometry<double>& geometry() const final; + +private: + const LineAnnotation annotation; +}; + +} // namespace mbgl diff --git a/src/mbgl/annotation/shape_annotation_impl.cpp b/src/mbgl/annotation/shape_annotation_impl.cpp index a96c4eae72..a5116be72f 100644 --- a/src/mbgl/annotation/shape_annotation_impl.cpp +++ b/src/mbgl/annotation/shape_annotation_impl.cpp @@ -1,83 +1,21 @@ #include <mapbox/geojsonvt/convert.hpp> #include <mbgl/annotation/shape_annotation_impl.hpp> -#include <mbgl/annotation/annotation_manager.hpp> #include <mbgl/annotation/annotation_tile.hpp> -#include <mbgl/util/constants.hpp> -#include <mbgl/util/string.hpp> -#include <mbgl/style/style.hpp> -#include <mbgl/layer/line_layer.hpp> -#include <mbgl/layer/fill_layer.hpp> +#include <mbgl/tile/tile_id.hpp> +#include <mbgl/math/wrap.hpp> #include <mbgl/math/clamp.hpp> +#include <mbgl/util/string.hpp> +#include <mbgl/util/constants.hpp> namespace mbgl { namespace geojsonvt = mapbox::geojsonvt; -ShapeAnnotationImpl::ShapeAnnotationImpl(const AnnotationID id_, - const ShapeAnnotation& shape_, - const uint8_t maxZoom_) -: id(id_), - layerID("com.mapbox.annotations.shape." + util::toString(id)), - shape(shape_), - maxZoom(maxZoom_) { -} - -void ShapeAnnotationImpl::updateStyle(Style& style) { - if (style.getLayer(layerID)) - return; - - if (shape.properties.is<LineAnnotationProperties>()) { - type = geojsonvt::ProjectedFeatureType::LineString; - - std::unique_ptr<LineLayer> layer = std::make_unique<LineLayer>(); - layer->layout.lineJoin = LineJoinType::Round; - - const LineAnnotationProperties& properties = shape.properties.get<LineAnnotationProperties>(); - layer->paint.lineOpacity = properties.opacity; - layer->paint.lineWidth = properties.width; - layer->paint.lineColor = properties.color; - - layer->id = layerID; - layer->source = AnnotationManager::SourceID; - layer->sourceLayer = layer->id; - - style.addLayer(std::move(layer), AnnotationManager::PointLayerID); - - } else if (shape.properties.is<FillAnnotationProperties>()) { - type = geojsonvt::ProjectedFeatureType::Polygon; - - std::unique_ptr<FillLayer> layer = std::make_unique<FillLayer>(); - - const FillAnnotationProperties& properties = shape.properties.get<FillAnnotationProperties>(); - layer->paint.fillOpacity = properties.opacity; - layer->paint.fillColor = properties.color; - layer->paint.fillOutlineColor = properties.outlineColor; - - layer->id = layerID; - layer->source = AnnotationManager::SourceID; - layer->sourceLayer = layer->id; - - style.addLayer(std::move(layer), AnnotationManager::PointLayerID); - - } else { - const StyleLayer* sourceLayer = style.getLayer(shape.properties.get<std::string>()); - if (!sourceLayer) return; - - std::unique_ptr<StyleLayer> layer = sourceLayer->clone(); - - type = layer->is<LineLayer>() - ? geojsonvt::ProjectedFeatureType::LineString - : geojsonvt::ProjectedFeatureType::Polygon; - - layer->id = layerID; - layer->ref = ""; - layer->source = AnnotationManager::SourceID; - layer->sourceLayer = layer->id; - layer->visibility = VisibilityType::Visible; - - style.addLayer(std::move(layer), sourceLayer->id); - } +ShapeAnnotationImpl::ShapeAnnotationImpl(const AnnotationID id_, const uint8_t maxZoom_) + : id(id_), + maxZoom(maxZoom_), + layerID("com.mapbox.annotations.shape." + util::toString(id)) { } struct ToGeoJSONVT { @@ -166,7 +104,7 @@ void ShapeAnnotationImpl::updateTile(const CanonicalTileID& tileID, AnnotationTi const double tolerance = baseTolerance / (maxAmountOfTiles * util::EXTENT); std::vector<geojsonvt::ProjectedFeature> features = { - Geometry<double>::visit(shape.geometry, ToGeoJSONVT(tolerance)) + Geometry<double>::visit(geometry(), ToGeoJSONVT(tolerance)) }; mapbox::geojsonvt::Options options; diff --git a/src/mbgl/annotation/shape_annotation_impl.hpp b/src/mbgl/annotation/shape_annotation_impl.hpp index fb3ef2d893..f342c4b1fc 100644 --- a/src/mbgl/annotation/shape_annotation_impl.hpp +++ b/src/mbgl/annotation/shape_annotation_impl.hpp @@ -3,12 +3,9 @@ #include <mapbox/geojsonvt.hpp> #include <mbgl/annotation/annotation.hpp> -#include <mbgl/annotation/shape_annotation.hpp> -#include <mbgl/util/geo.hpp> -#include <memory> #include <string> -#include <map> +#include <memory> namespace mbgl { @@ -18,20 +15,17 @@ class CanonicalTileID; class ShapeAnnotationImpl { public: - using Map = std::map<AnnotationID, std::unique_ptr<ShapeAnnotationImpl>>; + ShapeAnnotationImpl(const AnnotationID, const uint8_t maxZoom); + virtual ~ShapeAnnotationImpl() = default; - ShapeAnnotationImpl(const AnnotationID, const ShapeAnnotation&, const uint8_t maxZoom); + virtual void updateStyle(Style&) const = 0; + virtual const Geometry<double>& geometry() const = 0; - void updateStyle(Style&); void updateTile(const CanonicalTileID&, AnnotationTile&); const AnnotationID id; - const std::string layerID; - const ShapeAnnotation shape; - -private: const uint8_t maxZoom; - mapbox::geojsonvt::ProjectedFeatureType type; + const std::string layerID; std::unique_ptr<mapbox::geojsonvt::GeoJSONVT> shapeTiler; }; diff --git a/src/mbgl/annotation/style_sourced_annotation_impl.cpp b/src/mbgl/annotation/style_sourced_annotation_impl.cpp new file mode 100644 index 0000000000..5d8f1f0da1 --- /dev/null +++ b/src/mbgl/annotation/style_sourced_annotation_impl.cpp @@ -0,0 +1,38 @@ +#include <mbgl/annotation/style_sourced_annotation_impl.hpp> +#include <mbgl/annotation/annotation_manager.hpp> +#include <mbgl/style/style.hpp> +#include <mbgl/style/style_layer.hpp> + +namespace mbgl { + +namespace geojsonvt = mapbox::geojsonvt; + +StyleSourcedAnnotationImpl::StyleSourcedAnnotationImpl(const AnnotationID id_, const StyleSourcedAnnotation& annotation_, const uint8_t maxZoom_) + : ShapeAnnotationImpl(id_, maxZoom_), + annotation(annotation_) { +} + +void StyleSourcedAnnotationImpl::updateStyle(Style& style) const { + if (style.getLayer(layerID)) + return; + + const StyleLayer* sourceLayer = style.getLayer(annotation.layerID); + if (!sourceLayer) + return; + + std::unique_ptr<StyleLayer> layer = sourceLayer->clone(); + + layer->id = layerID; + layer->ref = ""; + layer->source = AnnotationManager::SourceID; + layer->sourceLayer = layer->id; + layer->visibility = VisibilityType::Visible; + + style.addLayer(std::move(layer), sourceLayer->id); +} + +const Geometry<double>& StyleSourcedAnnotationImpl::geometry() const { + return annotation.geometry; +} + +} // namespace mbgl diff --git a/src/mbgl/annotation/style_sourced_annotation_impl.hpp b/src/mbgl/annotation/style_sourced_annotation_impl.hpp new file mode 100644 index 0000000000..734f6c8290 --- /dev/null +++ b/src/mbgl/annotation/style_sourced_annotation_impl.hpp @@ -0,0 +1,19 @@ +#pragma once + +#include <mbgl/annotation/shape_annotation_impl.hpp> +#include <mbgl/annotation/annotation.hpp> + +namespace mbgl { + +class StyleSourcedAnnotationImpl : public ShapeAnnotationImpl { +public: + StyleSourcedAnnotationImpl(const AnnotationID, const StyleSourcedAnnotation&, const uint8_t maxZoom); + + void updateStyle(Style&) const final; + const Geometry<double>& geometry() const final; + +private: + const StyleSourcedAnnotation annotation; +}; + +} // namespace mbgl diff --git a/src/mbgl/annotation/point_annotation_impl.cpp b/src/mbgl/annotation/symbol_annotation_impl.cpp index a1367f3901..5ad6142eec 100644 --- a/src/mbgl/annotation/point_annotation_impl.cpp +++ b/src/mbgl/annotation/symbol_annotation_impl.cpp @@ -1,24 +1,29 @@ -#include <mbgl/annotation/point_annotation_impl.hpp> +#include <mbgl/annotation/symbol_annotation_impl.hpp> #include <mbgl/annotation/annotation_tile.hpp> #include <mbgl/math/clamp.hpp> namespace mbgl { -PointAnnotationImpl::PointAnnotationImpl(const AnnotationID id_, const PointAnnotation& point_) +SymbolAnnotationImpl::SymbolAnnotationImpl(const AnnotationID id_, const SymbolAnnotation& annotation_) : id(id_), - point(point_) { + annotation(annotation_) { + if (!annotation.geometry.is<Point<double>>()) { + throw std::runtime_error("unsupported symbol annotation geometry type"); + } } -void PointAnnotationImpl::updateLayer(const CanonicalTileID& tileID, AnnotationTileLayer& layer) const { +void SymbolAnnotationImpl::updateLayer(const CanonicalTileID& tileID, AnnotationTileLayer& layer) const { std::unordered_map<std::string, std::string> featureProperties; - featureProperties.emplace("sprite", point.icon.empty() ? std::string("default_marker") : point.icon); + featureProperties.emplace("sprite", annotation.icon.empty() ? std::string("default_marker") : annotation.icon); + + const Point<double>& p = annotation.geometry.get<Point<double>>(); // Clamp to the latitude limits of Web Mercator. - const double constrainedLatitude = util::clamp(point.position.latitude, -util::LATITUDE_MAX, util::LATITUDE_MAX); + const double constrainedLatitude = util::clamp(p.y, -util::LATITUDE_MAX, util::LATITUDE_MAX); // Project a coordinate into unit space in a square map. const double sine = std::sin(constrainedLatitude * util::DEG2RAD); - const double x = point.position.longitude / util::DEGREES_MAX + 0.5; + const double x = p.x / util::DEGREES_MAX + 0.5; const double y = 0.5 - 0.25 * std::log((1.0 + sine) / (1.0 - sine)) / M_PI; Point<double> projected(x, y); diff --git a/src/mbgl/annotation/point_annotation_impl.hpp b/src/mbgl/annotation/symbol_annotation_impl.hpp index d8852fca9e..43c490140d 100644 --- a/src/mbgl/annotation/point_annotation_impl.hpp +++ b/src/mbgl/annotation/symbol_annotation_impl.hpp @@ -1,7 +1,6 @@ #pragma once #include <mbgl/annotation/annotation.hpp> -#include <mbgl/annotation/point_annotation.hpp> #include <mbgl/util/geo.hpp> #include <string> @@ -36,31 +35,29 @@ namespace mbgl { class AnnotationTileLayer; class CanonicalTileID; -class PointAnnotationImpl { +class SymbolAnnotationImpl { public: - using Map = std::map<AnnotationID, std::shared_ptr<PointAnnotationImpl>>; - using Tree = boost::geometry::index::rtree<std::shared_ptr<const PointAnnotationImpl>, boost::geometry::index::rstar<16, 4>>; - - PointAnnotationImpl(const AnnotationID, const PointAnnotation&); + SymbolAnnotationImpl(const AnnotationID, const SymbolAnnotation&); void updateLayer(const CanonicalTileID&, AnnotationTileLayer&) const; const AnnotationID id; - const PointAnnotation point; + const SymbolAnnotation annotation; }; } // namespace mbgl -// Tell Boost Geometry how to access a std::shared_ptr<mbgl::PointAnnotation> object. +// Tell Boost Geometry how to access a std::shared_ptr<mbgl::SymbolAnnotation> object. namespace boost { namespace geometry { namespace index { template <> -struct indexable<std::shared_ptr<const mbgl::PointAnnotationImpl>> { - using result_type = const mbgl::LatLng&; - inline const mbgl::LatLng& operator()(const std::shared_ptr<const mbgl::PointAnnotationImpl>& v) const { - return v->point.position; +struct indexable<std::shared_ptr<const mbgl::SymbolAnnotationImpl>> { + using result_type = mbgl::LatLng; + inline mbgl::LatLng operator()(const std::shared_ptr<const mbgl::SymbolAnnotationImpl>& v) const { + const mbgl::Point<double>& p = v->annotation.geometry.get<mbgl::Point<double>>(); + return mbgl::LatLng(p.y, p.x); } }; diff --git a/src/mbgl/map/map.cpp b/src/mbgl/map/map.cpp index e0a73c2a06..f89fde1f03 100644 --- a/src/mbgl/map/map.cpp +++ b/src/mbgl/map/map.cpp @@ -3,8 +3,6 @@ #include <mbgl/map/view.hpp> #include <mbgl/map/transform.hpp> #include <mbgl/map/transform_state.hpp> -#include <mbgl/annotation/point_annotation.hpp> -#include <mbgl/annotation/shape_annotation.hpp> #include <mbgl/annotation/annotation_manager.hpp> #include <mbgl/style/style.hpp> #include <mbgl/style/style_observer.hpp> @@ -693,37 +691,19 @@ double Map::getTopOffsetPixelsForAnnotationIcon(const std::string& name) { return impl->annotationManager->getTopOffsetPixelsForIcon(name); } -AnnotationID Map::addPointAnnotation(const PointAnnotation& annotation) { - return addPointAnnotations({ annotation }).front(); -} - -AnnotationIDs Map::addPointAnnotations(const std::vector<PointAnnotation>& annotations) { - auto result = impl->annotationManager->addPointAnnotations(annotations, getMaxZoom()); - update(Update::Annotations); - return result; -} - -AnnotationID Map::addShapeAnnotation(const ShapeAnnotation& annotation) { - return addShapeAnnotations({ annotation }).front(); -} - -AnnotationIDs Map::addShapeAnnotations(const std::vector<ShapeAnnotation>& annotations) { - auto result = impl->annotationManager->addShapeAnnotations(annotations, getMaxZoom()); +AnnotationID Map::addAnnotation(const Annotation& annotation) { + auto result = impl->annotationManager->addAnnotation(annotation, getMaxZoom()); update(Update::Annotations); return result; } -void Map::updatePointAnnotation(AnnotationID annotationId, const PointAnnotation& annotation) { - impl->annotationManager->updatePointAnnotation(annotationId, annotation, getMaxZoom()); +void Map::updateAnnotation(AnnotationID id, const Annotation& annotation) { + impl->annotationManager->updateAnnotation(id, annotation, getMaxZoom()); update(Update::Annotations); } void Map::removeAnnotation(AnnotationID annotation) { - removeAnnotations({ annotation }); -} - -void Map::removeAnnotations(const AnnotationIDs& annotations) { - impl->annotationManager->removeAnnotations(annotations); + impl->annotationManager->removeAnnotation(annotation); update(Update::Annotations); } diff --git a/src/mbgl/util/geometry.hpp b/src/mbgl/util/geometry.hpp deleted file mode 100644 index 6b9c332bf2..0000000000 --- a/src/mbgl/util/geometry.hpp +++ /dev/null @@ -1,37 +0,0 @@ -#pragma once - -#include <mapbox/geometry/geometry.hpp> -#include <mapbox/geometry/point_arithmetic.hpp> - -namespace mbgl { - -template <class T> -using Point = mapbox::geometry::point<T>; - -template <class T> -using LineString = mapbox::geometry::line_string<T>; - -template <class T> -using Polygon = mapbox::geometry::polygon<T>; - -template <class T> -using MultiPoint = mapbox::geometry::multi_point<T>; - -template <class T> -using MultiLineString = mapbox::geometry::multi_line_string<T>; - -template <class T> -using MultiPolygon = mapbox::geometry::multi_polygon<T>; - -template <class T> -using LinearRing = mapbox::geometry::linear_ring<T>; - -template <class T> -using Geometry = mapbox::geometry::geometry<T>; - -template <class S, class T> -Point<S> convertPoint(const Point<T>& p) { - return Point<S>(p.x, p.y); -} - -} // namespace mbgl |