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

Fix dynamically added props not appearing in queryRenderedFeatures results #10102

Closed
wants to merge 2 commits into from
Closed

Fix dynamically added props not appearing in queryRenderedFeatures results #10102

wants to merge 2 commits into from

Conversation

osvodef
Copy link
Contributor

@osvodef osvodef commented Nov 14, 2020

Bug description

Optional layout and paint properties don't appear in queryRenderedFeatures results if they're set after layer creation.

JSFiddle

https://jsfiddle.net/osvodef/f45dapvu/10/
This sets a text-opacity property to a label and then queries it.

Solution

Like in #10074, the bug occurs because of serialized layers caching. I modified evaluateProperties so that it iterates over styleLayer._transitionablePaint._values and styleLayer._unevaluatedLayout._values objects instead of the outdated serialized layout and paint objects.

Launch Checklist

  • briefly describe the changes in this PR
  • manually test the debug page
  • write tests for all new functionality

@osvodef osvodef marked this pull request as ready for review November 14, 2020 13:12
@CLAassistant
Copy link

CLAassistant commented Dec 8, 2020

CLA assistant check
All committers have signed the CLA.

Copy link
Contributor

@ryanhamley ryanhamley left a comment

Choose a reason for hiding this comment

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

Thanks for finding this bug and putting together a PR @osvodef. As written, this does not actually fix the issue. The query test you've added is passing incidentally because the line color defaults to black. If you try changing the line color, you can see that the query test doesn't update properly. Additionally, if you set up a debug page with the same code as your JSBin, you'll see that the output is 1, not 0.5.

The crux of the issue seems to be that you're evaluating the property from styleLayerProperties which doesn't have the updated style property added to it. Once we get this fixed and have a working query test, I'd like to run benchmarks on this as well. This area of the code base is sensitive to changes, performance-wise as you can see in the original PR that implements it (#9198).

I also noted that we should pass in the CanonicalTileID to the evaluation of the feature property which was never updated after the canonical argument was added. Let me know if you have questions on the way forward.

Comment on lines +219 to +220
serializedLayer.paint = evaluateProperties(styleLayer._transitionablePaint, styleLayer.paint, feature, featureState, availableImages);
serializedLayer.layout = evaluateProperties(styleLayer._unevaluatedLayout, styleLayer.layout, feature, featureState, availableImages);
Copy link
Contributor

Choose a reason for hiding this comment

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

Here's where we can pass in the CanonicalTileID by doing (styleLayer._transitionablePaint, styleLayer.paint, feature, featureState, this.tileID.canonical, availableImages).

const prop = styleLayerProperties instanceof PossiblyEvaluated ? styleLayerProperties.get(key) : null;
return prop && prop.evaluate ? prop.evaluate(feature, featureState, availableImages) : prop;
});
const value = prop && prop.evaluate ? prop.evaluate(feature, featureState, availableImages) : prop;
Copy link
Contributor

Choose a reason for hiding this comment

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

This needs to be updated or it won't evaluate properly down the line because the property evaluation method takes the arguments (feature, featureState, canonical, availableImage). You can pass the CanonicalTileID into this function above.

evaluate(feature: Feature, featureState: FeatureState, canonical?: CanonicalTileID, availableImages?: Array<string>): T {
return this.property.evaluate(this.value, this.parameters, feature, featureState, canonical, availableImages);
}

@ryanhamley
Copy link
Contributor

Since there hasn't been any movement on this in a long time, I've created a ticket for the bug #11584 and we're going to close this PR. Thanks for reporting the issue. If you decide to finish the PR, let us know and we can reopen it.

@ryanhamley ryanhamley closed this Mar 10, 2022
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