如何在arcobjects中访问底图的子图层?

时间:2010-08-25 21:58:59

标签: arcobjects

ILayer layer = mapControl.get_Layer(1); //layer 1 is usa_base_map 

我有一个ILayer,现在我想访问并打开和关闭各种子层,如街道层或铁路层。你能告诉我如何访问这些图层吗?

2 个答案:

答案 0 :(得分:1)

我认为您希望将您的论坛图层转换为ICompositeLayerlinky)。

答案 1 :(得分:1)

访问底图子图层 以下代码示例演示如何访问底图子图层,检索内层图层,更新内层图层上的属性以及通知底图图层更改。通知使图层的内部缓存无效,以便重新绘制内容以反映更新。在此示例中,更新将清除要素图层的定义表达式。 [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