1 #pragma once 2 3 #include <mbgl/util/string.hpp> 4 #include <mapbox/geojsonvt.hpp> 5 6 #include <mbgl/annotation/annotation.hpp> 7 #include <mbgl/util/geometry.hpp> 8 #include <mbgl/style/style.hpp> 9 10 #include <string> 11 #include <memory> 12 13 namespace mbgl { 14 15 class AnnotationTileData; 16 class CanonicalTileID; 17 18 class ShapeAnnotationImpl { 19 public: 20 ShapeAnnotationImpl(const AnnotationID); 21 virtual ~ShapeAnnotationImpl() = default; 22 23 virtual void updateStyle(style::Style::Impl&) const = 0; 24 virtual const ShapeAnnotationGeometry& geometry() const = 0; 25 26 void updateTileData(const CanonicalTileID&, AnnotationTileData&); 27 28 const AnnotationID id; 29 const std::string layerID; 30 std::unique_ptr<mapbox::geojsonvt::GeoJSONVT> shapeTiler; 31 }; 32 33 struct CloseShapeAnnotation { operator ()mbgl::CloseShapeAnnotation34 ShapeAnnotationGeometry operator()(const mbgl::LineString<double> &geom) const { 35 return geom; 36 } operator ()mbgl::CloseShapeAnnotation37 ShapeAnnotationGeometry operator()(const mbgl::MultiLineString<double> &geom) const { 38 return geom; 39 } operator ()mbgl::CloseShapeAnnotation40 ShapeAnnotationGeometry operator()(const mbgl::Polygon<double> &geom) const { 41 mbgl::Polygon<double> closed = geom; 42 for (auto &ring : closed) { 43 if (!ring.empty() && ring.front() != ring.back()) { 44 ring.emplace_back(ring.front()); 45 } 46 } 47 return closed; 48 } operator ()mbgl::CloseShapeAnnotation49 ShapeAnnotationGeometry operator()(const mbgl::MultiPolygon<double> &geom) const { 50 mbgl::MultiPolygon<double> closed = geom; 51 for (auto &polygon : closed) { 52 for (auto &ring : polygon) { 53 if (!ring.empty() && ring.front() != ring.back()) { 54 ring.emplace_back(ring.front()); 55 } 56 } 57 } 58 return closed; 59 } 60 }; 61 62 } // namespace mbgl 63