Tuesday, 31 January 2017

arcobjects - How to let user only rearrange layers in a group layer?


We have a stand-alone application were we let the users add local shape and raster layers. We would like to add functionality so that the user can rearrange the added layers within a specific group layer.


We know it's possible to enable drag and drop on the TocControl but it lets the user rearrange all layers and that's not an option for us. Is there a way to enable drag and drop only on a specific group layer or somehow mimic the same behavior?



Answer



Not as visually cool but at least it work, use the MoveLayerEx in IMapLayers can be used to move a layer in a group layer, use the same grouplayer as source and target and apply the index that the layer shall have in the group. Made a small code sample:


Private Sub MoveGroupLayerItem(ByVal up As Boolean)
Dim layer As ILayer = getLayer()
Dim layerIndex As Integer = getLayerGroupIndex()


Dim map As IMap = axMapControl1.ActiveView.FocusMap

Dim mapLayers As IMapLayers = CType(map, IMapLayers)

Dim groupLayer As IGroupLayer = CType(map.Layer(0), IGroupLayer)
Dim compLayer As ICompositeLayer = CType(groupLayer, ICompositeLayer)


If up Then
If layerIndex > 0 Then

mapLayers.MoveLayerEx(groupLayer, groupLayer, layer, layerIndex - 1)
End If
Else
If (layerIndex < compLayer.Count - 1) Then
mapLayers.MoveLayerEx(groupLayer, groupLayer, layer, layerIndex + 1)
End If
End If

axMapControl1.Refresh(esriViewDrawPhase.esriViewAll, Nothing, Nothing)
End Sub

No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...