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. Implement a TextView with an animation in its left side

    In my case, I want to write a TextView with an animation in its left side. ImageView + TextView coul ...

  2. PHP--获取响应头(Response Header)方法

    方法一: $baiduUrl = "http://www.baidu.com/link";   file_get_contents($baiduUrl); $responseInf ...

  3. 浏览器JS脚本

    javascript: void((function() { alert("zeze"); })()) javascript:

  4. Alien Dictionary

    There is a new alien language which uses the latin alphabet. However, the order among letters are un ...

  5. iOS 活动图 流程图

    活动图        活动图和状态机图都被称为演化图,其区别和联系如下:       1.活动图:用于描述用例内部的活动或方法的流程,如果除去活动图中的并行活动描述以后,它就变成流程图.       ...

  6. Maven 3.3.3 Win10环境下的使用实例(上)

    Maven是一个项目管理和构建自动化工具,在使用之前,请按照Apache官网提供的指南进行环境变量配置. 完成后在PowerShell中输入如下命令来验证Maven的部署情况: mvn -v 正常的响 ...

  7. [转][Android]FragmentPagerAdapter与FragmentStatePagerAdapter使用详解与区别

    原文链接:http://blog.csdn.net/zhaokaiqiang1992 FragmentPagerAdapter是android-support-v4支持包里面出现的一个新的适配器,继承 ...

  8. Effective C++ -----条款53:不要轻忽编译期的警告

    严肃对待编译器发出的警告信息.努力在你的编译器的最高(最严苛)警告级别下争取“无任何警告”的荣誉. 不要过度依赖编译器的报警能力,因为不同的编译器对待事情的态度并不相同.一旦移植到另一个编译器上,你元 ...

  9. Maven实现直接部署Web项目到Tomcat7(转)

    转载自:http://my.oschina.net/angel243/blog/178554 以前在项目中很少使用Maven,最近自己学习了一下maven,真的是非常强大的项目构建工具,对于依赖包的定 ...

  10. JAVA导出pdf实例

    一.直接导出成PDF   Java代码 1. import java.io.FileNotFoundException; 2. import java.io.FileOutputStream; 3.  ...