Tasks and jobs

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();

视频资料

转载于:https://www.cnblogs.com/tom110/p/8564727.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值