上一节我们建立了一个Viewer for Silverlight的空工具,并且让它能够在我们配置的Viewer框架中调用,接下来我们就讲述怎么在这个工具中调用WCF服务。
首先完善一下QueryToolWindow,让它能够查询发出的服务图层的数据,并能将数据在Viewer生成的应用程序中显示出来。
关键代码为:
public partial class QueryToolWindow : UserControl
{
QueryTool QueryTool = null;
QueryTask QueryTask = null;
GraphicsLayer RainPointLayer = null;
public QueryToolWindow(QueryTool queryTool)
{
this.QueryTool = queryTool;
InitializeComponent();
this.Loaded += new RoutedEventHandler(QueryToolWindow_Loaded);
}
void QueryToolWindow_Loaded(object sender, RoutedEventArgs e)
{
this.QueryTask = new QueryTask(this.QueryTool.LayersDic["Point"]);
this.QueryTask.Failed += new EventHandler<TaskFailedEventArgs>(QueryTask_Failed);
this.QueryTask.ExecuteCompleted += new EventHandler<QueryEventArgs>(QueryTask_ExecuteCompleted);
Query query = new Query()
{
Where = "1=1",
ReturnGeometry = true,
OutFields = new OutFields() { "ID" },
OutSpatialReference = MapApplication.Current.Map.SpatialReference
};
this.QueryTask.ExecuteAsync(query);
}
void QueryTask_ExecuteCompleted(object sender, QueryEventArgs e)
{
GraphicsLayer layer = new GraphicsLayer();
layer.Renderer = new Sim