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. Python tab键自动补齐

    1.进入root家目录  建立.tab文件 .tab文件内容如下: ############################################## import sys import r ...

  2. tomcat 访问软连接

    Linux创建软连接: ln -s 源文件 目标文件 tomcat安装目录 / conf目录下的:context.xml文件在 <Context />; 里面加上 allowLinking ...

  3. phpcms更换域名用户无法注册问题

    问题背景: 用户注册必须在后台开启phpsso,这个sso也就是单点登录了,之前做的站都没有带用户登录,也一直没注意,今天线下localhost用户登录注册都没有问题,可是移到线上测试却怎么都无法注册 ...

  4. 使用GitHub

    1. 进入 1.1 建立账号 打开网站https://github.com/主页上就可以注册.注册之后会有一个简单的帮助文档,在帮组文档上可以下载一个PC客户端(如果是WINDOWS平台,需要.NET ...

  5. Find celebrity

    Suppose you are at a party with n people (labeled from 0 to n - 1) and among them, there may exist o ...

  6. c++数据类型和定义

    我们都知道,刚开始学习数学的时候.乘法口诀.99乘法口诀.这个是大家都需要背的.背熟了这个,大家才能知道遇到算术题如何计算.这个99乘法口诀就是一种定义. 同样任何的语言都会有很多的定义.比如语文:各 ...

  7. 常见概率组合题目总结quickstart

    [本文链接] http://www.cnblogs.com/hellogiser/p/interview-questions-quickstart-for-combination-permutatio ...

  8. django 添加comments app

    django 添加comments app 参看 django comments 文档 安装和配置comments 1.安装comments,运行:pip install django-contrib ...

  9. linux的提示信息--/etc/motd和/etc/issue

    /etc/motd 即 message of the day 每次用户登录时,这个文件的内容都会显示在用户的终端上.如果shell支持中文,还可以使用中文,这样看起来更加舒服. 成功登录后,自动输出. ...

  10. javascript 导出Excel

    测试兼容IE google 火狐浏览器.看到的朋友也许你某一天也会需要. //obj是table表格外面嵌套div id function saveCode(obj) { try { var strH ...