Skip to content
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

Feature reactive Cesium3DTileStyle.style object #7573

Merged

Conversation

bkuster
Copy link
Contributor

@bkuster bkuster commented Feb 15, 2019

This closes #7567.

Recap

The .style property was set on creation of Cesium3DTileStyle and no longer evaluated.

New Implementation

The .style property now reacts to property changes on the Cesium3DTileStyle. This allows cloning or serializing of a style, even after it has been updated.

@cesium-concierge
Copy link

Thanks for the pull request @bkuster!

  • ✔️ Signed CLA found.

Reviewers, don't forget to make sure that:

  • Cesium Viewer works.
  • Works in 2D/CV.
  • Works (or fails gracefully) in IE11.

@lilleyse
Copy link
Contributor

Thanks @bkuster, I'll look at this soon.

@cesium-concierge
Copy link

Thanks again for your contribution @bkuster!

No one has commented on this pull request in 30 days. Maintainers, can you review, merge or close to keep things tidy?

I'm going to re-bump this in 30 days. If you'd like me to stop, just comment with @cesium-concierge stop. If you want me to start again, just delete the comment.

@hpinkos
Copy link
Contributor

hpinkos commented Mar 18, 2019

@lilleyse will you have time to review this soon?

@@ -159,16 +159,29 @@ define([
that._ready = true;
}

function getExpression(tileStyle, value) {
function getExpression(tileStyle, value, key) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe it would be better to separate getting the expression from setting the json. One idea:

function getJsonFromExpression(expression) {
    if (defined(value.expression)) {
        return value.expression;
    } else if (defined(value.conditionsExpression)) {
        return clone(value.conditionsExpression, true);
    }
    return expression;
}
set : function(value) {
    this._show = getExpression(this, value);
    this._style.show = getJsonFromExpression(this._show);
}

A couple things to handle are:

  • this._style would need to be initialized to an empty object
  • What happens if the expression is a custom expression? Should that be added to the json as is? Or should getJsonFromExpression return undefined in that case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the feedback @lilleyse. True, abusing getExpression in this fashion is not very intuitive, I like your proposal and will implement something along those lines.

  1. this._style initialization in the constructor makes sense to me, but this would change a non-experimental API, as the default value for .style would not longer be undefined but Object, or would you still return undefined in the getter, if the Object is empty?
  2. Haven't thought of custom expressions tbh. Both approaches (undefined or the expression instance) have their uses. You cant serialize the expression, but you could use it to clone the style at runtime. I would lean toward an implementation that is closest to the current behavior, I'll have to checkout what that is first, but would assume it to be undefined?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed my mind on 2.. Behavior as is now adds the custom expression passed in the options to style, this should remain unchanged. Added some specs to outline the behavior.

@bkuster
Copy link
Contributor Author

bkuster commented Mar 26, 2019

This is ready for a second review.

@lilleyse
Copy link
Contributor

Thanks @bkuster, this all looks good to me. My simple test checks out:

var viewer = new Cesium.Viewer('cesiumContainer');

var tileset = new Cesium.Cesium3DTileset({
    url: '../../SampleData/Cesium3DTiles/PointCloud/PointCloudWithPerPointProperties/tileset.json'
});
viewer.scene.primitives.add(tileset);
viewer.zoomTo(tileset, new Cesium.HeadingPitchRange(0.0, -1.0, 50.0));

var style = new Cesium.Cesium3DTileStyle({
    color : "color('#ff0000')"
});

tileset.style = style;

console.log(style.style);

style.color = "color('#ffff00')";

console.log(style.style);

And the breaking change is minimal enough to not worry about deprecating first.

@lilleyse lilleyse merged commit 46cdb02 into CesiumGS:master Mar 30, 2019
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.

Cesium3DTileStyle.style is not reactive
4 participants