Select to view content in your preferred language

Python API add group layer to Web Map

07-10-2023 04:16 PM
New Contributor III

I would like to use the Python API to add an existing group layer feature service to a WebMap object. However, when I use the WebMap.add_layer() function, it adds every sublayer individually to the map, rather than the group layer as a whole. When I use the GUI to add the group layer feature service, it adds it as a single group, which is great. How can I do that with the Python API?

I saw a previous post that involved formatting the JSON structure for the group and sublayers, and generating ids for them, before adding them in the appropriate location of the maps JSON structure, which is ridiculous for such an obvious, simple task.

Just to clarify, what I mean by "group layer" is a single Hosted Feature Layer that contains sublayers.

1 Reply
New Contributor III

Hi @Scoth,

I think this will be a good idea to post in the ideas forum. 

As you mentioned, the only way I see to implement this functionality is by using the GroupLayer spec.

And checking out the solution from @RichardReinicke over here 

The Map Viewer in AGOL uses the GroupLayer.js which is different to the python sdk. The idea would be to include a python function called: WebMap.add_feature_service() or WebMap.add_layers('layers': 'layer 1, layer 2', title : 'group layer name').