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

Resource transforms: alter URLs before requesting #4740

Closed
kkaefer opened this issue May 23, 2017 · 8 comments
Closed

Resource transforms: alter URLs before requesting #4740

kkaefer opened this issue May 23, 2017 · 8 comments
Assignees
Labels
feature 🍏 GL native → GL JS For feature parity with Mapbox Maps SDK on a native platform good first issue

Comments

@kkaefer
Copy link
Contributor

kkaefer commented May 23, 2017

In Native, we have added "Resource transforms", which allows you to supply a function that is called every time a URL is requested. That function can perform arbitrary operations on the URL string, and the returned URL will be requested. We should implement this in GL JS for API parity.

@kkaefer kkaefer added feature 🍏 GL native → GL JS For feature parity with Mapbox Maps SDK on a native platform good first issue high priority labels May 23, 2017
@asheemmamoowala asheemmamoowala self-assigned this May 26, 2017
@Scarysize
Copy link

Will this feature make it possible to have relative URLs for certain properties in the map style JSON? E.g.:

{
  ...
  "spritesheet": "my/local/spritesheet"
}

A callback could resolve this relative url and return an absolute one.

@asheemmamoowala
Copy link
Contributor

asheemmamoowala commented May 30, 2017

@Scarysize - the changes proposed in #4763 do not allow pure relative URLs in the style.json.
Instead, you can provide a custom protocol and resolve that in the transform callback:

{
...
"sprite": "app-local://my/local/spritesheet"
}

@Scarysize
Copy link

That was my intention. Thanks for confirming that 🙌

@volkergraf
Copy link

Will this kinda make the following Possible:

To load "local"-Tiles like

"sources": {
                "openmaptiles": {
                    "type": "vector",
                    "tiles":  [location.href + "/../germany/{z}/{x}/{y}.pbf" ],
                    "name": "OpenMapTiles",
                    "format": "pbf",
                    "basename": "germany.mbtiles",

on iOS, I have to transform the FileURL from e.g. location.href + "/../germany/14/1111/{2222.pbf"
to the corresponding blob-id (blob:file:///c415dbb6-3d57-4354-83c0-a33c0b6ddb4f) on iOs using the function window.resolveLocalFileSystemURL provided by the cordova-plugin-file-Plugin.

Thanx for any Help

@asheemmamoowala
Copy link
Contributor

@volkergraf I believe you are asking for #4917.

#5021 will allow transforming the URL as you've mentioned above. Not being familiar with Cordova, I do not know if a blob url from Cordova, returned from window.resolveLocalFuleSystemURL, can be retrieved using an XMLHttpRequest.

@volkergraf
Copy link

@asheemmamoowala Well THIS I can definively can confirm (using the cordova-file-plugin and the local-URl-Fix).. to test it I created such an URL form an Object like

./germany/14/8601/5648.pbf -> blob:file:///55e863d2-00d0-4712-b7ad-ab2792505e14

"sources": {
                "openmaptiles": {
                    "type": "vector",
                    "tiles":  [**"blob:file:///55e863d2-00d0-4712-b7ad-ab2792505e14"** ],

And I see the tile .. but well everywhere =) .. but at least I see that it's beeing loaded =)

@Yermo
Copy link

Yermo commented Jul 24, 2017

@asheemmamoowala I do not believe this addresses my use case as there are significant limits on the size of blobs and they differ based on browser and version.

Stackoverflow - Max Blog Size

Cordova provides an SQLLite plugin that allows you to query sqlite databases directly which is how I have implemented my local mbtiles support that I mention in #5021

Having a mechanism to pass the buck back to the main thread where a user supplied object can handle the request and return the data is the approach I have chosen for my implementation in :
Resource Loader Fork

Take a look at

resourceLoader.js

I've replaced every call to ajax.js with calls to my resourceLoader. If the requested resources is a remote resource, it forwards the request to ajax.js business as usual. If, however, the requested resources has a scheme of file:// it forwards the request back to the main thread where a user supplied object handles it and then returns the result. This approach requires minimal changes to the code but opens up the possibility for feeding arbitrary local sources of data into the mapping API programmatically. Also, in my use case, I modify the local mbtiles file depending on what the user wants to download. (Consider the case of downloading minimal detail maps of individual US states for use when one is offline. In my app, users will spend significant time without connectivity.)

It's currently an ugly hack, but it works like a champ and at least on my iPhone 6 I don't notice any performance degradation yet, but I am still in the proof of concept phase.

Separately, using the blob approach, I'm not sure how one would distribute the blob with a Cordova app?

@asheemmamoowala
Copy link
Contributor

Fixed in #5021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature 🍏 GL native → GL JS For feature parity with Mapbox Maps SDK on a native platform good first issue
Projects
None yet
Development

No branches or pull requests

5 participants