Want to obtain a job to generate and download a vector tile package and its default style resources by passing the (ExportVectorTilesParameters) to the (ExportVectorTiles) method on the (ExportVectorTilesTask) class. That must also provide a download path to store the vector tile package and its default style resources.
But when I run the (ExportVectorTilesJob) to export and download the vector tile package (.vtpk), it ends up no where.
How can I check and handle the job status that where my job is residing, and what went wrong.
Following is the code I am using to export the vector tiles:
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.Start();
CodePudding user response:
You need to wait for the job to complete. It takes the server a little while to generate the data, and then for the runtime to download it. The simplest way is to just await the result:
var result = await exportVectorTilesJob.GetResultAsync();
(If you do this you don't actually need to explicitly start the job) You can also listen for the JobChanged, ProgressChanged and check the Status property to understand how the job is running and provide progress feedback to the user.
CodePudding user response:
You achieve this by using the following code, just add the below code , before your last line, which can handle job status change and check the status for you.
// Handle job status change to check the status.
exportVectorTilesJob.JobChanged = async (sender, args) =>
{
// Show job status and progress.
Console.WriteLine($"Job status: {exportVectorTilesJob.Status}, progress: {exportVectorTilesJob.Progress}%");
// When the job succeeds, display the local vector tiles.
if (exportVectorTilesJob.Status == JobStatus.Succeeded)
{
// Get the result from the job.
ExportVectorTilesResult result = await exportVectorTilesJob.GetResultAsync();
// Create a vector tile cache from the result.
VectorTileCache vectorCache = result.VectorTileCache;
// Create new vector tiled layer using the tile cache.
ArcGISVectorTiledLayer localVectorTileLayer = new ArcGISVectorTiledLayer(vectorCache);
// Display the layer as a basemap.
MyMapView.Map = new Map(new Basemap(localVectorTileLayer));
}
};