Tasks and jobs
Tasks
引用服务Task
// Create a new LocatorTask from a geocode service endpoint
var locatorUri = new Uri("http://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer");
LocatorTask onlineLocator = new LocatorTask(locatorUri);
// If the address text box is not empty, run the geocode task
if (!string.IsNullOrEmpty(FromAddressTextBox.Text.Trim()))
{
// Pass the address to the GeocodeAsync method and get the results
IReadOnlyList<GeocodeResult> matches = await onlineLocator.GeocodeAsync(FromAddressTextBox.Text);
// Get the first match (one with the highest score)
GeocodeResult bestMatch = matches[0];
// Use geometry and attributes from the match (and a symbol created earlier) to create a new graphic
Graphic fromGraphic = new Graphic(bestMatch.DisplayLocation, bestMatch.Attributes, fromPointSymbol);
// Add the graphic to an existing graphics overlay in the map view
MyMapView.GraphicsOverlays[0].Graphics.Add(fromGraphic);
}
定义Task参数
// get the default route parameters
var routeParams = await routeTask.CreateDefaultParametersAsync();
// explicitly set values for some parameters
routeParams.ReturnDirections = true;
routeParams.ReturnRoutes = true;
routeParams.OutputSpatialReference = MyMapView.SpatialReference;
// solve the route with these parameters
RouteResult routeTaskResult = await routeTask.SolveRouteAsync(routeParams);
// ... work with results ...
新建Task参数
GeocodeParameters geocodeParams = new GeocodeParameters();
geocodeParams.CountryCode = "France";
geocodeParams.MaxResults = 5;
在线和离线服务
// Create a new LocatorTask from a geocode service endpoint
var locatorUri = new Uri("http://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer");
LocatorTask onlineLocator = new LocatorTask(locatorUri);
// Create an offline locator from a local .loc file - coverage will depend on the packaged locator dataset...
LocatorTask offlineLocator = new LocatorTask(localLocatorUri);
// Mobile map packages can also contain locators - use this to get a reference to an offline locator...
MobileMapPackage mmpk = await MobileMapPackage.OpenAsync(localMmpkPath);
LocatorTask mmpkLocator = mmpk.LocatorTask;
Tasks and jobs
// Function to submit a geodatabase synchronization job
// URL for the feature service and the path to the local geodatabase are passed in
public async Task SyncronizeEditsAsync(string serviceUrl, string geodatabasePath)
{
// create a sync task with the URL of the feature service to sync
var syncTask = await GeodatabaseSyncTask.CreateAsync(new Uri(serviceUrl));
// create sync parameters
var taskParameters = new SyncGeodatabaseParameters()
{
RollbackOnFailure = true,
GeodatabaseSyncDirection = SyncDirection.Bidirectional
};
// open the local geodatabase
var gdb = await Esri.ArcGISRuntime.Data.Geodatabase.OpenAsync(geodatabasePath);
// create a synchronize geodatabase job, pass in the parameters and the geodatabase
SyncGeodatabaseJob job = syncTask.SyncGeodatabase(taskParameters, gdb);
// handle the JobChanged event for the job
job.JobChanged += (s, e) =>
{
// report changes in the job status
if (job.Status == Esri.ArcGISRuntime.Tasks.JobStatus.Succeeded)
{
// report success ...
statusMessage = "Synchronization is complete!";
}
else if (job.Status == Esri.ArcGISRuntime.Tasks.JobStatus.Failed)
{
// report failure ...
statusMessage = job.Error.Message;
}
else
{
statusMessage = "Sync in progress ...";
}
};
// await the completion of the job
var result = await job.GetResultAsync();
}
Report job progress
// Execute a task to return the Job
GenerateOfflineMapJob job = task.GenerateOfflineMap(parameters, packagePath);
// Hook into the ProgressChanged event to track the current progress
job.ProgressChanged += (s, e) =>
{
// Note: The event might be raised in a background thread.
// Make sure updates to UI elements are pushed to the UI thread.
Dispatcher.Invoke(() =>
{
// Update a UI element to show the updated progress value (percent complete)
PercentageLabel.Text = "Operation is %" + job.Progress.ToString() + " complete ...";
});
};
// Run the job and await the results asynchronously
GenerateOfflineMapResult results = await job.GetResultAsync();
视频资料