-
-
Notifications
You must be signed in to change notification settings - Fork 760
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
Support custom tiles source #30
Conversation
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 am not too sure either way if this is a good approach or not, but just a minor code cleanup suggestion.
I'd like some time to look over this before we consider it, esp since @HarelM can't test directly (thanks for contributing this @HarelM btw!!!), at the very least, this is probably something we should save for "v1.15". v1.13: full compat |
I'll do the requested changes later on, haven't got to it yet. |
I have not dug too deep, but it seems a bit weird to introduce a magical |
Good point. I'll see what I can do about it. |
Thanks for the review! I've pushed changes according it. |
Recent tests shows that the above code is not working as expected since the |
SharedArrayBuffer might be the answer, but... Spectre / Meltdown 😞 |
If we can't access the list of registered custom schemes here, could we instead check that it's a scheme not handled by if (requestParameters.url.match(/^(\w+):/) &&
!requestParameters.url.match(/^(about|blob|data|file|ftp|https?):/)
) {
// Use custom handler
} else {
// Current logic to use fetch or XMLHttpRequest
} |
@HarelM , it looks like the config is accesible from the worker, but the property Possible reasons I can think of:
So lucky number 3. Broadcast Channel API would be great to solve this, but it's not supported by Safari. Workers/Actors code region is a bit obscure to me in order to inject some messaging logic to pass the variables 😞 |
I'm guessing sending a function is probably not a good idea, however sending only the keys to allow knowing there's a function in the main thread context is the way to go, IMO. |
I've been testing that very approach and no change to config, even adding a plain string, is propagated to the workers. They only see the default values. Even using the original getters and setters to set up API_URL or the token... is not propagated to the workers. I have no idea how on earth they consume those params. Maybe this PR can shed some light on how can we deal with this issue, and, double combo, get rid of custom Mapbox code |
I don't think the config is the right approach for the reasons you mentioned in your comment. |
Have you checked out |
I'm also using a custom source "maphub:" which I load using |
@hyperknot I haven't. If you can share a working example, or something that almost works just to get the idea it would be great. If this is already implemented and there's no need to do anything it would be great :-) |
@hyperknot - this doesn't seem to be a valid solution for reading a tile that is locally stored in a sqlite or indexdb database. |
I don't know the internal details of Cordova, etc. but are you saying that a fetch wouldn't work from an url like object (like file:// or whatever)? If so then indeed transformRequest wouldn't work. |
I see. So I guess `transformRequest won't work for my needs. You can think of the following scenario which is not related to Cordova. A user clicks on "Make map available offline" button. In that moment downloading of tiles begin and are stored in indexdb (or wherever). When this operation is finished the user should be able to see the map in the browser without network connectivity. Since running fetch for any url won't help there's a need to be able to inject mapbox-gl with the actual data, stored in IndexDb in this case, so a function to support this is needed. |
I have a fully working version, should I open a new PR? |
I looked at the code and I think you can send a PR to my repository and I can merge it, but I think more work is needed here to remove the "file or http" assumption... |
There're not much in this PR honestly, a small change to the ajax.js handling for custom protocols. |
My 2 cents: I maintain a fork to implement a very similar feature, but using an async transformRequest as mentioned in this thread above. The downside of the that approach is it's not specific; transformRequest will be called for all HTTP requests, including not only tiles but TileJSON, sprites, and glyph ranges. Also, not all the contexts in which transformRequest is used are asynchronous: example in the code, so implementing it that way would require refactoring a lot more internals. I tested out this PR by implementing an adapter for PMTiles archives, a COG-like format which fetches raster or vector tiles from a single file via HTTP Range requests. Here is the code of my implementation. You can run this by putting the file in the debug/ directory of your branch checkout. Demo of how it works: protocol.mp4Comments
} else {
callback(new Error(`Tile fetch error: ${t.statusText}`));
} One new condition introduced by protocols is the possibility of missing tiles. For example, if you are fetching tiles from LocalStorage, there might not exist any Tile for a given Z/X/Y, but this is not an error state that should be propagated to the console or other parts of the code. In my implementation I pass an empty array on line 83 for this case, but I'm not sure if this will behave correctly in all cases. ConclusionOverall I think this PR is great and minimal, and in my case would discourage me from maintaining a separate fork for the functionality I need, even though the developer ergonomics aren't perfect. It is difficult to predict what protocols others are going to implement, and a more full-fledged API could be evolved from the common pain points shared among Protocols. I think there's some aversion to merging a new feature like this because of the implications of backward compatibility later - maybe it would a good precedent to mark 👍 |
It feels right to me 🙂 We are getting closer to get this functionality onboard! 🎉 Regarding @bdon comments, I think the (minimal) working example I posted at #30 (comment) manages all the bullet points you mentioned 🤓 . Regarding the need of |
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.
The renaming (mapboxgl to maplibregl) is a bit noisy in this PR, maybe this should be done in a separate PR?
Otherwise LGTM
If the typescript definition is updated in main I can merge and resolve the conflicts to allow the PR to be less noisy. |
I like this implementation, but I agree with @bdon that it should be noted that it's experimental and subject to change for a few iterations. @bdon We could suggest replacing something like |
I'm good with everything you decide, just let me know... |
Since |
Looks like merging #172 has tagged this PR as Once this is fixed, is there any way to help it move forward and be approved? |
I'm planning to fix this tonight unless you @AbelVM want to do it first (I.e. Merge main to branch and resolve conflicts). |
I've reduced the "noise" last night as requested by @Joxit. |
Thank you for your changes! 😁 |
Hi, @snickell , any chance to green-light this PR soon? 😅 |
Added link to issue and item in the changelog
Increment rc candidate number
Thanks @HarelM! I think we can just make a note in the documentation that it's subject to change, but it's also so simple I think it may not really matter. |
This PR should facilitate for feature request describe here: Support custom source #29
I've added documentation above the function itself, I don't know how to convert this to proper documentation.
Any help would be appreciated.
As a side note, since I'm using a patch version of mapbox-gl-js I will only be able to help testing (for example current rc) only after this is merged... Sorry...
I would prefer to have all the breaking changes (mainly name changes etc) as soon as possible since I prefer to work in order to migrate to this library only after the breaking changes had occurred to make sure that everything is working once and I won't need to do it in two steps (first only to migrate to this library and the second to make sure I fix things that were broken assuming I want to upgrade to a later version, which I probably will).
This is of-course only my point of view and needs...