-
Notifications
You must be signed in to change notification settings - Fork 274
Allow custom styling for VectorTilesRasterOverlay. #1430
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
bf50d7d
2b81a3a
e5ba7ef
250bcc6
403dc49
b6400a0
aa22ab5
4250318
640ed6f
dd3cff0
58c44aa
4eba129
63d4b8f
70c812b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -2,6 +2,7 @@ | |||||
|
|
||||||
| #include <CesiumUtility/Color.h> | ||||||
|
|
||||||
| #include <functional> | ||||||
| #include <optional> | ||||||
|
|
||||||
| namespace CesiumVectorData { | ||||||
|
|
@@ -46,6 +47,9 @@ struct ColorStyle { | |||||
| * a given seed, but nearby seeds will not usually return nearby colors. | ||||||
| */ | ||||||
| CesiumUtility::Color getColor(size_t randomColorSeed = 0) const; | ||||||
|
|
||||||
| /** @brief Checks if two ColorStyle instances are equal. */ | ||||||
| bool operator==(const ColorStyle& rhs) const; | ||||||
| }; | ||||||
|
|
||||||
| /** @brief The mode to use when interpreting a given line width. */ | ||||||
|
|
@@ -78,6 +82,9 @@ struct LineStyle : public ColorStyle { | |||||
| * @brief The mode to use when interpreting `width`. | ||||||
| */ | ||||||
| LineWidthMode widthMode = LineWidthMode::Pixels; | ||||||
|
|
||||||
| /** @brief Checks if two LineStyle instances are equal. */ | ||||||
| bool operator==(const LineStyle& rhs) const; | ||||||
| }; | ||||||
|
|
||||||
| /** @brief The style used to draw a Polygon. */ | ||||||
|
|
@@ -92,6 +99,9 @@ struct PolygonStyle { | |||||
| * polygon will not be outlined. | ||||||
| */ | ||||||
| std::optional<LineStyle> outline; | ||||||
|
|
||||||
| /** @brief Checks if two PolygonStyle instances are equal. */ | ||||||
| bool operator==(const PolygonStyle& rhs) const; | ||||||
| }; | ||||||
|
|
||||||
| /** @brief The style used to draw a point. */ | ||||||
|
|
@@ -108,6 +118,9 @@ struct PointStyle { | |||||
| * point will not be outlined. | ||||||
| */ | ||||||
| std::optional<LineStyle> outline; | ||||||
|
|
||||||
| /** @brief Checks if two PointStyle instances are equal. */ | ||||||
| bool operator==(const PointStyle& rhs) const; | ||||||
| }; | ||||||
|
|
||||||
| /** | ||||||
|
|
@@ -149,5 +162,48 @@ struct VectorStyle { | |||||
| * @brief Initializes all styles to the given color. | ||||||
| */ | ||||||
| VectorStyle(const CesiumUtility::Color& color); | ||||||
|
|
||||||
| /** @brief Checks if two VectorStyle instances are equal. */ | ||||||
| bool operator==(const VectorStyle& rhs) const; | ||||||
| }; | ||||||
| } // namespace CesiumVectorData | ||||||
|
|
||||||
| /** @brief Hash implementation for \ref CesiumVectorData::ColorStyle. */ | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Prefer
Suggested change
|
||||||
| template <> struct std::hash<CesiumVectorData::ColorStyle> { | ||||||
| /** @brief Returns a `size_t` hash of the provided \ref | ||||||
| * CesiumVectorData::ColorStyle instance. */ | ||||||
| std::size_t | ||||||
| operator()(const CesiumVectorData::ColorStyle& style) const noexcept; | ||||||
| }; | ||||||
| } // namespace CesiumVectorData | ||||||
|
|
||||||
| /** @brief Hash implementation for \ref CesiumVectorData::LineStyle. */ | ||||||
| template <> struct std::hash<CesiumVectorData::LineStyle> { | ||||||
| /** @brief Returns a `size_t` hash of the provided \ref | ||||||
| * CesiumVectorData::LineStyle instance. */ | ||||||
| std::size_t | ||||||
| operator()(const CesiumVectorData::LineStyle& style) const noexcept; | ||||||
| }; | ||||||
|
|
||||||
| /** @brief Hash implementation for \ref CesiumVectorData::PolygonStyle. */ | ||||||
| template <> struct std::hash<CesiumVectorData::PolygonStyle> { | ||||||
| /** @brief Returns a `size_t` hash of the provided \ref | ||||||
| * CesiumVectorData::PolygonStyle instance. */ | ||||||
| std::size_t | ||||||
| operator()(const CesiumVectorData::PolygonStyle& style) const noexcept; | ||||||
| }; | ||||||
|
|
||||||
| /** @brief Hash implementation for \ref CesiumVectorData::PointStyle. */ | ||||||
| template <> struct std::hash<CesiumVectorData::PointStyle> { | ||||||
| /** @brief Returns a `size_t` hash of the provided \ref | ||||||
| * CesiumVectorData::PointStyle instance. */ | ||||||
| std::size_t | ||||||
| operator()(const CesiumVectorData::PointStyle& style) const noexcept; | ||||||
| }; | ||||||
|
|
||||||
| /** @brief Hash implementation for \ref CesiumVectorData::VectorStyle. */ | ||||||
| template <> struct std::hash<CesiumVectorData::VectorStyle> { | ||||||
| /** @brief Returns a `size_t` hash of the provided \ref | ||||||
| * CesiumVectorData::VectorStyle instance. */ | ||||||
| std::size_t | ||||||
| operator()(const CesiumVectorData::VectorStyle& style) const noexcept; | ||||||
| }; | ||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -395,6 +395,43 @@ void VectorRasterizer::drawPoints( | |
| style); | ||
| } | ||
|
|
||
| void VectorRasterizer::drawPoints( | ||
| const std::vector<CesiumGeospatial::Cartographic>& points, | ||
| const std::vector<const CesiumVectorData::VectorStyle*>& styles) { | ||
| if (this->_finalized) { | ||
| return; | ||
| } | ||
|
|
||
| for (size_t i = 0; i < points.size(); i++) { | ||
| BLPoint point = radiansToPoint( | ||
| points[i].longitude, | ||
| points[i].latitude, | ||
| this->_bounds, | ||
| this->_context); | ||
| // clang-tidy does not understand that we *are* in fact checking these | ||
| // optionals | ||
| if (styles[i]->point.fill) { | ||
|
Comment on lines
+399
to
+413
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems like there's some assumptions here:
We should add |
||
| // NOLINTBEGIN(bugprone-unchecked-optional-access) | ||
| this->_context.fillCircle( | ||
| BLCircle(point.x, point.y, styles[i]->point.radius), | ||
| BLRgba32(styles[i] | ||
| ->point.fill->getColor(seedForObject(points[i], 17)) | ||
| .toRgba32())); | ||
| // NOLINTEND(bugprone-unchecked-optional-access) | ||
| } | ||
|
|
||
| if (styles[i]->point.outline) { | ||
| // NOLINTBEGIN(bugprone-unchecked-optional-access) | ||
| this->_context.strokeCircle( | ||
| BLCircle(point.x, point.y, styles[i]->point.radius), | ||
| BLRgba32(styles[i] | ||
| ->point.outline->getColor(seedForObject(points[i], 31)) | ||
| .toRgba32())); | ||
| // NOLINTEND(bugprone-unchecked-optional-access) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| void VectorRasterizer::drawGeoJsonObject( | ||
| const GeoJsonObject& geoJsonObject, | ||
| const VectorStyle& style) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| #pragma once | ||
|
|
||
| #include "Library.h" | ||
|
|
||
| #include <CesiumAsync/AsyncSystem.h> | ||
| #include <CesiumAsync/Future.h> | ||
| #include <CesiumGeospatial/Cartographic.h> | ||
| #include <CesiumGltf/Model.h> | ||
| #include <CesiumVectorData/VectorStyle.h> | ||
|
|
||
| namespace CesiumVectorOverlays { | ||
|
|
||
| /** | ||
| * @brief An interface for providing styling information for vector features. | ||
| */ | ||
| class CESIUMVECTOROVERLAYS_API VectorStylingProvider { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a unit test for this, to confirm that a simple style can be successfully applied? |
||
| public: | ||
| /** | ||
| * @brief Styles a set of point features. | ||
| * | ||
| * @param asyncSystem The async system. | ||
| * @param model The glTF model containing the features and metadata | ||
| * information. | ||
| * @param featureIds The feature IDs of the points to style. | ||
| * @param points The geometry of the points to style. This will be the same | ||
| * size as `featureIds`, and each point corresponds to the feature ID at the | ||
| * same index. | ||
| * @returns A future that resolves to a vector of optional VectorStyle | ||
| * objects, one for each point feature. The vector should be the same size as | ||
| * `featureIds and `points`. If `std::nullopt` is provided for a feature, the | ||
| * feature will use the default style. If the returned vector is empty or does | ||
| * not match the size of `featureIds` and `points`, the default style will be | ||
| * used for all features. | ||
| */ | ||
| virtual CesiumAsync::Future< | ||
| std::vector<std::optional<CesiumVectorData::VectorStyle>>> | ||
| onStylePoints( | ||
| const CesiumAsync::AsyncSystem& asyncSystem, | ||
| const CesiumGltf::Model& model, | ||
| const std::vector<int64_t>& featureIds, | ||
| const std::vector<CesiumGeospatial::Cartographic>& points) = 0; | ||
|
|
||
| /** | ||
| * @brief Styles a set of polyline features. | ||
| * | ||
| * @param asyncSystem The async system. | ||
| * @param model The glTF model containing the features and metadata | ||
| * information. | ||
| * @param featureIds The feature IDs of the polylines to style. | ||
| * @param polylines The geometry of the polylines to style. This will be the | ||
| * same size as `featureIds`, and each polyline corresponds to the feature ID | ||
| * at the same index. | ||
| * @returns A future that resolves to a vector of optional VectorStyle | ||
| * objects, one for each polyline feature. The vector should be the same size | ||
| * as `featureIds` and `polylines`. If `std::nullopt` is provided for a | ||
| * feature, the feature will use the default style. If the returned vector is | ||
| * empty or does not match the size of `featureIds` and `polylines`, the | ||
| * default style will be used for all features. | ||
| */ | ||
| virtual CesiumAsync::Future< | ||
| std::vector<std::optional<CesiumVectorData::VectorStyle>>> | ||
| onStylePolylines( | ||
| const CesiumAsync::AsyncSystem& asyncSystem, | ||
| const CesiumGltf::Model& model, | ||
| const std::vector<int64_t>& featureIds, | ||
| const std::vector<std::vector<CesiumGeospatial::Cartographic>>& | ||
| polylines) = 0; | ||
|
|
||
| /** | ||
| * @brief Styles a set of polygon features. | ||
| * | ||
| * @param asyncSystem The async system. | ||
| * @param model The glTF model containing the features and metadata | ||
| * information. | ||
| * @param featureIds The feature IDs of the polygons to style. | ||
| * @param polygons The geometry of the polygons to style. This will be the | ||
| * same size as `featureIds`, and each polygon corresponds to the feature ID | ||
| * at the same index. | ||
| * @returns A future that resolves to a vector of optional VectorStyle | ||
| * objects, one for each polygon feature. The vector should be the same size | ||
| * as `featureIds` and `polygons`. If `std::nullopt` is provided for a | ||
| * feature, the feature will use the default style. If the returned vector is | ||
| * empty or does not match the size of `featureIds` and `polygons`, the | ||
| * default style will be used for all features. | ||
| */ | ||
| virtual CesiumAsync::Future< | ||
| std::vector<std::optional<CesiumVectorData::VectorStyle>>> | ||
| onStylePolygons( | ||
| const CesiumAsync::AsyncSystem& asyncSystem, | ||
| const CesiumGltf::Model& model, | ||
| const std::vector<int64_t>& featureIds, | ||
| const std::vector<std::vector<CesiumGeospatial::Cartographic>>& | ||
| polygons) = 0; | ||
| }; | ||
|
|
||
| } // namespace CesiumVectorOverlays | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, it seems like
styles.size()must equalpoints.size(), wherestyle[i]is applied topoints[i]. Perhaps we should call it out here.