Query Query Task Silverlight with ESRI Maps
Where can i learn how to query the layers of an ESRI Map? I n开发者_Go百科eed to query the layer of esri maps and store the data in dictionary.
The ESRI Silverlight SDK provides a QueryTask
object for this. Your map must be published with ArcGIS Server providing a REST endpoint (URL) to query against. Check out the ESRI sample page. They include several examples of different styles of queries.
In its simplest form, a query will look like...
void DoQuery()
{
QueryTask queryTask = new QueryTask("[AGS Service Endpoint]"); // Service url typically in format of http://[servername]/ArcGIS/rest/services/[ServiceName]/MapServer/[LayerId]
queryTask.ExecuteCompleted += QueryTask_ExecuteCompleted;
ESRI.ArcGIS.Client.Tasks.Query query = new ESRI.ArcGIS.Client.Tasks.Query();
query.Where = "1=1"; // Return all features
query.OutFields.Add("*"); // Return all fields
queryTask.ExecuteAsync(query);
}
void QueryTask_ExecuteCompleted(object sender, ESRI.ArcGIS.Client.Tasks.QueryEventArgs args)
{
FeatureSet featureSet = args.FeatureSet;
if (featureSet == null || featureSet.Features.Count == 0) return;
foreach (Graphic feature in featureSet.Features)
{
// feature.Attributes is a type Dictionary<string, object> containing all attributes. Do something with it.
}
}
精彩评论