-
-
Notifications
You must be signed in to change notification settings - Fork 754
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
Add Feature Properties Transform #5343
Conversation
* Alternative option * Improve agronomics, add test * Remove unwanted change
* Alternative option * Improve agronomics, add test * Remove unwanted change * Update browser.test.ts - fix test * Update land.json
Thank you for taking this up @neodescis! I don't know if we need a getFeaturePropertiesTransform actually since the user always sets it. Regarding raw tile data I am not sure, but I would do the least amount of work for normal operations, and do some extra work if needed if someone calls queryRenderedFeatures. |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #5343 +/- ##
==========================================
- Coverage 91.84% 91.83% -0.02%
==========================================
Files 282 283 +1
Lines 38908 38955 +47
Branches 6827 6836 +9
==========================================
+ Hits 35735 35773 +38
- Misses 3046 3054 +8
- Partials 127 128 +1 ☔ View full report in Codecov by Sentry. |
I left the getter in for symmetry, but I can take it out if that's what's wanted. As for queryRenderedFeatures, I believe this updating of rawTileData needs to be done up-front, since the data needs to make its way back to the main thread (ultimately into the FeatureIndex), and queryRenderedFeatures is synchronous. |
// If any features were transformed, re-encode to rawTileData to override the original | ||
let transformedRawData: ArrayBuffer = null; | ||
if (Object.keys(transformedFeatures).length) { | ||
const transformedTile: VectorTile = { |
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.
This is a bit funky, but the VectorTile classes don't allow you to modify some of their data directly. Instead, this is overriding the layer's function that retrieves its features to get the transformed ones instead, so vtpbf can process using the updated data.
I've spent some time investigating geometry overrides, and I don't think the effort is worth it:
|
On the other hand, I've also looked at how this works with |
@@ -99,6 +109,24 @@ export class WorkerTile { | |||
for (let index = 0; index < sourceLayer.length; index++) { | |||
const feature = sourceLayer.feature(index); | |||
const id = featureIndex.getId(feature, sourceLayerId); | |||
if (WorkerTile.featurePropertiesTransform) { | |||
const {geometry} = feature.toGeoJSON(this.tileID.canonical.x, this.tileID.canonical.y, this.tileID.canonical.z); |
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.
I believe the z here should be canonical and not the overscaled value, since this is used to convert the MVT geometry to GeoJSON. Is that correct?
@HarelM, I have tests working now. The example also works, but is maybe a little complex since it encompasses a GeoJSON source and vector tiles? Also, I'm not sure exactly how to document this API, since it's only available in the worker thread. |
I'll review this in the coming days thoroughly. |
Currently the "rawTileData" is shipped back to the main thread, and it is passed into the FeatureIndex there to be used by queryRenderedFeatures. The raw data is read every time queryRenderedFeatures is called. You can see this in So, if we want to transform features AND have queryRenderedFeatures return them as they have been transformed, the raw data needs to be updated. Now, I fully recognize that, from a design perspective, we may not actually want to handle things this way. If we think that |
Well, I went down the So, my recommendation would be to create an example that does this using |
I still think it would be great to have an example of addProtocol in a worker if we don't have such an example yet, but yes, addProtocol is very powerful. |
Closing this in favor of #5370 |
This is a furtherance of @wipfli's #4199, with the aim to solve #4198.
Things I've done since the original:
vtpbf
after feature transforms to ship it back to the main thread. By doing this,queryRenderedFeatures()
now works as expected.queryRenderedFeatures()
call, and also to transform a feature from a GeoJSON source.Launch Checklist
CHANGELOG.md
under the## main
section.