Is there a way to get a list of Cesium Ion assets for display in a popup on a Cesium application? Minimally, I need the asset ID and name so when users select an item in the list it can be displayed on the globe. We've searched the API and other sources and have been unable to find any discussion of this. Thank you.
There does exist an ion API, but it’s not documented yet. I’m not sure what the exact route would be for this, but I’m bumped this issue here which has some more info:
https://github.com/AnalyticalGraphicsInc/cesium-ion-community/issues/29
Feel free to follow up there too.
Thank you, Omar. I actually had found that post the other day, but I’m not sure I understand how it addresses what we’re trying to do. We are currently creating a Cesium.Ion object with our access token. We can then display assets using Cesium.IonResource.fromAssetId() so long as we know the asset IDs.
The missing piece is this: How do we retrieve a list of available asset IDs and their associated asset names from Ion? We want to present this list to the user, who can then select which assets to show. We would use Cesium.IonResource.fromAssetId() to display the selected assets. The reason we want to do this is that users will be able to add assets to Ion, so we can’t hard code the IDs. The only other alternative I see is to create a tool for adding asset IDs and names to our database, which is doable but requires users to do double-entry when creating assets (once in Ion, once in our DB).
If there isn’t any available documentation, might there be a code snippet showing how to get the asset list, assuming it’s possible? Thank you again.
–Dale
What you need is:
How do we retrieve a list of available asset IDs and their associated asset names from Ion
This is exactly what the ion API would allow you to do (in addition to programmatically creating, deleting, or modifying assets). For example, I did some digging, and the route you want is:
This will give you a list of ion assets with some information on each one, for whatever access token is currently authenticate. Matt mentions several ways to authenticate via the thread linked in the GitHub issue there. One way is to add the token in the URL:
https://api.cesium.com/assets?access_token=
You can make this request from any application, not just CesiumJS/not just JavaScript, but in CesiumJS it would be:
Cesium.Resource.fetchJson(‘https://api.cesium.com/assets?access_token=’)
.then(function(result){
// result
is all available asset IDs and their names
console.log(result);
});
``
Hi Omar,
Ah, okay, that makes sense now. I’ll give it a try. Thank you!
–Dale
Hi Omar,
I am using https://api.cesium.com/assets?access_token=<your token here> API in my application and it works fine.
But today it stopped working. I am getting CORS Policy issue on API.
Access to XMLHttpRequest at 'https://api.cesium.com/assets?access_token=<access-token>' from origin 'http://localhost:38389' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
Can you please help on this?
Thanks
Rohit
I think this route might have been updated to https://api.cesium.com/v1/assets (you can see this when opening your ion dashboard).
Also, if you’re using the default ion token, it won’t have access to this route. You need to make sure your token has the “assets:list” scope. That way you can control exactly how much permission each token has. Let me know if that works for you.
Thanks Omar. There is an issue with api route, which has been changed now.
The ion REST API is officially out! Check it out, let me know if you have any feedback: