ILayer layer = mapControl.get_Layer(1); //layer 1 is usa_base_map
我有一个 ILayer,现在我想访问和打开和关闭各种子层,例如街道层或铁路层。你能告诉我如何访问这些图层吗?
ILayer layer = mapControl.get_Layer(1); //layer 1 is usa_base_map
我有一个 ILayer,现在我想访问和打开和关闭各种子层,例如街道层或铁路层。你能告诉我如何访问这些图层吗?
我认为您需要将组图层转换为ICompositeLayer
(linky)。
访问底图子图层 以下代码示例显示如何访问底图子图层、检索内层、更新内层的属性以及通知底图图层更改。该通知使图层的内部缓存无效,以便重新绘制内容以反映更新。在此示例中,更新会清除要素图层的定义表达式。[C#]
private void UpdateBasemapSublayerAndNotify(IBasemapLayer basemapLayer, IMap map)
{
ICompositeLayer basemapCompositeLayer = basemapLayer as ICompositeLayer;
IBasemapSubLayer basemapSubLayer = basemapCompositeLayer.get_Layer(0)as
IBasemapSubLayer;
ILayer innerLayer = basemapSubLayer.Layer;
IFeatureLayer featureLayer = innerLayer as IFeatureLayer;
if (featureLayer != null)
{
IFeatureLayerDefinition featureLayerDef = featureLayer as
IFeatureLayerDefinition;
featureLayerDef.DefinitionExpression = "";
}
//When performing operations against the wrapped layer that change properties, you must
//notify the basemaplayer so the display cache can be recreated if necessary.
basemapLayer.NotifyLayerChanged(basemapSubLayer as ILayer,
esriLayerEventHint.esriLayerEventHintProperties, null);
IActiveView activeView = map as IActiveView;
activeView.PartialRefresh(esriViewDrawPhase.esriViewGeography, basemapLayer as
object, null);
}
[VB.NET]
Private Sub UpdateBasemapSublayerAndNotify(ByVal basemapLayer As IBasemapLayer, ByVal map As IMap)
Dim basemapCompositeLayer As ICompositeLayer = TryCast(basemapLayer, ICompositeLayer)
Dim basemapSubLayer As IBasemapSubLayer = TryCast(basemapCompositeLayer.get_Layer(0), IBasemapSubLayer)
Dim innerLayer As ILayer = basemapSubLayer.Layer
Dim featureLayer As IFeatureLayer = TryCast(innerLayer, IFeatureLayer)
If featureLayer IsNot Nothing Then
Dim featureLayerDef As IFeatureLayerDefinition = TryCast(featureLayer, IFeatureLayerDefinition)
featureLayerDef.DefinitionExpression = ""
End If
'When performing operations against the wrapped layer that change properties, you must
'notify the basemaplayer so the display cache can be recreated if necessary.
basemapLayer.NotifyLayerChanged(TryCast(basemapSubLayer, ILayer), esriLayerEventHint.esriLayerEventHintProperties, Nothing)
Dim activeView As IActiveView = TryCast(map, IActiveView)
activeView.PartialRefresh(esriViewDrawPhase.esriViewGeography, TryCast(basemapLayer, Object), Nothing)
End Sub