Select to view content in your preferred language

How to supply account info when building offline map

761
2
08-21-2017 11:26 AM
EricDUCOS1
Occasional Contributor

Hi,

This part of code is what I have written based on the "Create an offline map" Guide:

            Map theMap = new Map(new Uri(_configService.ServerConfiguration.SigMapUrl));
            OfflineMapTask task = await OfflineMapTask.CreateAsync(theMap);
           
            Envelope areaOfInterest = theMap.Item.Extent;
            GenerateOfflineMapParameters parameters = await task.CreateDefaultGenerateOfflineMapParametersAsync(areaOfInterest);
            parameters.MaxScale = 3000;
            OfflineMapCapabilities results1 = await task.GetOfflineMapCapabilitiesAsync(parameters);
            DependencyService.Get<IFileService>().CreateLocalDBFolder(App.CurrentConfigName);
            string pathToOutputPackage = DependencyService.Get<IFileService>().CreateLocalDBFolder(App.CurrentConfigName+"/Sig");
            DependencyService.Get<IFileService>().EmptyFolder(pathToOutputPackage);
            GenerateOfflineMapJob job = task.GenerateOfflineMap(parameters, pathToOutputPackage);
            GenerateOfflineMapResult results2 = await job.GetResultAsync();
When I run this part of code, a dialog opens in middle of the process that asks to me to give login and password to get acces to tiled basemap.
What sort of code should I add to avoid this dialog opening and to give these information (login and password)  hard-coded in code ?
And I have a second question, concerning this part of code. Downloading the tiles from the server can be a long operation. Is there some ways to have a sort of progress event to give some UI progress on interface (% of downloading for exemple) ?
Regards.
Tags (1)
0 Kudos
2 Replies
NagmaYasmin
Esri Contributor

Hi Eric,

Suppose, you are trying to access the tile layer, "https://tiledbasemaps.arcgis.com/arcgis/rest/services/World_Street_Map/MapServer"
and it will  ask the AGOL credential to access. You could access the layer using AuthenticationManager and hardcode the credentials as below:

using Esri.ArcGISRuntime.Security;

string ONLINE_BASEMAP_URL = "https://tiledbasemaps.arcgis.com/arcgis/rest/services/World_Street_Map/MapServer";
string ONLINE_BASEMAP_TOKEN_URL = "https://www.arcgis.com/sharing/rest/generatetoken";

ArcGISTiledLayer tiledLayer = new ArcGISTiledLayer(new Uri(ONLINE_BASEMAP_URL));
AuthenticationManager auth = AuthenticationManager.Current;
var cred = await auth.GenerateCredentialAsync(new Uri(ONLINE_BASEMAP_TOKEN_URL), <AGOL_USERNAME>, <AGOL_PASSWORD>);

tiledLayer.Credential = cred;

Hope that helps.

Nagma

0 Kudos
AnttiKajanus1
Deactivated User

Have a look into https://community.esri.com/message/700103-re-downloading-map-from-portal-for-offline-use?commentID=7... 

Note that you have to use AuthenticationManager to hook the authentication and providing credentials directly won't work. We do this because there might be multiple domains involved in the task so we cannot send one set of credentials around.

It shows how to hook the progress indication as well.