From 3689f52ef3f001450dd2480f5a985568efefe819 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Wed, 1 Jun 2016 17:29:50 -0700 Subject: [core] Constrain annotation API to the supported geometry types --- include/mbgl/annotation/annotation.hpp | 14 ++++++++++---- src/mbgl/annotation/fill_annotation_impl.cpp | 2 +- src/mbgl/annotation/fill_annotation_impl.hpp | 2 +- src/mbgl/annotation/line_annotation_impl.cpp | 2 +- src/mbgl/annotation/line_annotation_impl.hpp | 2 +- src/mbgl/annotation/shape_annotation_impl.cpp | 14 +------------- src/mbgl/annotation/shape_annotation_impl.hpp | 2 +- src/mbgl/annotation/style_sourced_annotation_impl.cpp | 2 +- src/mbgl/annotation/style_sourced_annotation_impl.hpp | 2 +- src/mbgl/annotation/symbol_annotation_impl.cpp | 5 +---- src/mbgl/annotation/symbol_annotation_impl.hpp | 2 +- 11 files changed, 20 insertions(+), 29 deletions(-) diff --git a/include/mbgl/annotation/annotation.hpp b/include/mbgl/annotation/annotation.hpp index 3b2b7f3ade..8b0c3026a8 100644 --- a/include/mbgl/annotation/annotation.hpp +++ b/include/mbgl/annotation/annotation.hpp @@ -16,13 +16,19 @@ using AnnotationIDs = std::vector; class SymbolAnnotation { public: - Geometry geometry; + Point geometry; std::string icon; }; +using ShapeAnnotationGeometry = variant< + LineString, + Polygon, + MultiLineString, + MultiPolygon>; + class LineAnnotation { public: - Geometry geometry; + ShapeAnnotationGeometry geometry; float opacity = 1; float width = 1; Color color = {{ 0, 0, 0, 1 }}; @@ -30,7 +36,7 @@ public: class FillAnnotation { public: - Geometry geometry; + ShapeAnnotationGeometry geometry; float opacity = 1; Color color = {{ 0, 0, 0, 1 }}; Color outlineColor = {{ 0, 0, 0, -1 }}; @@ -39,7 +45,7 @@ public: // An annotation whose type and properties are sourced from a style layer. class StyleSourcedAnnotation { public: - Geometry geometry; + ShapeAnnotationGeometry geometry; std::string layerID; }; diff --git a/src/mbgl/annotation/fill_annotation_impl.cpp b/src/mbgl/annotation/fill_annotation_impl.cpp index 2555f90439..093f53fb91 100644 --- a/src/mbgl/annotation/fill_annotation_impl.cpp +++ b/src/mbgl/annotation/fill_annotation_impl.cpp @@ -29,7 +29,7 @@ void FillAnnotationImpl::updateStyle(Style& style) const { style.addLayer(std::move(layer), AnnotationManager::PointLayerID); } -const Geometry& FillAnnotationImpl::geometry() const { +const ShapeAnnotationGeometry& FillAnnotationImpl::geometry() const { return annotation.geometry; } diff --git a/src/mbgl/annotation/fill_annotation_impl.hpp b/src/mbgl/annotation/fill_annotation_impl.hpp index 1d98505c43..c396499e38 100644 --- a/src/mbgl/annotation/fill_annotation_impl.hpp +++ b/src/mbgl/annotation/fill_annotation_impl.hpp @@ -10,7 +10,7 @@ public: FillAnnotationImpl(const AnnotationID, const FillAnnotation&, const uint8_t maxZoom); void updateStyle(Style&) const final; - const Geometry& geometry() const final; + const ShapeAnnotationGeometry& geometry() const final; private: const FillAnnotation annotation; diff --git a/src/mbgl/annotation/line_annotation_impl.cpp b/src/mbgl/annotation/line_annotation_impl.cpp index e22c36bcbe..5bcc142a5b 100644 --- a/src/mbgl/annotation/line_annotation_impl.cpp +++ b/src/mbgl/annotation/line_annotation_impl.cpp @@ -30,7 +30,7 @@ void LineAnnotationImpl::updateStyle(Style& style) const { style.addLayer(std::move(layer), AnnotationManager::PointLayerID); } -const Geometry& LineAnnotationImpl::geometry() const { +const ShapeAnnotationGeometry& LineAnnotationImpl::geometry() const { return annotation.geometry; } diff --git a/src/mbgl/annotation/line_annotation_impl.hpp b/src/mbgl/annotation/line_annotation_impl.hpp index 05a79fc0c3..05d650c051 100644 --- a/src/mbgl/annotation/line_annotation_impl.hpp +++ b/src/mbgl/annotation/line_annotation_impl.hpp @@ -10,7 +10,7 @@ public: LineAnnotationImpl(const AnnotationID, const LineAnnotation&, const uint8_t maxZoom); void updateStyle(Style&) const final; - const Geometry& geometry() const final; + const ShapeAnnotationGeometry& geometry() const final; private: const LineAnnotation annotation; diff --git a/src/mbgl/annotation/shape_annotation_impl.cpp b/src/mbgl/annotation/shape_annotation_impl.cpp index a5116be72f..a2dc4c8093 100644 --- a/src/mbgl/annotation/shape_annotation_impl.cpp +++ b/src/mbgl/annotation/shape_annotation_impl.cpp @@ -57,18 +57,6 @@ struct ToGeoJSONVT { return convertFeature(geojsonvt::ProjectedFeatureType::Polygon, converted); } - geojsonvt::ProjectedFeature operator()(const Point&) { - throw std::runtime_error("unsupported shape annotation geometry type"); - } - - geojsonvt::ProjectedFeature operator()(const MultiPoint&) { - throw std::runtime_error("unsupported shape annotation geometry type"); - } - - geojsonvt::ProjectedFeature operator()(const mapbox::geometry::geometry_collection&) { - throw std::runtime_error("unsupported shape annotation geometry type"); - } - private: geojsonvt::LonLat convertPoint(const Point& p) const { return { @@ -104,7 +92,7 @@ void ShapeAnnotationImpl::updateTile(const CanonicalTileID& tileID, AnnotationTi const double tolerance = baseTolerance / (maxAmountOfTiles * util::EXTENT); std::vector features = { - Geometry::visit(geometry(), ToGeoJSONVT(tolerance)) + ShapeAnnotationGeometry::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 f342c4b1fc..7f36f8b888 100644 --- a/src/mbgl/annotation/shape_annotation_impl.hpp +++ b/src/mbgl/annotation/shape_annotation_impl.hpp @@ -19,7 +19,7 @@ public: virtual ~ShapeAnnotationImpl() = default; virtual void updateStyle(Style&) const = 0; - virtual const Geometry& geometry() const = 0; + virtual const ShapeAnnotationGeometry& geometry() const = 0; void updateTile(const CanonicalTileID&, AnnotationTile&); diff --git a/src/mbgl/annotation/style_sourced_annotation_impl.cpp b/src/mbgl/annotation/style_sourced_annotation_impl.cpp index 5d8f1f0da1..ae92d917aa 100644 --- a/src/mbgl/annotation/style_sourced_annotation_impl.cpp +++ b/src/mbgl/annotation/style_sourced_annotation_impl.cpp @@ -31,7 +31,7 @@ void StyleSourcedAnnotationImpl::updateStyle(Style& style) const { style.addLayer(std::move(layer), sourceLayer->id); } -const Geometry& StyleSourcedAnnotationImpl::geometry() const { +const ShapeAnnotationGeometry& StyleSourcedAnnotationImpl::geometry() const { return annotation.geometry; } diff --git a/src/mbgl/annotation/style_sourced_annotation_impl.hpp b/src/mbgl/annotation/style_sourced_annotation_impl.hpp index 734f6c8290..98e9910c66 100644 --- a/src/mbgl/annotation/style_sourced_annotation_impl.hpp +++ b/src/mbgl/annotation/style_sourced_annotation_impl.hpp @@ -10,7 +10,7 @@ public: StyleSourcedAnnotationImpl(const AnnotationID, const StyleSourcedAnnotation&, const uint8_t maxZoom); void updateStyle(Style&) const final; - const Geometry& geometry() const final; + const ShapeAnnotationGeometry& geometry() const final; private: const StyleSourcedAnnotation annotation; diff --git a/src/mbgl/annotation/symbol_annotation_impl.cpp b/src/mbgl/annotation/symbol_annotation_impl.cpp index 5ad6142eec..44a89576bb 100644 --- a/src/mbgl/annotation/symbol_annotation_impl.cpp +++ b/src/mbgl/annotation/symbol_annotation_impl.cpp @@ -7,16 +7,13 @@ namespace mbgl { SymbolAnnotationImpl::SymbolAnnotationImpl(const AnnotationID id_, const SymbolAnnotation& annotation_) : id(id_), annotation(annotation_) { - if (!annotation.geometry.is>()) { - throw std::runtime_error("unsupported symbol annotation geometry type"); - } } void SymbolAnnotationImpl::updateLayer(const CanonicalTileID& tileID, AnnotationTileLayer& layer) const { std::unordered_map featureProperties; featureProperties.emplace("sprite", annotation.icon.empty() ? std::string("default_marker") : annotation.icon); - const Point& p = annotation.geometry.get>(); + const Point& p = annotation.geometry; // Clamp to the latitude limits of Web Mercator. const double constrainedLatitude = util::clamp(p.y, -util::LATITUDE_MAX, util::LATITUDE_MAX); diff --git a/src/mbgl/annotation/symbol_annotation_impl.hpp b/src/mbgl/annotation/symbol_annotation_impl.hpp index 43c490140d..5dc882ab93 100644 --- a/src/mbgl/annotation/symbol_annotation_impl.hpp +++ b/src/mbgl/annotation/symbol_annotation_impl.hpp @@ -56,7 +56,7 @@ template <> struct indexable> { using result_type = mbgl::LatLng; inline mbgl::LatLng operator()(const std::shared_ptr& v) const { - const mbgl::Point& p = v->annotation.geometry.get>(); + const mbgl::Point& p = v->annotation.geometry; return mbgl::LatLng(p.y, p.x); } }; -- cgit v1.2.1