Hi Team,
I have been trying to display the thumbnail for the portail Item.
Portal Item has a thumbnail field, it says Loadable Image but when i try to load() its, its says failure and also its has image parameter which is bitmap is null
They do have an URI path, but its not constructed in a way we can use it. refer the below url.
https://bhp.maps.arcgis.com/home/group.html?id=ac8ee9b9c61d49e895a7413774488c34&view=list#content/sh...
I heard from one of the stories about constructing the url. I tried that too..
Url constructed: https://bhp.maps.arcgis.com/sharing/rest/content/items/7210eda2e3fb46dbb38351821b0b84b5/info/thumbna...
https://bhp.maps.arcgis.com/sharing/rest/content/items/7210eda2e3fb46dbb38351821b0b84b5/info/thumbna...?token=<Auth-token>
Its says invalid token.
So unable to get the thumbnail. Is there something i am missing.
Need your help in this regard.
Hi @DeepamPalaniswami , assuming you have the proper privileges to load the PortalItem, you should be able to then load the item's thumbnail. Can you kindly confirm that you have loaded the PortalItem before attempting to load the PortalItem's thumbnail?
For example:
/**
* Loads portal items from [getListOfMaps].
*/
private suspend fun loadPortalItems() {
for (map in getListOfMaps()) {
val portalItem = PortalItem(map)
// load the actual portalItem
portalItem.load()
// load its thumbnail
portalItem.thumbnail?.load()
_portalItems.add(portalItem)
}
}
Hi @SorenRoth
Thanks for your reply. I will explain the steps which i follow it. Based on your comments, I am not sure about the list of maps.
val portalQueryParameters =
PortalQueryParameters(query = getString(R.string.group_id))
val groups = portal.findGroups(portalQueryParameters)
3. Find the portal items using
val portalGroupContentSearchParameters =
PortalGroupContentSearchParameters.query("")
val items =
groupResult?.get(0)?.findItems(portalGroupContentSearchParameters)
4. outcome of the step 3, I get the list of portal Items.
5. If i try to portalItem. load() , its says
Failure(com.arcgismaps.exceptions.JsonException: message=JSON parser invalid start of JSON., additionalMessage=� : 0, errorCode=6004)
6. If i try portalItem.thumbnail.load(), it says
Failure(com.arcgismaps.exceptions.MappingException: message=Invalid request response., additionalMessage=, errorCode=7003)
I can see the title, last updated date etc. I could not able to load the file and also not able to get the map size info.
Need your help on confirming my flow and also help me out If i am doing anything wrong.
Hello,
What is the PortalItemType of the item you would like to load? I suggest using the items method rather than the query method to find and load your items so that you can be certain the items you are getting are of the type you are interested in. I suspect you are getting a broad range of items and that the first one in the list is not something that can be loaded.
Please see the Portal group content search documentation and the search syntax documentation. An example query to find items of type Web Map would be
(+type:\"Web Map\" -type:\"Web Mapping Application\")
however, using the items method will provide the same constraint on the search by specifying PortalItemType.WebMap.
HI @SorenRoth
Portal Item type I am trying to load is
PortalItemType.MobileMapPackage
I tried with Items and also Query, I am getting the Group content Title, Last update time. it seems fine. Except thumbnail image and file size of the map.
Size of the portal item return -1, which indicates error happened as per arcGIS documentation.
refer the below code snippet.
lifecycleScope.launch {
portal.load().onSuccess {
// Search for the group based on id.
val portalQueryParameters =
PortalQueryParameters(query = getString(R.string.group_id))
val groups = portal.findGroups(portalQueryParameters)
if (groups.isSuccess) {
val groupResult = groups.getOrNull()?.results
if (groupResult?.isEmpty() == true) return@launch
// fetch the Group content info of type PortalItemType.MobileMapPackage
val typeList = arrayListOf<PortalItemType>(PortalItemType.MobileMapPackage)
val portalGroupContentSearchParameters =
PortalGroupContentSearchParameters.items(typeList)
// TODO: I have referred index 0 as there is only one group
// I have subscribed to, so currently set with index 0. Ignore at the moment.
val items =
groupResult?.get(0)?.findItems(portalGroupContentSearchParameters)
if (items?.isSuccess == true) {
val portalItems = items.getOrNull()?.results ?: emptyList()
if (portalItems.isNotEmpty()) {
portalItems.forEach {portalItem ->
portalItem.thumbnail?.load()?.onSuccess {
println("Thumbnail image : " + portalItem.thumbnail?.image)
}?.onFailure {
it.printStackTrace()
}
}
}
}
} else {
displayToast("No items for this Group")
}
}.onFailure { throwable ->
// authentication failed, display error message
displayToast(getString(R.string.server_unavailable_please_try_again))
}
}
I am able to get the content of the group such as title, description, last updated , created time etc.,
Unable to get the thumbnail image and also the size of the map.
In your code snippet above, you need to first load the PortalItem, then load the PortalItem.thumbnail.
if (portalItems.isNotEmpty()) {
portalItems.forEach {portalItem ->
portalItem.load() // FIRST LOAD PORTALITEM HERE
portalItem.thumbnail?.load()?.onSuccess {
println("Thumbnail image : " + portalItem.thumbnail?.image)
}?.onFailure {
it.printStackTrace()
}
}
}
portalItem.load() throws an exception.
Failure(com.arcgismaps.exceptions.JsonException: message=JSON parser invalid start of JSON., additionalMessage=� : 0, errorCode=6004)
I found a workaround creating the instance of portal item with the url.
val portalItem = PortalItem("https://www.arcgis.com/home/item.html?id="+ portalItem.itemId)
I can call load(), its successful and also able to fetch the thumbnail image too.
Just wondering why the previous way is throwing an error?