In the layer list, is there a way to limit the drag-drop of layers so that they can only be reordered within their current group and not moved to another group?
I'm using the arcgis-layer-list component from version 4.33 of the SDK. I have use cases where we are adding multiple groups of feature layers to a map. I would like to limit the movability (dragging and dropping, reordering, etc.) of the list items to within the current group only. So, if I have groups A, B, and C, each of which contain layers 1, 2, and 3, I want to be able to reorder A-1, A-2, A-3 within group A, but not move them into either of the other groups, or to the top level of the list. Similarly, I want to be able to reorder groups A, B, and C at the top level of the layer list (so maybe they are in C, A, B order), but not drag any group into one of the other groups.
I have come up with a very hacky solution to intercept DOM drag events, determine whether the dragged item was dropped into a different parent, and if so, restore a snapshot of the layers from before the drag. However, even though this 'works', I then noticed that clicking on the drag handle for any item in the list opens a menu that allows me to 'Reorder' it (Move Up, Move Down), which is what I want, but also to 'Move To' any of the other groups, which I don't want.
Is there any straightforward way to accomplish this with the API as-is?
Solved! Go to Solution.
This is an interesting idea @SparkyT19, and would make a good enhancement, but there isn't a supported way to do this right now with group layers. The only, possibly not so easy way, to accomplish this today would be to publish the group layer as a Map Service and use MapImageLayer. We prevent sublayers from being moved outside their parent map image layer in the layer list.
This is an interesting idea @SparkyT19, and would make a good enhancement, but there isn't a supported way to do this right now with group layers. The only, possibly not so easy way, to accomplish this today would be to publish the group layer as a Map Service and use MapImageLayer. We prevent sublayers from being moved outside their parent map image layer in the layer list.
Thanks @Sage_Wall - I thought that might be the case. We do already have each group of feature layers published as both Map Services and Feature Services, but a number of our current and future use cases require that we add these layers to the map as Feature Layers.
For the time being, we will likely disable drag functionality in the layer list and just provide some Move Up and Move Down options in the actions section of the list items. I'll post the enhancement idea over in the Ideas section.