Extracting URL from createWorldImagery and other imagery provider helper functions

To be clear this is a question not a bug

1. A concise explanation of the problem you’re experiencing.

Extract the url (and session tokens if necessary) from:

createWorldImagery({ style: IonWorldImageryStyle.AERIAL })

``

``

And other imagery creation provider functions (ArcGisMapServerImageryProvider, WebMapServiceImageryProvider, etc…).

2. A minimal code example. If you’ve found a bug, this helps us reproduce and repair it.

createWorldImagery({ style: IonWorldImageryStyle.AERIAL })

``

3. Context. Why do you need to do this? We might know a better way to accomplish your goal.

We’re saving the user’s base maps using a structure like the one below.

{
“category”: “Cesium ion”,
“creationFunction”: “createWorldImagery({ style: IonWorldImageryStyle.AERIAL })”,
“display”: true,
“iconUrl”: “buildModuleUrl(“Widgets/Images/ImageryProviders/bingAerial.png”)”,
“name”: “Bing Maps Aerial”,
“tooltip”: “Bing Maps aerial imagery, provided by Cesium ion”
},

``

We
have some entries in that point to our servers as well as the default ones Cesium provides (specifically the Bing ones). However, due to various network and server reliablity issues sometime the various servers are unavailable or unreachable. As such we’re trying to implement some code that will get the URLs and if needed the session tokens and ‘ping’ the servers.

However, where we’re hitting a brick wall is getting the URL out of the creation functions. Of course we could add the base URL of the server to the structure above but it’s not ideal as we’ll have to update 2 urls.

4. The Cesium version you’re using, your operating system and browser.

Cesium: 1.53.0

Browser: Chrome 72.0.3626.121

OS: Windows 10

The createWorldImagery creates an IonImageryProvider, which has a requestImage function. It’s a bit of a hack, but you could wrap this function in your own custom function and extract the URL from the request this way:

// Blue Marble Next Generation July, 2004 imagery from NASA

var provider = new Cesium.IonImageryProvider({ assetId: 3845 });

var viewer = new Cesium.Viewer(‘cesiumContainer’, {

imageryProvider: provider

});

var oldReq = provider.requestImage;

provider.requestImage = function(x, y, level, request){

setTimeout(function(){

console.log(request.url);

}, 1000);

return oldReq.call(provider, x, y, level, request);

};

``

Tested this code in Sandcastle. I add the timeout because it looks like the request.url is only populated after the function is called.

I had some vague notation that something like this might be possible but wanted to avoid it at all cost :P.

But even with the ability to get the raw URL using this method, which is a questionable at best, some of these imagery providers have built in session tokens in their headers like Sentinel-2 which makes a request to https://assets.cesium.com/3954/2/2/1.jpg.

The URL above I got by using they function you posted and will return:

{“code”:“InvalidCredentials”,“message”:“Invalid access token”}

``

And the request object doesn’t seem to contain the access token anywhere:

request.png

Token:

To be completely honest the imagery providers that require tokens I may just ignore but for a complete solution I would be nice to be able to deal with all imagery providers rather than hacking around a hack lol.

PS: Unrelated… but your previous work is certainly impressive :).