【转】ArcGIS API for Silverlight/WPF 2.1学习笔记(五)
2、Find示例代码
(1)xaml文件:
//添加Symbol命名空间
xmlns:esriSymbols="clr-namespace:ESRI.ArcGIS.Client.Symbols;assembly=ESRI.ArcGIS.Client
//创建Symbol
<Grid.Resources>
<esriSymbols:SimpleFillSymbol x:Name="ResultsFillSymbol" Fill="#64FF0000" BorderBrush="Red" BorderThickness="2" />
</Grid.Resources>
//创建GraphicsLayer,显示查询结果
<esri:GraphicsLayer ID="MyGraphicsLayer">
<esri:GraphicsLayer.MapTip>
<Grid Background="LightYellow">
<StackPanel Margin="5">
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding [NAME]}" FontWeight="Bold" />
<TextBlock Text=" County, " FontWeight="Bold" />
<TextBlock Text="{Binding [STATE_NAME]}" FontWeight="Bold" />
</StackPanel>
<StackPanel Orientation="Horizontal">
<TextBlock Text="Population (2007): " />
<TextBlock Text="{Binding [POP2007]}" />
</StackPanel>
</StackPanel>
<Border BorderBrush="Black" BorderThickness="1" />
</Grid>
</esri:GraphicsLayer.MapTip>
</esri:GraphicsLayer>
//Find对话框
<Canvas HorizontalAlignment="" VerticalAlignment="" Margin="0,15,7,0" Width="230" >
<Rectangle Fill="#CC5C90B2" Stroke="Gray" RadiusX="10" RadiusY="10" Width="210" Height="55" />
<TextBlock Text="Find的国家名:" Foreground="White" FontSize="10" Margin="10,5,0,0" />
<TextBox x:Name="FindTextBox" Width="150" Margin="15,22,0,0" Text="Wash" />
<Button x:Name="FindButton" Content="Find" Margin="168,23,0,0" Click="FindButton_Click" />
</Canvas>
(2)cs文件
//添加命名空间
using ESRI.ArcGIS.Client;
using ESRI.ArcGIS.Client.Tasks;
// 点击find按钮,执行Find
private void FindButton_Click(object sender, RoutedEventArgs e)
{
//初始化Find task
FindTask findTask = new FindTask("http://./ArcGIS/rest/services/./MapServer/");
findTask.ExecuteCompleted += FindTask_ExecuteCompleted;
findTask.Failed += FindTask_Failed;
//初始化Find参数:将countries图层的Name字段作为Find Field
FindParameters findParameters = new FindParameters();
findParameters.LayerIds.AddRange(new int[] { 3 });
findParameters.SearchFields.AddRange(new string[] { "NAME" });
//返回find结果的feature geometry
findParameters.ReturnGeometry = true;
//textbox的text作为查询关键字
findParameters.SearchText = FindTextBox.Text;
//执行查询
findTask.ExecuteAsync(findParameters);
}
//find结束后,将结果绘制在地图上
private void FindTask_ExecuteCompleted(object sender, FindEventArgs args)
{
//获取graphicsLayer,清除先前的查询结果
GraphicsLayer graphicsLayer = MyMap.Layers["MyGraphicsLayer"] as GraphicsLayer;
graphicsLayer.ClearGraphics();
// Check for new results
if (args.FindResults.Count > 0)
{
//将结果添加进地图
foreach (FindResult result in args.FindResults)
{
result.Feature.Symbol = ResultsFillSymbol;
graphicsLayer.Graphics.Add(result.Feature);
}
}
else
{
MessageBox.Show("No features found");
}
}
//find失败时,显示失败原因
private void FindTask_Failed(object sender, TaskFailedEventArgs args)
{
MessageBox.Show("Find failed: " + args.Error);
}
3、Identify示例代码
(1)xaml文件:
//添加命名空间
xmlns:esriTasks="clr-namespace:ESRI.ArcGIS.Client.Tasks;assembly=ESRI.ArcGIS.Client" xmlns:esriSymbols="clr-namespace:ESRI.ArcGIS.Client.Symbols;assembly=ESRI.ArcGIS.Client xmlns:slData="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data"
//定义task resources
<Grid.Resources>
<esriSymbols:PictureMarkerSymbol x:Name="IdentifyLocationSymbol" OffsetX="35" OffsetY="35" Source="/Assets/images/i_about.png" />
<esriSymbols:SimpleFillSymbol x:Name="SelectedFeatureSymbol" Fill="#64FF0000" BorderBrush="Red" BorderThickness="2" />
</Grid.Resources>
//创建GraphicsLayer,容纳Identify的地图结果显示
<esri:GraphicsLayer ID="ResultsGraphicsLayer" />
<esri:GraphicsLayer ID="IdentifyIconGraphicsLayer" />
//Identify的属性结果显示界面
<StackPanel Margin="10" HorizontalAlignment="Left">
<Grid>
<Rectangle Fill="#CC5C90B2" Stroke="Gray" RadiusX="10" RadiusY="10" />
<TextBlock Text="点击地图identify feature" Foreground="White" FontSize="10" Margin="10,5,10,5" />
<StackPanel x:Name="IdentifyResultsStackPanel" Margin="15,30,15,10" Visibility="Collapsed">
<TextBlock Text="Select a result from the list to display it" Foreground="White" FontSize="10" Margin="0,0,0,5" />
<ComboBox x:Name="IdentifyComboBox" SelectionChanged="IdentifyComboBox_SelectionChanged" />
<ScrollViewer MaxHeight="340" Margin="0,10,0,0">
<slData:DataGrid x:Name="IdentifyDetailsDataGrid" AutoGenerateColumns="False" HeadersVisibility="None" >
<slData:DataGrid.Columns>
<slData:DataGridTextColumn Binding="{Binding Path=Key}" FontWeight="Bold"/>
<slData:DataGridTextColumn Binding="{Binding Path=Value}"/>
</slData:DataGrid.Columns>
</slData:DataGrid>
</ScrollViewer>
</StackPanel>
</Grid>
</StackPanel>
(2)cs文件
//添加命名空间
using ESRI.ArcGIS.Client.Tasks;
using ESRI.ArcGIS.Client.Symbols;
// IdentifyResult
private List<IdentifyResult> _lastIdentifyResult;
public MainPage() { InitializeComponent(); }
// 点击地图,执行Identify
private void MyMap_MouseClick(object sender, ESRI.ArcGIS.Client.Map.MouseEventArgs args)
{
//在identify的地方(鼠标点击附近)显示一个icon
GraphicsLayer graphicsLayer = MyMap.Layers["IdentifyIconGraphicsLayer"] as GraphicsLayer;
graphicsLayer.ClearGraphics();
ESRI.ArcGIS.Client.Graphic graphic = new ESRI.ArcGIS.Client.Graphic()
{
Geometry = args.MapPoint,
Symbol = IdentifyLocationSymbol
};
graphicsLayer.Graphics.Add(graphic);
// 初始化Identify task
IdentifyTask identifyTask = new IdentifyTask("http://./ArcGIS/rest/services/./MapServer");
identifyTask.ExecuteCompleted += IdentifyTask_ExecuteCompleted;
identifyTask.Failed += IdentifyTask_Failed;
//初始化Identify parameters,指定searching的layers
IdentifyParameters identifyParameters = new IdentifyParameters();
identifyParameters.LayerOption = LayerOption.all;
// 设置identify parameters:通过地图的现有属性
identifyParameters.MapExtent = MyMap.Extent;
identifyParameters.Width = (int)MyMap.ActualWidth;
identifyParameters.Height = (int)MyMap.ActualHeight;
//通过点击执行Identify features
identifyParameters.Geometry = args.MapPoint;
identifyTask.ExecuteAsync(identifyParameters);
}
//identify完成后,查询结果的Attribute显示窗口
private void IdentifyTask_ExecuteCompleted(object sender, IdentifyEventArgs args)
{
//清除旧的结果
IdentifyComboBox.Items.Clear();
// Check for new results
if (args.IdentifyResults.Count > 0)
{
IdentifyResultsStackPanel.Visibility = Visibility.Visible;
//将结果添加到ComboBox
foreach (IdentifyResult result in args.IdentifyResults)
{
string title = string.Format("{0} ({1})", result.Value.ToString(), result.LayerName);
IdentifyComboBox.Items.Add(title);
}
// Workaround for ComboBox bug
IdentifyComboBox.UpdateLayout();
// Store the list of identify results
_lastIdentifyResult = args.IdentifyResults;
// Initialize ComboBox and fire SelectionChanged
IdentifyComboBox.SelectedIndex = 0;
}
else
{
// Hide ComboBox and attributes DataGrid and notify user
IdentifyResultsStackPanel.Visibility = Visibility.Collapsed;
MessageBox.Show("No features found");
}
}

//多个结果时,点击下拉框更改其它结果
void IdentifyComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
//地图上清除先前的结果
GraphicsLayer graphicsLayer = MyMap.Layers["ResultsGraphicsLayer"] as GraphicsLayer;
graphicsLayer.ClearGraphics();
// Check that ComboBox has a selected item. Needed because SelectionChanged fires
// when ComboBox.Clear is called.
if (IdentifyComboBox.SelectedIndex > -1)
{
// Update DataGrid with selected feature's attributes
Graphic selectedFeature = _lastIdentifyResult[IdentifyComboBox.SelectedIndex].Feature;
IdentifyDetailsDataGrid.ItemsSource = selectedFeature.Attributes;
// Apply symbol and add selected feature to map
selectedFeature.Symbol = SelectedFeatureSymbol;
graphicsLayer.Graphics.Add(selectedFeature);
}
}
//identify失败时,显示失败原因
private void IdentifyTask_Failed(object sender, TaskFailedEventArgs args)
{
MessageBox.Show("Identify failed: " + args.Error);
}
4、Adress locator示例代码(暂未学)
5、Geometry示例代码(暂未学)
6、Geoprocessing示例代码(暂未学)
7、Route示例代码(暂未学)
【转】ArcGIS API for Silverlight/WPF 2.1学习笔记(五)的更多相关文章
- ArcGIS API for Silverlight/WPF 2.1学习笔记(一)——精简版
一.安装 1.Visual Studio: (1)Visual Studio 2010或Visual Web Developer Express 2010 (2)Silverlight 4 Tools ...
- 【转】ArcGIS API for Silverlight/WPF 2.1学习笔记(一)
源自:http://blog.163.com/zwx_gis/blog/static/32434435201122193611576/ (主页:http://blog.163.com/zwx_gis/ ...
- 【转】ArcGIS API for Silverlight/WPF 2.1学习笔记(四)
七.Editing ArcGIS Server 10提供了: 通过feature service,在Web上编辑Feature layers的geographic data的功能. 通过geome ...
- 【转】ArcGIS API for Silverlight/WPF 2.1学习笔记(二)
五.Graphics layer 1.新增Graphics layer Graphics layer用于显示用户自定义绘制的点.线.面图形.使用时确保xaml文件中Graphics layer定义 ...
- 【转】ArcGIS API for Silverlight/WPF 2.1学习笔记(三)
六.Feature Layer Feature Layer是一种特殊的Graphics layer(继承自Graphics layer),除了像Graphics layer一样包含和显示Graphic ...
- 扩展ArcGIS API for Silverlight/WPF 中的TextSymbol支持角度标注
原文 http://blog.csdn.net/esricd/article/details/7587136 在ArcGIS API for Silverlight/WPF中原版的TextSymbol ...
- ArcGIS API for Silverlight学习笔记
ArcGIS API for Silverlight学习笔记(一):为什么要用Silverlight API(转) 你用上3G手机了吗?你可能会说,我就是喜欢用nokia1100,ABCDEFG跟我都 ...
- ArcGIS API for Silverlight开发入门
你用上3G手机了吗?你可能会说,我就是喜欢用nokia1100,ABCDEFG跟我 都没关系.但你不能否认3G是一种趋势,最终我们每个人都会被包裹在3G网络中.1100也不是一成不变,没准哪天为了打击 ...
- ArcGIS API For Silverlight使用在线地图的多种方法总结
引自:http://www.cnblogs.com/meimao5211/p/3283969.html ArcGIS API For Silverlight使用在线地图的多种方法总结 本人也正在学习A ...
随机推荐
- 【week6】团队贡献分
小组名称:nice! 小组成员:李权 于淼 杨柳 刘芳芳 项目内容:约跑app 完成任务: 10% 20% 70% 好 于淼 李权 中 刘芳芳 杨柳 差 1.李权8.4 2.于 ...
- app加密算法
php端 <?phpnamespace app\controllers;use yii\web\Controller;class TestController extends Controlle ...
- Ignite缓存大小管理
Ignite使用计算机内存存储缓存数据,达到提升缓存读写性能的.但是计算机内存往往是有限的,我们必须合理管理Ignite对内存的使用. Ignite可以使用JVM堆外内存和堆内内存.使用堆外内存基本上 ...
- python 代码覆盖率 coverage用法
先装coverage: D:\test_python\e8_test>pip install coverageCollecting coverage Downloading https://f ...
- 首屏渲染时间获取 performance.now()
Performance — 前端性能监控利器 最近在写一个监控脚本,终于有机会接触到了这一块,整理后写下了本文.Performance是一个做前端性能监控离不开的API,最好在页面完全加载完成之后 ...
- Kotlin语言Web库又添一虎将:Kweb
Kweb是一个库,您可以利用它使用Kotlin编程语言轻松构建Web应用程序.从程序员的角度来看,它基本上消除了浏览器和服务器之间的分离.这意味着只操纵DOM的事件不需要进行服务器往返.由于Kweb是 ...
- ES6学习--对象属性的可枚举性( enumerable)
可枚举性(enumerable)用来控制所描述的属性,是否将被包括在for...in循环之中.具体来说,如果一个属性的enumerable为false,下面三个操作不会取到该属性.* for..in循 ...
- Redis计算地理位置距离-GeoHash
Redis 在 3.2 版本以后增加了地理位置 GEO 模块,意味着我们可以使用 Redis 来实现摩拜单车「附近的 Mobike」.美团和饿了么「附近的餐馆」这样的功能了. 地图元素的位置数据使用二 ...
- 20145118 《Java程序设计》 实验报告四
实验要求 基于Android Studio开发简单的Android应用并部署测试; 了解Android组件.布局管理器的使用: 掌握Android中事件处理机制: Android Studio安装 实 ...
- 20145216史婧瑶《网络对抗》Web基础
20145216史婧瑶<网络对抗>Web基础 实验问题回答 (1)什么是表单 表单在网页中主要负责数据采集功能.一个表单有三个基本组成部分: 表单标签.表单域.表单按钮. (2)浏览器可以 ...