When users use your app, they are using it to retrieve information by specifying some criteria or clicking on the map/scene, and then expecting some kind of result that either provides them with the information they asked for, or lets them know that nothing was found. In this chapter, we're going to turn our attention to retrieving information from the layers we've been using so that our users can quickly and easily get information out of the app. In particular, we're going to discuss the options available in ArcGIS Runtime that allow us to find, query, and identify features in a FeatureLayer
resource. We're also going to discuss the difference between Find
, Query
, and Identify
, how tasks are relevant to this discussion, and how to implement these tasks following the MVVM pattern. We will also discuss the following topics:
Everything you will be using in this chapter will be related to the .NET concept of tasks. Tasks were introduced in .NET Framework 4 and have greatly simplified the process of writing asynchronous applications, which makes your apps more responsive and non-blocking. A user can enter some search parameter, such as a name, press a button or hit the Enter key, and then the operation will do its work in such a manner that it doesn't prevent the user from continuing to work on other parts of the app. ArcGIS Runtime's capabilities are heavily based on this pattern, so it's important that you have a good understanding of how to execute code using this pattern.
In this chapter, we're going to explore Esri.ArcGISRuntime.Tasks
. This namespace has many classes in it, but for now we're going to just focus on the ones relevant to the topic of this chapter. In later chapters, we'll return to this namespace because the pattern of using tasks is so prevalent when using ArcGIS Runtime. In Esri.ArcGISRuntime.Tasks
, you'll find the following classes:
The TaskBase
class is a base class that has two properties: ServiceUri
and Token
. The FindTask
, QueryTask
and IdentifyTask
constructors inherit from TaskBase
. To use these tasks, we will generally follow this pattern:
FeatureService
or FeatureLayer
.ExecuteAsync
, and then do something with the results, such as show the user a list, generate a new geometry, and then display it as a graphic, and send the results to another ViewModel as part of the input to another tool.