使用ESRI Maps查询查询任务Silverlight

时间:2010-08-03 07:46:14

标签: silverlight maps esri

在哪里可以学习如何查询ESRI地图的图层?我需要查询esri地图层并将数据存储在字典中。

1 个答案:

答案 0 :(得分:4)

ESRI Silverlight SDK为此提供了QueryTask对象。您的地图必须与ArcGIS Server一起发布,提供要查询的REST端点(URL)。查看ESRI sample page。它们包括几个不同样式的查询示例。

在最简单的形式中,查询看起来像......

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.
    }
}