using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using ESRI.ArcGIS.Client;
using ESRI.ArcGIS.Client.Tasks;
namespace 查询
{
public partial class MainPage : UserControl
{
public MainPage()
{
InitializeComponent();
}
private void ExecuteButton_Click(object sender, RoutedEventArgs e)
{
GraphicsLayer graphicsLayer = MyMap.Layers["MyGraphicsLayer"] as GraphicsLayer;
graphicsLayer.Graphics.Clear();
FindTask findTask = new FindTask("http://localhost/ArcGIS/rest/services/Map/AnHui/MapServer");
findTask.Failed += FindTask_Failed;
FindParameters findParameters = new FindParameters();
// Layer ids to search
findParameters.LayerIds.AddRange(new int[] { 0, 1, 2, 3 });
// Fields in layers to search
findParameters.SearchFields.AddRange(new string[] { "Name "});
// Return features in map's spatial reference
findParameters.SpatialReference = MyMap.SpatialReference;
// Bind data grid to find results. Bind to the LastResult property which returns a list
// of FindResult instances. When LastResult is updated, the ItemsSource property on the
// will update.
Binding resultFeaturesBinding = new Binding("LastResult");
resultFeaturesBinding.Source = findTask;
FindDetailsDataGrid.SetBinding(DataGrid.ItemsSourceProperty, resultFeaturesBinding);
findParameters.SearchText = FindText.Text;
findTask.ExecuteAsync(findParameters);
// Since binding to DataGrid, handling the ExecuteComplete event is not necessary.
}
private void FindDetails_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
// Highlight the graphic feature associated with the selected row
DataGrid dataGrid = sender as DataGrid;
int selectedIndex = dataGrid.SelectedIndex;
if (selectedIndex > -1)
{
FindResult findResult = (FindResult)FindDetailsDataGrid.SelectedItem;
Graphic graphic = findResult.Feature;
switch (graphic.Attributes["SHAPE"].ToString())
{
case "Polygon":
graphic.Symbol = LayoutRoot.Resources["DefaultFillSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol;
break;
case "Polyline":
graphic.Symbol = LayoutRoot.Resources["DefaultLineSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol;
break;
case "Point":
graphic.Symbol = LayoutRoot.Resources["DefaultMarkerSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol;
break;
}
GraphicsLayer graphicsLayer = MyMap.Layers["MyGraphicsLayer"] as GraphicsLayer;
graphicsLayer.Graphics.Clear();
graphicsLayer.Graphics.Add(graphic);
}
}
private void FindTask_Failed(object sender, TaskFailedEventArgs args)
{
MessageBox.Show("Find failed: " + args.Error);
}
}
}