-
-
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 #4199
Conversation
This is ready for review. Let me know what needs to be changed |
Thanks again for the PR! |
For the tests I will need some help. Do we already have tests for |
Import script requires integration tests, so I wouldn't start with that. |
I've opened the following PR: |
* Alternative option * Improve agronomics, add test * Remove unwanted change
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4199 +/- ##
==========================================
- Coverage 87.85% 87.79% -0.07%
==========================================
Files 246 246
Lines 33372 33392 +20
Branches 2182 2183 +1
==========================================
- Hits 29318 29315 -3
- Misses 3064 3084 +20
- Partials 990 993 +3 ☔ View full report in Codecov by Sentry. |
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.
See my comments at:
wipfli#342
Seems like this feature needs a bit more work.
* Alternative option * Improve agronomics, add test * Remove unwanted change * Update browser.test.ts - fix test * Update land.json
The image is empty, I think it's a bug in chrome or headless chrome... not sure. Or you can toggle headless for image creation. |
@@ -8,6 +9,8 @@ export interface WorkerGlobalScopeInterface { | |||
registerRTLTextPlugin: (_: any) => void; | |||
addProtocol: (customProtocol: string, loadFn: AddProtocolAction) => void; | |||
removeProtocol: (customProtocol: string) => void; | |||
getFeaturePropertiesTransform: () => FeaturePropertiesTransform; |
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 think get is not needed anymore, right?
@@ -11,6 +11,8 @@ export class MessageBus implements WorkerGlobalScopeInterface, ActorTarget { | |||
registerRTLTextPlugin: any; | |||
addProtocol: any; | |||
removeProtocol: any; | |||
getFeaturePropertiesTransform: any; |
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.
Same here
Now you have a failing test that reproduces what I said :-) |
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 didn't know that you could send some script to be executed to a worker like this! I am intrigued.
Here it says that after using createObjectURL
, the URL needs to be cleaned up again with revokeObjectURL
to avoid a memory leak: https://developer.mozilla.org/en-US/docs/Web/API/URL/createObjectURL_static
Since the script is only executed once, I think MapLibre GL JS should take care of this cleanup after the script is executed.
Maybe importScriptInWorkers
can be updated to also take a function with (self: ServiceWorkerGlobalScope) => void
as prototype. This has the advantage that instead of writing the script as a string, you get type and syntax checking. Also, you don't need to repeat yourself to prepare the data URL and the cleanup can be handled automatically.
If a function is passed to importScriptInWorkers
, you would call toString()
, strip the resulting string to get the function body, and then use decodeURIComponent
, Blob
and URL.createObjectURL
internally.
Modify the MessageType.importScript
to pass along an optional boolean to indicate that revokeObjectURL
needs to be called on the worker side once the script has been executed.
The example is a way to inline everything into a single file for demo purposes, I would not advise to use |
Ah OK, I thought that was the recommended approach. Makes sense. 👍 |
The documentation for queryRenderedFeatures says that the result "contains the properties of its source feature": Line 1519 in a942081
Based on this I would suggest to add a note to the documentation of the setFeaturePropertiesTransform function that changes will not be reflected in queryRenderedFeatures. For tests I would suggest to write some render tests. What do you think? |
I think that you'll have a hard time creating render tests for this feature as render tests are mainly style driven and this feature "breaks" the style. Can you elaborate on the limitation of query render features? If this hook is creating a discrepancy between the rendered results and the returned value of the query it might confusing to users, wouldn't it? |
The functionality proposed in here seems to have a lot of overlap with feature-state. It is just global on all features and not on individual features. I will think a bit if there is a better api than what is proposed here... |
@wipfli is this still something you want to push forward? |
Thanks for the ping @HarelM. |
Yes, I believe the issue was around |
Closing in favor of #5370 |
Proof-of-concept implementation for #4198. The implantation is inspired the
addProtocol
implementation.Demo:
https://github.com/wipfli/maplibre-feature-properties-transform-example
Launch Checklist
CHANGELOG.md
under the## main
section.