silverlight查询功能

<UserControl x:Class="查询.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:slData="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data"
    xmlns:esri="http://schemas.esri.com/arcgis/client/2009"
    mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="400">

    <Grid x:Name="LayoutRoot" Background="White">
        <Grid.Resources>
            <esri:SimpleMarkerSymbol x:Key="DefaultMarkerSymbol" Size="8" Color="Red" Style="Circle" />
            <esri:SimpleLineSymbol x:Key="DefaultLineSymbol" Color="Red" Width="6"  />
            <esri:SimpleFillSymbol x:Key="DefaultFillSymbol" BorderBrush="Red" BorderThickness="2" Fill="#50FF0000"/>
        </Grid.Resources>

        <Grid.RowDefinitions>
            <RowDefinition Height="*" />
            <RowDefinition Height="150" />
        </Grid.RowDefinitions>

        <esri:Map x:Name="MyMap" Grid.Row="0" WrapAround="True">
            <esri:ArcGISDynamicMapServiceLayer ID="TopoLayer" 
                    Url="http://localhost/ArcGIS/rest/services/Map/AnHui/MapServer"/>
            <esri:FeatureLayer ID="point"
                Url="http://localhost/ArcGIS/rest/services/Map/AnHui/MapServer/1"/>
            <esri:GraphicsLayer ID="MyGraphicsLayer" />
        </esri:Map>
        <Border BorderBrush="Black" Grid.Row="0" CornerRadius="5" BorderThickness="1" Height="35" MinWidth="550" HorizontalAlignment="Center" VerticalAlignment="Top"
                Background="#77919191" Margin="10">
            <Border.Effect>
                <DropShadowEffect ShadowDepth="1" />
            </Border.Effect>
            <Grid MinWidth="550">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="Auto" />
                </Grid.ColumnDefinitions>
                <TextBlock Text="Search for" Foreground="White" Grid.Column="0"
                           HorizontalAlignment="Center" Height="24" VerticalAlignment="Center" 
                           FontWeight="Bold" FontSize="12" Margin="20,8,5,0"/>
                <TextBox x:Name="FindText" Background="White" Text="合肥" Height="23" Width="100" HorizontalContentAlignment="Center" Grid.Column="1" />
                <TextBlock Text="in the attributes of States, Rivers, or Cities:" Foreground="White"  Grid.Column="2"
                           HorizontalAlignment="Center" Height="24" VerticalAlignment="Center" 
                           FontWeight="Bold" FontSize="12" Margin="5,8,5,0"/>
                <Button x:Name="ExecuteButton" Content="Find" Width="75" Height="24" VerticalAlignment="Center" Click="ExecuteButton_Click"  
                        Margin="5,0,5,0" Cursor="Hand"  Grid.Column="3" />
            </Grid>
        </Border>

        <slData:DataGrid x:Name="FindDetailsDataGrid" AutoGenerateColumns="False" HeadersVisibility="All" Background="White" 
                         BorderBrush="Black" BorderThickness="1" SelectionChanged="FindDetails_SelectionChanged" 
                         HorizontalScrollBarVisibility="Hidden" Grid.Row="1"
                         IsReadOnly="True" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" 
                         Height="Auto" Width="Auto">
            <slData:DataGrid.Columns>
                <slData:DataGridTextColumn Binding="{Binding Path=LayerId}" Header="Layer ID" />
                <slData:DataGridTextColumn Binding="{Binding Path=LayerName}" Header="Layer Name"/>
                <slData:DataGridTextColumn Binding="{Binding Path=FoundFieldName}" Header="Found Field Name" />
                <slData:DataGridTextColumn Binding="{Binding Path=Value}" Header="Found Field Value"/>
            </slData:DataGrid.Columns>
        </slData:DataGrid>



    </Grid>
</UserControl>
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);
        }
    }
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值