简体   繁体   English

如何使用ArcGIS .net运行时SDK正确设置ExportTileCacheJob

[英]How to properly setup an ExportTileCacheJob using ArcGIS .net runtime sdk

I'm using the .Net runtime sdk (v.100) for Xamarin Android. 我正在为Xamarin Android使用.Net运行时sdk(v.100)。 I'm trying to download tiles as a .tpk for offline use by my mobile app. 我正在尝试将图块以.tpk格式下载,以供移动应用离线使用。

I've managed to use the AuthenticationManager to give me a token for my app. 我设法使用AuthenticationManager为我的应用程序提供了令牌。 I can successfully create the ExportTileCacheTask and create the ExportTileCacheJob by calling ExportTileCache on the ExportTileCacheTask, but the status of the job never seems to change. 我可以通过在ExportTileCacheTask上调用ExportTileCache来成功创建ExportTileCacheTask并创建ExportTileCacheJob,但是作业的状态似乎从未改变。 When I check the job status immediately after the call to ExportTileCache, it is "NotStarted" and the ServerId = "". 在调用ExportTileCache之后立即检查作业状态时,它是“ NotStarted”,并且ServerId =“”。 I have a breakpoint on my ExportJob_JobChanged handler and it never gets hit no matter how long I wait. 我的ExportJob_JobChanged处理程序上有一个断点,无论我等待多长时间,它都不会命中。

Any ideas? 有任何想法吗? Code below: 代码如下:

var serviceUri = new Uri("https://tiledbasemaps.arcgis.com/arcgis/rest/services/World_Imagery/MapServer");
var tokenUri = new Uri("https://www.arcgis.com/sharing/rest");
try
{
    var serverInfo = new ServerInfo
    {
        ServerUri = tokenUri,
        TokenAuthenticationType = TokenAuthenticationType.OAuthClientCredentials,
        OAuthClientInfo = new OAuthClientInfo { ClientId = MYCLIENTID, ClientSecret = MYCLIENTSECRET) },
    };
    AuthenticationManager.Current.RegisterServer(serverInfo);

    var cred = await AuthenticationManager.Current.GenerateCredentialAsync(tokenUri, new GenerateTokenOptions { });

    var exportTask = await ExportTileCacheTask.CreateAsync(serviceUri, cred);


    var exportParams = await exportTask.CreateDefaultExportTileCacheParametersAsync(aoi, 50000, 10000);

    job = exportTask.ExportTileCache(exportParams, localFilePath);
    job.JobChanged += ExportJob_JobChanged;
}
catch (Exception e)
{
    e.ToString();
}

Apparently the tooltip documentation on ExportTileCache is misleading. 显然,有关ExportTileCache的工具提示文档具有误导性。 It does not, in fact, Start and return an ExportTileCacheJob. 实际上,它不会启动并返回ExportTileCacheJob。 You must call Start() on the job to start it. 您必须在作业上调用Start()才能启动它。

I finally found java documentation of the class that mentioned this. 我终于找到了提到该类的java文档。 https://developers.arcgis.com/android/latest/api-reference/reference/com/esri/arcgisruntime/tasks/tilecache/ExportTileCacheJob.html https://developers.arcgis.com/android/latest/api-reference/reference/com/esri/arcgisruntime/tasks/tilecache/ExportTileCacheJob.html

After calling Start(), the JobChanged events fired as expected and I was able to successfully download a .tpk file. 调用Start()之后,JobChanged事件按预期触发,并且我能够成功下载.tpk文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM