Why getPreplannedMapAreasAsync returns empty List?

697
8
Jump to solution
07-17-2022 03:13 AM
ShawnKleese
New Contributor II

Hello Everybody,

i'am struggeling arround with Preplanned offline Maps and need some help.

The Problem:

offlinemaptask.getPreplannedMapAreasAsync returns a Empty UnmodifiableList.

What i have Done before:

  • I have created a new Map in the Arcgis Gallery (I tried OSM and Street as Basemaps) and 
  • Added a Offline Map Rectangle to the Map
  • ShawnKleese_0-1658052622043.png
  • Added the Permission to the API Key to use this Item
  • ShawnKleese_1-1658052721829.png

     

Environment/License:

I used the Free Developer Tier. I Have also in the same app the MapView and it worked - So Credentials and API Key is Ok.

 

Code Snippet:

 

ArcGISRuntimeEnvironment.setInstallDirectory(arcgisInstallFolder);
ArcGISRuntimeEnvironment.setApiKey(arcgisApiKey);
AuthenticationManager.setAuthenticationChallengeHandler(new DefaultAuthenticationChallengeHandler());

Credential cred = new UserCredential("username", "password");
portal = new Portal("https://www.arcgis.com/");
portal.setCredential(cred);
portalItem = new PortalItem(portal, "2098a0d8b#Cleaned#74b67bf3");

OfflineMapTask offlineMapTask = new OfflineMapTask(portalItem);

ListenableFuture<List<PreplannedMapArea>> future = offlineMapTask.getPreplannedMapAreasAsync();

future.addDoneListener(() -> {


try {
    List<PreplannedMapArea> preplannedMaps = future.get(); // <---- preplannedMaps  is EMPTY :-((((

   
} catch (InterruptedException | ExecutionException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
} );

 

 

The Question:

What can be the Reason why the Preplanned Maps are empty ?

0 Kudos
1 Solution

Accepted Solutions
Nicholas-Furness
Esri Regular Contributor

Hi @ShawnKleese,

I have a theory about what's going on.

Can you comment out your line of code that sets the global API Key on the ArcGISRuntimeEnvironment please and try that?

Here's what I think is happening:

  • Preplanned map areas are stored as hidden portal items that are related to the web map portal item (there's an area item for each preplanned map area, and each area item itself has related package items, all hidden).
  • The API Key might have access to the web map, but we don't yet automatically extend the API Key access to these related portal items.
  • By setting the global API Key on line 2, any Runtime object that doesn't have an explicit credential set will default to using that global API Key and bypass the authentication manager flow. I think that your OfflineTask can see the web map item, but cannot read the related area items to enumerate them.

We need to update our API Key scoping logic to include these related area and package items when scoping an API Key for a web map.

In the meantime you could do a couple of things:

  1. Do not set the API Key globally, but set it on each Runtime object that needs it.
  2. Explicitly set your credential (from line 5 in your code) on your OfflineMapTask with setCredential(). You should then be able to enumerate the preplanned areas. You will probably also need to set it on the DownloadPreplannedOfflineMapJob that you create from the OfflineMapTask

Let us know if that helps.

If not, you should create a test web map that is entirely public and we can investigate further from there.

View solution in original post

0 Kudos
8 Replies
MarkBaird
Esri Regular Contributor

A quick answer as it's a Sunday...  there is a working sample app on gitHub could take a look at.  It does pretty much the same as you are trying to do.

If that doesn't help then let me know and I'll take a closer look at your code on Monday.

Mark

0 Kudos
ShawnKleese
New Contributor II

Hey Mark,

thank you for your Sunday-Attention 🙂

Yes, i know this example and i have study it and all Documentions i found for the Offlinemaps-Topic. 

I have tried to fix my code for a few hours, but there are no PreplannedMaps found.

 

 

 

0 Kudos
ShawnKleese
New Contributor II

So i have started the Example-App with my License and my PortalItem/Map but i have the same Behavior - no PreplannedMaps Found: 

ShawnKleese_0-1658087081299.png

 

So Something is maybe not corrctly configured in the Arcgis-Backend?

But i have added the Offline Area:

ShawnKleese_1-1658087356587.png

 

Maybe you have tommorow some Idea...

 

0 Kudos
MarkBaird
Esri Regular Contributor

Swapping out your service into our sample app shows there is likely to be a config issue on the server side as you have suggested.  At least it shows that your original code was probably okay.

Configuring ArcGIS Online services isn't something I do very often so I'm going to ask someone who knows this area better to see if they have any thoughts.

0 Kudos
MarkBaird
Esri Regular Contributor

Okay thinking about this more (and having discussed it with someone else too), I'm wondering if you issue is around authenticating against your webmap.  The webmap we are using in the sample is a public one so doesn't require any authentication to get you accessing it.  

I'm wondering if you are able to open your web map and display it at all?  

There is a sample which shows how to display a webmap from a portal item here.  If security is the issue , then you can take a look at these samples which might help.

Let me know how you get on with this

0 Kudos
ShawnKleese
New Contributor II

Hello Mark,

thank you for your investigations. Security is'nt the problem.  The Map is displayed in the sample App and also my app. I've added the Credentials just for hopping, that this might be the problem...

So in my opinon the Problem is in the Configuration of my Arcgis Offline Map Areas ( But this is very simple and not a big deal) and the other possibility is that there is a Bug somewhere?

0 Kudos
Nicholas-Furness
Esri Regular Contributor

Hi @ShawnKleese,

I have a theory about what's going on.

Can you comment out your line of code that sets the global API Key on the ArcGISRuntimeEnvironment please and try that?

Here's what I think is happening:

  • Preplanned map areas are stored as hidden portal items that are related to the web map portal item (there's an area item for each preplanned map area, and each area item itself has related package items, all hidden).
  • The API Key might have access to the web map, but we don't yet automatically extend the API Key access to these related portal items.
  • By setting the global API Key on line 2, any Runtime object that doesn't have an explicit credential set will default to using that global API Key and bypass the authentication manager flow. I think that your OfflineTask can see the web map item, but cannot read the related area items to enumerate them.

We need to update our API Key scoping logic to include these related area and package items when scoping an API Key for a web map.

In the meantime you could do a couple of things:

  1. Do not set the API Key globally, but set it on each Runtime object that needs it.
  2. Explicitly set your credential (from line 5 in your code) on your OfflineMapTask with setCredential(). You should then be able to enumerate the preplanned areas. You will probably also need to set it on the DownloadPreplannedOfflineMapJob that you create from the OfflineMapTask

Let us know if that helps.

If not, you should create a test web map that is entirely public and we can investigate further from there.

0 Kudos
ShawnKleese
New Contributor II

Hello Nicholas,

yes! You are absolutly right! After removing the Api Key and using just Credentials The ExampleApp and my App work!

But i think it would be great if it just works with the Api-Key.

Thank you for your Solution!

 

 

0 Kudos