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

Add Feature Properties Transform #4199

Closed
wants to merge 15 commits into from

Conversation

wipfli
Copy link
Contributor

@wipfli wipfli commented May 29, 2024

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

  • Confirm your changes do not include backports from Mapbox projects (unless with compliant license) - if you are not sure about this, please ask!
  • Briefly describe the changes in this PR.
  • Link to related issues.
  • Include before/after visuals or gifs if this PR includes visual changes.
  • Write tests for all new functionality.
  • Document any changes to public APIs.
  • Post benchmark scores.
  • Add an entry to CHANGELOG.md under the ## main section.

@wipfli wipfli marked this pull request as draft May 29, 2024 13:02
@wipfli wipfli marked this pull request as ready for review June 17, 2024 06:51
@wipfli
Copy link
Contributor Author

wipfli commented Jun 17, 2024

This is ready for review. Let me know what needs to be changed

src/source/protocol_crud.ts Outdated Show resolved Hide resolved
src/source/worker.ts Outdated Show resolved Hide resolved
src/source/worker_tile.ts Outdated Show resolved Hide resolved
src/util/config.ts Outdated Show resolved Hide resolved
src/util/config.ts Outdated Show resolved Hide resolved
@HarelM
Copy link
Collaborator

HarelM commented Jun 17, 2024

Thanks again for the PR!
Can you please resolve conflicts and also create some tests and an example page of how to use this feature?

@wipfli
Copy link
Contributor Author

wipfli commented Jun 28, 2024

For the tests I will need some help. Do we already have tests for maplibregl.importScriptInWorker()?

@HarelM
Copy link
Collaborator

HarelM commented Jun 28, 2024

Import script requires integration tests, so I wouldn't start with that.
Try unit testing the worker and the tile parser by mocking and spying a lot if the stuff.
Also, don't forget the changelog entry.

@HarelM
Copy link
Collaborator

HarelM commented Jul 1, 2024

I've opened the following PR:
wipfli#341
Hope it helps...

* Alternative option

* Improve agronomics, add test

* Remove unwanted change
@codecov-commenter
Copy link

codecov-commenter commented Jul 2, 2024

Codecov Report

Attention: Patch coverage is 85.00000% with 3 lines in your changes missing coverage. Please review.

Project coverage is 87.79%. Comparing base (b8cb683) to head (2b2d199).
Report is 578 commits behind head on main.

Files with missing lines Patch % Lines
src/source/worker.ts 40.00% 2 Missing and 1 partial ⚠️
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.
📢 Have feedback on the report? Share it here.

Copy link
Collaborator

@HarelM HarelM left a 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.

HarelM and others added 4 commits July 9, 2024 17:27
* Alternative option

* Improve agronomics, add test

* Remove unwanted change

* Update browser.test.ts - fix test

* Update land.json
@HarelM
Copy link
Collaborator

HarelM commented Jul 10, 2024

The image is empty, I think it's a bug in chrome or headless chrome... not sure.
I think the following arguments may help:
/~https://github.com/maplibre/maplibre-gl-js/pull/4299/files

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;
Copy link
Collaborator

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;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same here

@HarelM
Copy link
Collaborator

HarelM commented Jul 10, 2024

Now you have a failing test that reproduces what I said :-)

Copy link
Collaborator

@louwers louwers left a 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.

@HarelM
Copy link
Collaborator

HarelM commented Jul 11, 2024

The example is a way to inline everything into a single file for demo purposes, I would not advise to use createObjectURL in production, but instead use a javascript file stored next to the code or even on a CDN. This file can be created using the regular typescript tooling to support type check and everithing.
I wouldn't like to complicate the import script interface for this edge case.
This is also outside the scope of this PR I believe.

@louwers
Copy link
Collaborator

louwers commented Jul 11, 2024

Ah OK, I thought that was the recommended approach. Makes sense. 👍

@wipfli
Copy link
Contributor Author

wipfli commented Jul 30, 2024

The documentation for queryRenderedFeatures says that the result "contains the properties of its source feature":

* The `properties` value of each returned feature object contains the properties of its source feature. For GeoJSON sources, only

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?

@HarelM
Copy link
Collaborator

HarelM commented Jul 30, 2024

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.
Browser integration tests are enough.

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?

@wipfli
Copy link
Contributor Author

wipfli commented Aug 27, 2024

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...

@HarelM
Copy link
Collaborator

HarelM commented Nov 26, 2024

@wipfli is this still something you want to push forward?
Are any breaking changes needed while we are at version 5 pre-release for this feature?

@wipfli
Copy link
Contributor Author

wipfli commented Nov 28, 2024

Thanks for the ping @HarelM.
I think this would be a nice feature but I have not been thinking about it for a while. The main open question was the result from queryRenderedFeatures right?
Regarding v5, this pull request should not lead to breaking changes so it can come after

@HarelM
Copy link
Collaborator

HarelM commented Nov 28, 2024

Yes, I believe the issue was around queryRenderedFeatures.
Thanks for the update.

@neodescis
Copy link
Collaborator

Closing in favor of #5370

@neodescis neodescis closed this Jan 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants