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

发布于 2024-09-16 04:28:21 字数 153 浏览 3 评论 0原文

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 

I have an ILayer, now I want to access and turn on and off various sublayers like the street layer or the railroad layer. Can you tell me how to access these layers?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

流云如水 2024-09-23 04:28:21

我认为您需要将图层组投射到 ICompositeLayer (链接)。

I think you'll want to cast your group layer to an ICompositeLayer (linky).

执手闯天涯 2024-09-23 04:28:21

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

Accessing a basemap sublayer
The following code example shows how to access a basemap sublayer, retrieve the inner layer, update a property on the inner layer, and notify the basemap layer of the change. The notification invalidates the layer's internal cache so that the content is redrawn to reflect the update. In this example, the update clears the definition expression of a feature layer.
[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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文