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. php类与对象

    1.类与对象 对象:实际存在该类事物中每个实物的个体.$a =new User(); 实例化后的$a 引用:php的别名,两个不同的变量名字指向相同的内容 封装: 把对象的属性和方法组织在一个类(逻辑 ...

  2. PyQt4关闭最大化最小化取消双击最大化

    self.setWindowFlags(Qt.Window | Qt.WindowTitleHint | Qt.WindowCloseButtonHint | Qt.CustomizeWindowHi ...

  3. ZJOIDay2T1 BB题解

    讲道理我是调不出来了... 考虑对序列按下标维护每个节点最后的树. 那么 改操作点 - 把一段连续的节点改父亲 加点/删点(注意拆成两个操作了) 插儿子 那么用seg维护一下下标, 用ETT维护Dep ...

  4. Objective C 快速入门学习五

    <一>继承和多态 @class Complex 声明类(同C++) 子类函数成员 super 访问父类 同C++类似 .通过继承 在子类中添加新方法 .通过继承 在子类中添加新成员 .通过 ...

  5. Oracle11g +Win 64+PLSQL9.0

    最近在Oracle11g配置数据库的时候发现了一个问题,就是找不到监听,网上说win7的64位的系统必须装上32位的客户端才能被PLSQL 识别,事实上也是这样,PLSQL 只能识别32位的客户端,所 ...

  6. 通过代理连接go01ge

     日本:https://pac.mcplay.cn/jp.pac台湾:https://pac.mcplay.cn/tw.pac如果想上Google可以试试简单的方法,在ie的代理自动配置脚本设置这个p ...

  7. 【转】你可能不知道的Shell

    本文转自http://coolshell.cn/articles/8619.html,只摘取了其中的一部分. 再分享一些可能你不知道的shell用法和脚本,简单&强大! 在阅读以下部分前,强烈 ...

  8. Unity3d《Shader篇》地球旋转上空悬浮云层

    记得把纹理设置成Repeat Shader "Custom/Earth" { Properties { _MainTex ("Base (RGB)", 2D) ...

  9. js中修改标签的hidden属性

    hidden属性在html5中,只要存在,就是隐藏效果,而不论值为多少 要显示元素,要删除hidden属性,而不是设置为false <script type="text/javascr ...

  10. win8内置管理员用户无法激活此应用

    在运行中输入:“gpedit.msc”,就会启动组策略编辑器, 计算机配置 --> Windows设置 --> 安全设置 --> 本地策略 -->  安全选项  ::::  用 ...