地图集合(Maps)和图层集合(Layers)
访问Maps和Layers
遍历maps和layers
创建一个新的图层
使用图层对象的属性
上一讲中,我们了解到在ArcMap应用中,Application代表ArcMap,一个Application
有MxDocument组成,一个MxDocument由多个Map组成,一个Map由多个图层Layer组成,
图层Layer是FeatureLayer的基类。现在,我们要了解,一个FeatureLayer和0或者1
个FeatureClass相联合。Dataset为抽象基类,Table为实例化类,从Dataset派生,
FeatureClass是Table的子类。多个FeatureClass组成FeatureDataset。
访问maps
由MxDocument访问maps
得到当前的map
Dim pMxDoc as IMxDocument
Set pMxDoc=ThisDocument
dim pMap as IMap
set pMap=pMxDoc.FocusMap
得到maps(IMaps)
一个地图文档可以包含有多个数据框,每个数据框都可以拥有不同的图层和表现。
FocusMap是指向当前活动的数据框。
访问Layers
有map和MxDocument访问layers
得到选定的layer(IMxDocument)
得到指定的图层(IMap)
得到所有图层(IMap)
遍历Maps集合
集合是按照顺序的.
遍历一个Map对象中的图层对象
IMaps图层集属性返回IEnumLayers,其只有Next和Reset两个方法.
好像是具有较少属性和方法的集合.Next返回ILayer,Reset当前指针指向top,即第一项的前边。
dim pLayer as ILayer
dim pLayers as IEnumLayers
set pLayers=pMap.layers
set pLayer=pLayers.Next;
set pLayer=pLayers.Next;
添加一个新图层到Map中
Layer是一个抽象类:不能创建
可创建的子类:TinLayer,FeatureLayer,RasterLayer等。
dim pFLayer as ILayer
set pFLayer=new FeatureLayer
dim pMxDoc as IMxDocument
dim pMap as IMap
set pMxDoc=thisdocument
set pMap=pMxDoc.focusmap
pMap.AddLayer pFLayer
因为还没有设置数据源,所以图标为失去数据连接的状态
使用图层对象
ILayer接口的属性:Name Visible ShowTips MaximumScale MinimumScale等
IGeoDataSet接口属性:Extent SpatialReference
Dim pLayer as ILayer
set pLayer=pMxDoc.SelectedLayer
pLayer.Name="Streets"
pLayer.Visible=true
pLayer.ShowTips=false
设置FeatureLayer的数据源
FeatureClass属性(IFeatureLayer)

浙公网安备 33010602011771号