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. Android Service1

    一.Service的种类 按运行地点分类: 类别 区别  优点 缺点   应用 本地服务(Local) 该服务依附在主进程上,  服务依附在主进程上而不是独立的进程,这样在一定程度上节约了资源,另外L ...

  2. 教程和工具--用wxPython编写GUI程序的

    wxPython是个很好的GUI库,对底层的C++库进行了封装,调用起来很方便,尤其是操作前台UI界面和后台多线程,两者配合很方便,做GUI程序最难是写界面尤其是布局. 关于wxPython,自己正在 ...

  3. IPC---共享内存

    共享内存就是允许两个或多个不相关的进程访问同一个逻辑内存.共享内存是在两个正在运行的进程之间共享和传递数据时,不需要在客户进程和服务器进程之间幅值,因此是最快的一种IPC.不同进程之间共享的内存通常安 ...

  4. vim python设置

    http://www.cnblogs.com/Leo-Forest/archive/2012/04/06/2435237.html http://linux-wiki.cn/wiki/zh-hans/ ...

  5. python模块介绍- collections(5)-OrderedDict 有序字典

    1.3.5 OrderedDict 有序字典 OrderedDict是dict的子类,它记住了内容添加的顺序. import collections print 'Regular dictionary ...

  6. 一步步搭建docker私有仓库并从私有仓库中下载镜像

    一步步搭建docker私有仓库 #下载镜像 docker pull registry#查看镜像 docker images #运行私有仓库,指定端口和数据卷 docker run -d -p : -v ...

  7. 如何为自己的windows 8系统的电脑更换锁屏壁纸

    现在的人都喜欢个性,今天教大家如何设置自己想要的锁屏壁纸 工具/原料 Windows 8系统的笔记本电脑 方法/步骤   将鼠标移到电脑的右下方,点击设置按钮进入设置页面   找到更改电脑设置并点击进 ...

  8. HDU 4966 GGS-DDU(最小树形图)

    n个技能,每个技能有0-a[i]的等级,m个课程,每个课程需要前置技能c[i]至少达到lv1[i]等级,效果是技能d[i]达到lv2[i]等级,花费w[i]. 输出最小花费使得全技能满级(初始全技能0 ...

  9. (2016弱校联盟十一专场10.2) E.Coins

    题目链接 很久之前写的了,好像是对拍打表过的,推一下就行了. #include <bits/stdc++.h> using namespace std; typedef long long ...

  10. Linux内核补丁升级

    如果机器已经联网,直接利用包管理工具更新,需要注意的是现在3.0以上的内核引入了签名机制,需要导入签名的key,参考步骤如下: 1.导入keyrpm --import https://www.elre ...