.NET平台导出矢量瓦片时ExportVectorTilesJob无输出如何排查处理
导出矢量瓦片任务状态检查与问题排查方案
1. 任务状态监听与结果获取
你当前的代码仅启动了导出任务,未监听任务运行状态、结果与错误信息,无法判断任务是仍在运行、运行失败还是已完成,这是找不到生成文件的核心原因。你可以通过两种方式获取任务状态:
方式1:通过事件监听任务全生命周期
Uri vectorTileLayerUri = vectorTiledLayer.Source; exportVectorTileTask = await ExportVectorTilesTask.CreateAsync(vectorTileLayerUri); ExportVectorTilesParameters exportVectorTileParams = await exportVectorTileTask.CreateDefaultExportVectorTilesParametersAsync( areaOfInterest: MyMapView.VisibleArea, maxScale: MyMapView.MapScale); string myDocumentsFolder = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); string tileCachePath = System.IO.Path.Combine(myDocumentsFolder, "VectorMapTiles.vtpk"); ExportVectorTilesJob exportVectorTilesJob = exportVectorTileTask.ExportVectorTiles(exportVectorTileParams, tileCachePath); // 监听任务进度变化 exportVectorTilesJob.ProgressChanged += (s, e) => { Console.WriteLine($"当前导出进度:{exportVectorTilesJob.Progress}%"); }; // 监听任务完成事件 exportVectorTilesJob.JobCompleted += (s, e) => { if (exportVectorTilesJob.Status == Esri.ArcGISRuntime.Tasks.JobStatus.Succeeded) { Console.WriteLine($"导出成功,文件存储路径:{tileCachePath}"); // 校验文件是否存在 if(File.Exists(tileCachePath)) { Console.WriteLine($"文件已生成,大小:{new FileInfo(tileCachePath).Length / 1024}KB"); } } else if (exportVectorTilesJob.Status == Esri.ArcGISRuntime.Tasks.JobStatus.Failed) { // 打印错误信息直接定位问题 Console.WriteLine($"导出失败,错误信息:{exportVectorTilesJob.Error?.Message}"); if(exportVectorTilesJob.Error?.InnerException != null) { Console.WriteLine($"内部错误详情:{exportVectorTilesJob.Error.InnerException.Message}"); } } }; exportVectorTilesJob.Start();
方式2:直接异步等待任务返回结果
exportVectorTilesJob.Start(); try { // 等待任务运行完成,会自动抛出运行过程中的异常 var result = await exportVectorTilesJob.GetResultAsync(); Console.WriteLine($"导出成功,vtpk文件路径:{result.VectorTileCache.Path}"); } catch (Exception ex) { Console.WriteLine($"导出失败:{ex.Message}"); }
如果你需要同步导出矢量瓦片的默认样式资源,需要调用
ExportVectorTiles的三参数重载,额外传入样式资源的存储目录路径即可,不需要额外修改其他参数:string styleResourcePath = System.IO.Path.Combine(myDocumentsFolder, "VectorTileStyle"); ExportVectorTilesJob exportVectorTilesJob = exportVectorTileTask.ExportVectorTiles(exportVectorTileParams, tileCachePath, styleResourcePath);
2. 常见问题排查点
- 路径权限问题:确认当前应用拥有你指定的
MyDocuments目录读写权限,部分沙箱环境(如UWP、移动端的系统公共目录)无法直接访问,建议替换为应用专属的私有沙箱存储路径测试。 - 参数合法性问题:检查
areaOfInterest是否为有效几何范围、目标矢量瓦片服务是否开放了导出权限、服务支持的比例尺范围是否包含你传入的maxScale,如果请求参数超出服务能力会直接导致任务失败。 - 任务未完成提前检查:导出矢量瓦片是异步任务,导出范围大、层级多的情况下需要较长运行时间,不要在调用
Start()方法后立刻检查文件,此时任务仍在运行,文件尚未生成。 - 文件覆盖问题:如果目标路径已经存在同名的
VectorMapTiles.vtpk文件,且该文件被其他进程占用、或应用没有覆盖权限,也会导致任务失败。
内容的提问来源于stack exchange,提问作者user17152018
相关产品推荐
相关产品推荐

