-
-
Notifications
You must be signed in to change notification settings - Fork 767
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
Allow addProtocol
in the worker code
#3459
Conversation
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main #3459 +/- ##
=======================================
Coverage 74.74% 74.74%
=======================================
Files 242 243 +1
Lines 19146 19154 +8
Branches 4240 4239 -1
=======================================
+ Hits 14311 14317 +6
- Misses 4835 4837 +2 ☔ View full report in Codecov by Sentry. |
Interesting... at first glance this seems to make sense for the maplibre contour plugin since the entire thing (fetch DEM tile, calculate contours, encode vector tile) could happen inside a worker which would eliminate the need for it to manage it's own worker. But I'd also like for it to be able to share a DEM tile cache with raster-DEM source which happens back in the main thread, and to be able to use other protocols defined by plugins the user is using (ie. load raster DEM tiles from pmtiles). What do you think the best way to accomplish those 2 goals would be? Also this approach requires you to know the internals of maplibre to know whether you need to inject a plugin into the main or worker thread (my diagram helps but it means we may break plugins if the fetch is moved between main/worker thread. I wonder if there's an approach where you can add a plugin that works no matter where the fetch happens? Either by requiring plugins provide both a worker and main thread implementation, or if the user just provides a worker or main thread implementation then maplibre falls back to sending a request to where the protocol is implemented? |
To overcome this limitation, I think I can think of a way to register the worker to Regarding shared tiles, this is a different story and I'm not sure this is related to this PR, we also have the same issue with the terrain and hillshding - i.e. you have to use different sources so that things are not colliding (tile fetch aborting etc). I'm not sure I have an easy solution for this... |
Passing a actor to the |
I had the following idea:
This way it is up to the developers to properly test everything and make sure it's working as expected instead of trying to solve everything for them. I'll change this PR so you can take a look at it. |
I think that makes more sense. Seems like from a users perspective they just want to say |
I guess a guide about how to write a plugin that uses these abilities would create a common plugins look and feel, hopefully. Generally speaking I'm not sure what API a plugin should implement, so I'm not sure how to define this API. Thanks again for the input! |
@birkskyum @neodescis can you guys approve this? |
This allows adding a protocol in the worker thread by exposing an addProtocol method in the workers code and allowing to import a code into the workers.
One issue I noticed is that the
raster
source is not using the worker thread at all since all it does it fetch an image and convert it to pixels, so there's not much work in the works anyway, which means that if you add a protocol in the worker thread but use a raster source it won't be called.This means that the developer needs to know where to add the method, which is OK, as the default is in the main thread and only if you'd like to optimize things you can move it to the worker thread.
The rest is the same.
I've also removed the import of the script when adding a source type, so that importing a script has only one entry point.
cc: @bdon, @msbarry
Launch Checklist
CHANGELOG.md
under the## main
section.