开发者

How to access sublayer of a basemap in arcobjects?

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

I have an I开发者_开发百科Layer, 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?


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


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜