ArcGIS可以设置动态地图服务(ArcGISDynamicMapServiceLayer)显示哪些图层,也可以设置每个图层根据某个属性字段的某些条件来进行过滤显示。

1、设置显示的图层

主要是通过ArcGISDynamicMapServiceLayer的VisibleLayers属性来设置或得到当前显示的图层,C#代码如下:

代码中Map1和TextBlock_VisibleLayers是已经定义好的地图和TextBlock控件。

//ArcGISDynamicMapServiceLayer初始化函数
private void ArcGISDynamicMapServiceLayer_Initialized(object sender, System.EventArgs e)
{
//得到ArcGISDynamicMapServiceLayer,这里是第一个图层,根据实际情况,可以通过Map.Layers["图层的ID"]来得到
ArcGISDynamicMapServiceLayer myArcGISDynamicMapServiceLayer = (ArcGISDynamicMapServiceLayer)Map1.Layers[]; //VisibleLayers的读写 //下面注释的代码:设置myArcGISDynamicMapServiceLayer第二和第三个图层显示
//int[] myVisibleLayers2 = { 1, 2 };
//myArcGISDynamicMapServiceLayer.VisibleLayers = myVisibleLayers2; //得到显示的图层ID
int[] myVisibleLayers = myArcGISDynamicMapServiceLayer.VisibleLayers;
if (myVisibleLayers != null)
{
string myVisibleLayersText = "Number VisibleLayers: " + myVisibleLayers.Length.ToString();
string myVisibleLayersText2 = "";
int i = ;
for (i = ; i < myVisibleLayers.Length; ++i)
{
myVisibleLayersText2 = myVisibleLayersText2 + " " + myVisibleLayers[i].ToString();
}
TextBlock_VisibleLayers.Text = myVisibleLayersText + ". VisibleLayers ID's: " + myVisibleLayersText2;
}
else
{
TextBlock_VisibleLayers.Text = "[VisibleLayers not set - Meaning all layers are visible.]";
}
}

2、设置图层根据字段条件过滤显示

如果不全部显示一个图层的所有要素,而是根据某些条件来“过滤显示”,则可以通过设置LayerDefinition来实现。

LayerDefinition的设置可以通过XAML代码实现:

<StackPanel Name="StackPanel1" Height="400" Width="400" Margin="0,0,0,0" HorizontalAlignment="Left" VerticalAlignment="Top" >
<esri:Map Background="White" Name="Map1" Height="200" Width="400"> <!-- Set the LayerDefinition for the ArcGISDynamicMapServiceLayer. -->
<!-- By default no LayerDefinition is set unless explicitly set on the server. -->
<esri:ArcGISDynamicMapServiceLayer
Url="http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Earthquakes/Since_1970/MapServer" />
<esri:ArcGISDynamicMapServiceLayer.LayerDefinitions> <!-- LayerID="0" is the Earthquakes1970 layer. The Definition only displays earth quakes that have a
Magnitude greater than 6. The field Magnitude is of type esriFieldTypeDouble. -->
<esri:LayerDefinition LayerID="0" Definition="Magnitude > 6" /> <!-- LayerID="0" is the Earthquakes1970 layer. The Definition only displays earth quakes that have a
Magnitude greater than 3 and less than 6. The field Magnitude is of type esriFieldTypeDouble. -->
<!-- <esri:LayerDefinition LayerID="0" Definition="Magnitude > 3 AND Magnitude &lt; 6" /> --> <!-- Another example where the Name of the earth quake event is to contains the letters 'CHINA'.
Note: the Definition is case sensitive. The field Name is of type esriFieldTypeString. -->
<!-- <esri:LayerDefinition LayerID="0" Definition="Name LIKE 'CHINA'" /> --> <!-- Another example where the Name of the earth quake event is exactly matches the letters 'VENEZUELA'.
Note: the Definition is case sensitive. The field Name is of type esriFieldTypeString. -->
<!-- <esri:LayerDefinition LayerID="0" Definition="Name = 'VENEZUELA'" /> --> <!-- Another example where the earth quake events are displayed if they occured after January 15, 2000.
The field Date_ is of type esriFieldTypeDate. -->
<!-- <esri:LayerDefinition LayerID="0" Definition="Date_ > DATE '1/15/2000'" />--> </esri:ArcGISDynamicMapServiceLayer.LayerDefinitions>
</esri:ArcGISDynamicMapServiceLayer>
</esri:Map> <!-- LayerDefinitions Property (Read) -->
<TextBlock Height="23" Name="TextBlock_LayerDefinitions"
Text="{Binding ElementName=Map1, Path=Layers[0].LayerDefinitions[0].Definition}" />
</StackPanel>

也可以通过代码来实现,C#代码如下:

//ArcGISDynamicMapServiceLayer初始化函数
private void ArcGISDynamicMapServiceLayer_Initialized(object sender, System.EventArgs e)
{
//得到ArcGISDynamicMapServiceLayer,这里是第一个图层,根据实际情况,可以通过Map.Layers["图层的ID"]来得到
ArcGISDynamicMapServiceLayer myArcGISDynamicMapServiceLayer = (ArcGISDynamicMapServiceLayer)Map1.Layers[]; //LayerDefinition的读写 //设置图层的LayerDefinition,默认情况下LayerDefinition是没有设置的
//得到图层的LayerDefinition
ESRI.ArcGIS.Client.LayerDefinition myDefinition = new ESRI.ArcGIS.Client.LayerDefinition();
myDefinition.LayerID = ; //设置LayerDefinition,属性字段“Magnitude”属于ID为0的图层
//LayerDefinition的设置语句和Query中的Where语句一样
//字段Magnitude的类型是esriFieldTypeDouble.
myDefinition.Definition = "Magnitude > 6"; // The Definition only displays earth quakes that have a Magnitude greater than 3 and less that 6.
// The field Magnitude is of type esriFieldTypeDouble.
// myDefinition.Definition = "Magnitude > 3 AND Magnitude < 6"; // Another example where the Name of the earth quake event is to contains the letters 'CHINA'.
// Note: the Definition is case sensitive. The field Name is of type esriFieldTypeString.
//myDefinition.Definition = "Name LIKE 'CHINA'"; // Another example where the Name of the earth quake event is exactly matches the letters 'VENEZUELA'.
// Note: the Definition is case sensitive. The field Name is of type esriFieldTypeString.
//myDefinition.Definition = "Name = 'VENEZUELA'"; // Another example where the earth quake events are displayed if they occured after January 15, 2000.
// The field Date_ is of type esriFieldTypeDate.
//myDefinition.Definition = "Date_ > DATE '1/15/2000'"; //创建一个ObservableCollection,add设置的LayerDefinition
System.Collections.ObjectModel.ObservableCollection<LayerDefinition> myObservableCollection2 =
new System.Collections.ObjectModel.ObservableCollection<LayerDefinition>();
myObservableCollection2.Add(myDefinition); //启动设置的LayerDefinition
myArcGISDynamicMapServiceLayer.LayerDefinitions = myObservableCollection2; //得到已经存在的LayerDefinitions collection.
System.Collections.ObjectModel.ObservableCollection<LayerDefinition> myObservableCollection =
myArcGISDynamicMapServiceLayer.LayerDefinitions; if (myObservableCollection.Count > )
{
//得到第一个LayerDefinition
ESRI.ArcGIS.Client.LayerDefinition myLayerDefinition = myObservableCollection[]; //得到LayerDefinition的信息
TextBlock_LayerDefinitions.Text = "For Layer: " + myLayerDefinition.LayerID.ToString() +
". The Defintion is: " + myLayerDefinition.Definition;
}
else
{
TextBlock_LayerDefinitions.Text = "[NO LayerDefinitions SET]";
}
}

上面ArcGISDynamicMapServiceLayer_Initialized(object sender, System.EventArgs e)函数是订阅到ArcGISDynamicMapServiceLayer.Initialized的,也就是在图层加载的时候就设置了“过滤”条件,如果要在后期在某个响应事件中动态的刷新地图,需要在设置LayerDefinition后,调用ArcGISDynamicMapServiceLayer.Refresh()函数来刷新地图才能看到效果。

参考:

http://help.arcgis.com/en/webapi/silverlight/apiref/ESRI.ArcGIS.Client~ESRI.ArcGIS.Client.ArcGISDynamicMapServiceLayer~VisibleLayers.html

http://help.arcgis.com/en/webapi/silverlight/apiref/ESRI.ArcGIS.Client~ESRI.ArcGIS.Client.ArcGISDynamicMapServiceLayer~LayerDefinitions.html

ArcGIS图层和要素的过滤显示的更多相关文章

  1. ArcGIS AO中控制图层中要素可见状态的总结

    一.DefinitionExpression 实现新建查询图层,查询结果要素为选中状态 该接口可以通过两种方法来控制要素的可见状态. 思路1 通过该接口的 DefinitionExpression 方 ...

  2. ArcGIS Server 10.2 实战(三)图层标注及图例中文显示乱码的解决

    发布的图层中不可避免的使用到中文来标注,默认设置下,ArcGIS Server不支持中文的,中文标注显示成乱码,主要是编码的问题,需要把手动把编码改为UTF-8. ArcGIS Server 10.2 ...

  3. Arcgis engine 指定图层对要素进行创建、删除等操作

    Arcgis engine 指定图层创建点要素 在指定的图层上创建一个点要素,点要素的位置是通过X,Y坐标指定的,下面是具体的注释 .其中 和IFeatureClassWrite接口有关的代码不要好像 ...

  4. ArcGIS图层介绍

    什么是图层 图层是用来在 ArcGIS 产品套件中显示地理数据集的机制.每个图层代表一种数据集(可以是地图服务.图形或是矢量数据),并指定该数据集是如何描绘使用一组属性的. 包含一个地图控件的每个应用 ...

  5. arcgis图层 GraphicsLayer与FeatureLayer

    什么是图层 图层是用来在 ArcGIS 产品套件中显示地理数据集的机制.每个图层代表一种数据集(可以是地图服务.图形或是矢量数据),并指定该数据集是如何描绘使用一组属性的. 包含一个地图控件的每个应用 ...

  6. 利用动态图层实现数据的实时显示(arcEngine IDynamiclayer)

    marine 原文利用动态图层实现数据的实时显示(arcEngine IDynamiclayer) 说明:最近一个项目用到这方面知识,文章主要来至网络,后期会加入自己的开发心得.(以下的代码实例中,地 ...

  7. QGis(三)查询矢量图层的要素属性字段值(转载)

    QGis(三)查询矢量图层的要素属性字段值 https://github.com/gwaldron/osgearth/issues/489 当加载一个矢量图层后,如果要查看要素的属性字段值,则需要实现 ...

  8. AE控制图层中要素可见状态的几种方法

    转自原文 AE控制图层中要素可见状态的几种方法 工作中常有这样的需求,一个作业图层由几个作业员来操作,我们要 控制每一个作业员只能看到他负责的区域.作业员的可见区域控制有时候是按空间区域划分,有时候是 ...

  9. ArcGIS 图层旋转工具-arcgis案例实习教程

    ArcGIS 图层旋转工具-arcgis案例实习教程 联系方式:谢老师,135-4855-4328,xiexiaokui#qq.com 目的:对输入图层执行坐标旋转 使用方法:输入图层,旋转中心,旋转 ...

随机推荐

  1. 9 DelayQueueEntry 延时队列节点类——Live555源码阅读(一)基本组件类

    这是Live555源码阅读的第一部分,包括了时间类,延时队列类,处理程序描述类,哈希表类这四个大类. 本文由乌合之众 lym瞎编,欢迎转载 http://www.cnblogs.com/oloroso ...

  2. 服务器设置SSH 长连接

    1.echo $TMOUT 如果显示空白,表示没有设置, 等于使用默认值0, 一般情况下应该是不超时. 如果大于0, 可以在如/etc/profile之类文件中设置它为0. 2.修改/etc/ssh/ ...

  3. django 的文件上传

    template html(模板文件): <form enctype="multipart/form-data" method="POST" action ...

  4. ndk学习15: IPC机制

    Linux IPC机制 来自为知笔记(Wiz)

  5. JS 对象遍历

    var orgRoot = { 271: {backgroundColor: '#f68f2b', textColor: '#FFFFFF'}, 272: {backgroundColor: '#49 ...

  6. Linux--多网卡的7种Bond模式

    网卡bond是通过把多张网卡绑定为一个逻辑网卡,实现本地网卡的冗余,带宽扩容和负载均衡.在应用部署中是一种常用的技术,我们公司基本所有的项目相关服务器都做了bond,这里总结整理,以便待查. bond ...

  7. css 图形,非常完美

    http://www.360doc.com/content/12/0327/13/8674_198243134.shtml

  8. POJ 1016

    http://poj.org/problem?id=1016 一道字符串处理的题目,理解题意后注意细节就好. 题意:每一串数字 都可以写成 a1 b1 a2 b2 ....ai bi 其中ai是指bi ...

  9. percona-toolkit 之 【pt-deadlock-logger】说明

    摘要: 死锁:是指两个或则多个事务在同一个资源上相互占用,并请求锁定对方占用的资源,而导致恶性循环的现象:当产生死锁的时候,MySQL会回滚一个小事务的SQL,确保另一个完成.上面是死锁的概念,而在M ...

  10. 原:[eclipse启动错误] JVM terminated.Exit code=2

    启动eclipse的时候忽然出现以下错误: 解决方案: 删除环境变量PATH或者Path中的 C:\ProgramData\Oracle\Java\javapath