Skip to content

Allow custom styling for VectorTilesRasterOverlay. - #1430

Open
azrogers wants to merge 14 commits into
mainfrom
vector-overlay-styling
Open

Allow custom styling for VectorTilesRasterOverlay.#1430
azrogers wants to merge 14 commits into
mainfrom
vector-overlay-styling

Conversation

@azrogers

Copy link
Copy Markdown
Contributor

This PR allows the user to specify a VectorStylingProvider that will be called to obtian styling information for the primitives loaded by the VectorTilesRasterOverlay. This allows per-element styling with a great degree of flexibility.

@j9liu j9liu left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR @azrogers! I still have to try this out in Unreal, but I wanted to give the Native part a pass to get things moving.

Also remember to update CHANGES.md!

};
} // namespace CesiumVectorData

/** @brief Hash implementation for \ref CesiumVectorData::ColorStyle. */

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer @ref according to the style guide, and apply this to the other instances of \ref in this doc too.

Suggested change
/** @brief Hash implementation for \ref CesiumVectorData::ColorStyle. */
/** @brief Hash implementation for @ref CesiumVectorData::ColorStyle. */

* @brief Draws a set of points to the canvas.
*
* @param points The set of points to draw.
* @param style The @ref PointStyle to use when drawing the points.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @param style The @ref PointStyle to use when drawing the points.
* @param styles The @ref PointStyle instances to use when drawing the points.

Copy link
Copy Markdown
Collaborator

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 equal points.size(), where style[i] is applied to points[i]. Perhaps we should call it out here.

Comment on lines +399 to +413
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) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like there's some assumptions here:

  • styles.size() == points.size()
  • styles[i] != nullptr for all i
  • styles[i].point.hasValue()

We should add if statements to guard for these, or at least add asserts.

/**
* @brief An interface for providing styling information for vector features.
*/
class CESIUMVECTOROVERLAYS_API VectorStylingProvider {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The 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?

Comment on lines +165 to +168
const CesiumGltf::FeatureId* pFeatureIdSet =
pMeshFeatures != nullptr && !pMeshFeatures->featureIds.empty()
? &pMeshFeatures->featureIds[0]
: nullptr;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be simplified using model.getSafe.

});

return {pContent, errors};
// Apply per-element styling if the user specified a styling provider.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move this comment down after the if (!pStylingProvider) ?

Comment on lines +203 to +210
const CesiumUtility::Result<int64_t> featureIdResult =
getFeatureId(pFeatureIdSet, model, primitive, startIndex);
errors.merge(featureIdResult.errors);
polylineFeatureIds.emplace_back(
featureIdResult.value.value_or(-1));
pContent->polylines.emplace_back(std::move(polyline));
polyline.clear();
startIndex = -1;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wonder if there's a nice way to reorganize this so there aren't two polyline.size() >=2 checks... but doesn't have to be in scope for this PR.

for (const auto& style : result) {
if (style.has_value()) {
pContent->pointStyles.emplace_back(
&*pContent->uniqueStyles.insert(*style).first);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: For readability help? (Same with the others in the file)

Suggested change
&*pContent->uniqueStyles.insert(*style).first);
&(*pContent->uniqueStyles.insert(*style).first));

vectorizationResult) mutable {
if (vectorizationResult.errors.hasErrors()) {
if (vectorizationResult.value) {
delete *vectorizationResult.value;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see this was already in the code, but for the future -- would be good to use smart pointers instead or otherwise document any specific reasons for why we're not using them.

Comment on lines 821 to +824
if (!pVectorContent->points.empty()) {
rasterizer.drawPoints(
pVectorContent->points,
pVectorContent->style.point);
pVectorContent->pointStyles);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: why do points have their own multi-style override when polylines/polygons use for loops?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants