[core] Constrain annotation API to the supported geometry types
This commit is contained in:
@@ -16,13 +16,19 @@ using AnnotationIDs = std::vector<AnnotationID>;
|
||||
|
||||
class SymbolAnnotation {
|
||||
public:
|
||||
Geometry<double> geometry;
|
||||
Point<double> geometry;
|
||||
std::string icon;
|
||||
};
|
||||
|
||||
using ShapeAnnotationGeometry = variant<
|
||||
LineString<double>,
|
||||
Polygon<double>,
|
||||
MultiLineString<double>,
|
||||
MultiPolygon<double>>;
|
||||
|
||||
class LineAnnotation {
|
||||
public:
|
||||
Geometry<double> geometry;
|
||||
ShapeAnnotationGeometry geometry;
|
||||
float opacity = 1;
|
||||
float width = 1;
|
||||
Color color = {{ 0, 0, 0, 1 }};
|
||||
@@ -30,7 +36,7 @@ public:
|
||||
|
||||
class FillAnnotation {
|
||||
public:
|
||||
Geometry<double> 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<double> geometry;
|
||||
ShapeAnnotationGeometry geometry;
|
||||
std::string layerID;
|
||||
};
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ void FillAnnotationImpl::updateStyle(Style& style) const {
|
||||
style.addLayer(std::move(layer), AnnotationManager::PointLayerID);
|
||||
}
|
||||
|
||||
const Geometry<double>& FillAnnotationImpl::geometry() const {
|
||||
const ShapeAnnotationGeometry& FillAnnotationImpl::geometry() const {
|
||||
return annotation.geometry;
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ public:
|
||||
FillAnnotationImpl(const AnnotationID, const FillAnnotation&, const uint8_t maxZoom);
|
||||
|
||||
void updateStyle(Style&) const final;
|
||||
const Geometry<double>& geometry() const final;
|
||||
const ShapeAnnotationGeometry& geometry() const final;
|
||||
|
||||
private:
|
||||
const FillAnnotation annotation;
|
||||
|
||||
@@ -30,7 +30,7 @@ void LineAnnotationImpl::updateStyle(Style& style) const {
|
||||
style.addLayer(std::move(layer), AnnotationManager::PointLayerID);
|
||||
}
|
||||
|
||||
const Geometry<double>& LineAnnotationImpl::geometry() const {
|
||||
const ShapeAnnotationGeometry& LineAnnotationImpl::geometry() const {
|
||||
return annotation.geometry;
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ public:
|
||||
LineAnnotationImpl(const AnnotationID, const LineAnnotation&, const uint8_t maxZoom);
|
||||
|
||||
void updateStyle(Style&) const final;
|
||||
const Geometry<double>& geometry() const final;
|
||||
const ShapeAnnotationGeometry& geometry() const final;
|
||||
|
||||
private:
|
||||
const LineAnnotation annotation;
|
||||
|
||||
@@ -57,18 +57,6 @@ struct ToGeoJSONVT {
|
||||
return convertFeature(geojsonvt::ProjectedFeatureType::Polygon, converted);
|
||||
}
|
||||
|
||||
geojsonvt::ProjectedFeature operator()(const Point<double>&) {
|
||||
throw std::runtime_error("unsupported shape annotation geometry type");
|
||||
}
|
||||
|
||||
geojsonvt::ProjectedFeature operator()(const MultiPoint<double>&) {
|
||||
throw std::runtime_error("unsupported shape annotation geometry type");
|
||||
}
|
||||
|
||||
geojsonvt::ProjectedFeature operator()(const mapbox::geometry::geometry_collection<double>&) {
|
||||
throw std::runtime_error("unsupported shape annotation geometry type");
|
||||
}
|
||||
|
||||
private:
|
||||
geojsonvt::LonLat convertPoint(const Point<double>& p) const {
|
||||
return {
|
||||
@@ -104,7 +92,7 @@ void ShapeAnnotationImpl::updateTile(const CanonicalTileID& tileID, AnnotationTi
|
||||
const double tolerance = baseTolerance / (maxAmountOfTiles * util::EXTENT);
|
||||
|
||||
std::vector<geojsonvt::ProjectedFeature> features = {
|
||||
Geometry<double>::visit(geometry(), ToGeoJSONVT(tolerance))
|
||||
ShapeAnnotationGeometry::visit(geometry(), ToGeoJSONVT(tolerance))
|
||||
};
|
||||
|
||||
mapbox::geojsonvt::Options options;
|
||||
|
||||
@@ -19,7 +19,7 @@ public:
|
||||
virtual ~ShapeAnnotationImpl() = default;
|
||||
|
||||
virtual void updateStyle(Style&) const = 0;
|
||||
virtual const Geometry<double>& geometry() const = 0;
|
||||
virtual const ShapeAnnotationGeometry& geometry() const = 0;
|
||||
|
||||
void updateTile(const CanonicalTileID&, AnnotationTile&);
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ void StyleSourcedAnnotationImpl::updateStyle(Style& style) const {
|
||||
style.addLayer(std::move(layer), sourceLayer->id);
|
||||
}
|
||||
|
||||
const Geometry<double>& StyleSourcedAnnotationImpl::geometry() const {
|
||||
const ShapeAnnotationGeometry& StyleSourcedAnnotationImpl::geometry() const {
|
||||
return annotation.geometry;
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ public:
|
||||
StyleSourcedAnnotationImpl(const AnnotationID, const StyleSourcedAnnotation&, const uint8_t maxZoom);
|
||||
|
||||
void updateStyle(Style&) const final;
|
||||
const Geometry<double>& geometry() const final;
|
||||
const ShapeAnnotationGeometry& geometry() const final;
|
||||
|
||||
private:
|
||||
const StyleSourcedAnnotation annotation;
|
||||
|
||||
@@ -7,16 +7,13 @@ namespace mbgl {
|
||||
SymbolAnnotationImpl::SymbolAnnotationImpl(const AnnotationID id_, const SymbolAnnotation& annotation_)
|
||||
: id(id_),
|
||||
annotation(annotation_) {
|
||||
if (!annotation.geometry.is<Point<double>>()) {
|
||||
throw std::runtime_error("unsupported symbol annotation geometry type");
|
||||
}
|
||||
}
|
||||
|
||||
void SymbolAnnotationImpl::updateLayer(const CanonicalTileID& tileID, AnnotationTileLayer& layer) const {
|
||||
std::unordered_map<std::string, std::string> featureProperties;
|
||||
featureProperties.emplace("sprite", annotation.icon.empty() ? std::string("default_marker") : annotation.icon);
|
||||
|
||||
const Point<double>& p = annotation.geometry.get<Point<double>>();
|
||||
const Point<double>& p = annotation.geometry;
|
||||
|
||||
// Clamp to the latitude limits of Web Mercator.
|
||||
const double constrainedLatitude = util::clamp(p.y, -util::LATITUDE_MAX, util::LATITUDE_MAX);
|
||||
|
||||
@@ -56,7 +56,7 @@ template <>
|
||||
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>>();
|
||||
const mbgl::Point<double>& p = v->annotation.geometry;
|
||||
return mbgl::LatLng(p.y, p.x);
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user