<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Python API add group layer to webmap? in ArcGIS API for Python Questions</title>
    <link>https://community.esri.com/t5/arcgis-api-for-python-questions/python-api-add-group-layer-to-webmap/m-p/1112126#M6770</link>
    <description>&lt;LI-CODE lang="python"&gt;map_item["operationalLayers"]&lt;/LI-CODE&gt;&lt;P&gt;Hi,&lt;BR /&gt;&lt;BR /&gt;I have a very general question this time.&lt;BR /&gt;&lt;BR /&gt;The Esri arcgis API is meant to be THE tool to automate workflows and to interact with ArcGIS Portal. But there seem to be a lot of features that are not implemented yet, in my case map authorization.&lt;BR /&gt;&lt;BR /&gt;I have the new webmaps (next gen) and map viewer beta. I can interact with web maps v2 also from the Python API. But I can't create a group layer with API methods.&lt;BR /&gt;&lt;BR /&gt;I can do:&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;map_item.get_data()&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;I see my GroupLayer in the map layers:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;map_item["operationalLayers"]&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;[
    {
        "id": "htsews6tyu0-layer-10010",
        "title": "DummyGroup",
        "layers": [
            {
                "id": "17cc733308b-layer-3",
                "title": "FeatureLayer1",
                "url": "some-feature-server-url",
                "itemId": "d77d046fb6de424da2258a08b376f1fc",
                "layerType": "ArcGISFeatureLayer",
                "popupInfo": {
                    "popupElements": [
                        {
                            "type": "fields"
                        }
                    ],
                    "showAttachments": True,
                    "fieldInfos": [
                        {
                            "fieldName": "objectid",
                            "label": "OBJECTID",
                            "visible": False
                        }
                    ],
                    "title": "Titel1"
                }
            },
            {
                "id": "17cc7332022-layer-2",
                "title": "FeatureLayer2",
                "url": "some-feature-server-url",
                "itemId": "3efe6ee7327e49e59a37406f622db492",
                "layerType": "ArcGISFeatureLayer",
                "popupInfo": {
                    "popupElements": [
                        {
                            "type": "fields"
                        }
                    ],
                    "showAttachments": True,
                    "fieldInfos": [
                        {
                            "fieldName": "objectid",
                            "label": "OBJECTID",
                            "visible": False
                        }
                    ],
                    "title": "Titel2"
                }
            }
        ],
        "layerType": "GroupLayer"
    }
]&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;Now I can get portal Feature Service items and it's FeatureLayer items and I want to:&lt;BR /&gt;1. add another Feature Layer to&amp;nbsp;map_item["operationalLayers"][0]["layers"]&lt;/P&gt;&lt;P&gt;2. or add another group layer with x feature layers&lt;BR /&gt;&lt;BR /&gt;We really need operations for the Python API to compose a webmap and its layers from existing layer items.&lt;/P&gt;</description>
    <pubDate>Thu, 28 Oct 2021 14:58:44 GMT</pubDate>
    <dc:creator>RichardReinicke</dc:creator>
    <dc:date>2021-10-28T14:58:44Z</dc:date>
    <item>
      <title>Python API add group layer to webmap?</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/python-api-add-group-layer-to-webmap/m-p/1112126#M6770</link>
      <description>&lt;LI-CODE lang="python"&gt;map_item["operationalLayers"]&lt;/LI-CODE&gt;&lt;P&gt;Hi,&lt;BR /&gt;&lt;BR /&gt;I have a very general question this time.&lt;BR /&gt;&lt;BR /&gt;The Esri arcgis API is meant to be THE tool to automate workflows and to interact with ArcGIS Portal. But there seem to be a lot of features that are not implemented yet, in my case map authorization.&lt;BR /&gt;&lt;BR /&gt;I have the new webmaps (next gen) and map viewer beta. I can interact with web maps v2 also from the Python API. But I can't create a group layer with API methods.&lt;BR /&gt;&lt;BR /&gt;I can do:&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;map_item.get_data()&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;I see my GroupLayer in the map layers:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;map_item["operationalLayers"]&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;[
    {
        "id": "htsews6tyu0-layer-10010",
        "title": "DummyGroup",
        "layers": [
            {
                "id": "17cc733308b-layer-3",
                "title": "FeatureLayer1",
                "url": "some-feature-server-url",
                "itemId": "d77d046fb6de424da2258a08b376f1fc",
                "layerType": "ArcGISFeatureLayer",
                "popupInfo": {
                    "popupElements": [
                        {
                            "type": "fields"
                        }
                    ],
                    "showAttachments": True,
                    "fieldInfos": [
                        {
                            "fieldName": "objectid",
                            "label": "OBJECTID",
                            "visible": False
                        }
                    ],
                    "title": "Titel1"
                }
            },
            {
                "id": "17cc7332022-layer-2",
                "title": "FeatureLayer2",
                "url": "some-feature-server-url",
                "itemId": "3efe6ee7327e49e59a37406f622db492",
                "layerType": "ArcGISFeatureLayer",
                "popupInfo": {
                    "popupElements": [
                        {
                            "type": "fields"
                        }
                    ],
                    "showAttachments": True,
                    "fieldInfos": [
                        {
                            "fieldName": "objectid",
                            "label": "OBJECTID",
                            "visible": False
                        }
                    ],
                    "title": "Titel2"
                }
            }
        ],
        "layerType": "GroupLayer"
    }
]&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;Now I can get portal Feature Service items and it's FeatureLayer items and I want to:&lt;BR /&gt;1. add another Feature Layer to&amp;nbsp;map_item["operationalLayers"][0]["layers"]&lt;/P&gt;&lt;P&gt;2. or add another group layer with x feature layers&lt;BR /&gt;&lt;BR /&gt;We really need operations for the Python API to compose a webmap and its layers from existing layer items.&lt;/P&gt;</description>
      <pubDate>Thu, 28 Oct 2021 14:58:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/python-api-add-group-layer-to-webmap/m-p/1112126#M6770</guid>
      <dc:creator>RichardReinicke</dc:creator>
      <dc:date>2021-10-28T14:58:44Z</dc:date>
    </item>
    <item>
      <title>Re: Python API add group layer to webmap?</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/python-api-add-group-layer-to-webmap/m-p/1112351#M6771</link>
      <description>&lt;P&gt;I've been able now to accomplish my goal and to add a new group layer with existing feature layers to my web map item. Unfortunatly for this you need to write dictionaries that correspond to Esri web map specification (GroupLayer, FeatureLayer ... )&lt;BR /&gt;&lt;A href="https://developers.arcgis.com/web-map-specification/objects/groupLayer/" target="_blank"&gt;https://developers.arcgis.com/web-map-specification/objects/groupLayer/&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Here are the major parts:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def create_layer_id(layerIndex):
    return ''.join(random.choices(string.ascii_lowercase + \
        string.digits, k=11)) + "-layer-" + str(layerIndex)


# This is my base webmap (template)
map_template = gis.content.get('3095cb51e2a44e818b90608c487f8b3b')

# Copy template to new web map item into subfolder
project_map = WebMap(map_template).save({
    "title": "project map",
    "snippet": "some description",
    "tags": "maps"}, folder="project_folder")

# Create a new group layer following esri web map specification
group_layer = {
    "id": create_layer_id(random.randint(10000, 99999)),
    "layers": [],
    "layerType": "GroupLayer",
    "title": "my new group layer" }

# Get an existing feature service / layer collection item
# get_item() is standard portal item query logic
lyr_item = get_item(lyr_name, "Feature Service", "test")

# Create feature layer following esri web map specification
feature_layer = {
    "id": create_layer_id(random.randint(10000, 99999)),
    "url": lyr_item.layers[0].url,
    "title": lyr_item.layers[0].properties.name,
    "itemId": lyr_item.id,
    "layerType": "ArcGISFeatureLayer" }

# Add feature layer to group layer
group_layer["layers"].append(feature_layer )

# Update project map with new group layer
map_def = project_map.get_data()
map_def["operationalLayers"].append(group_layer)
project_map.update({'text': str(map_def)})&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Maybe this will help someone &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 29 Oct 2021 08:41:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/python-api-add-group-layer-to-webmap/m-p/1112351#M6771</guid>
      <dc:creator>RichardReinicke</dc:creator>
      <dc:date>2021-10-29T08:41:58Z</dc:date>
    </item>
    <item>
      <title>Re: Python API add group layer to webmap?</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/python-api-add-group-layer-to-webmap/m-p/1307283#M8859</link>
      <description>&lt;P&gt;Do you know if the layer id has to be unique? If so, it seems like the randint function wouldn't be the best option, even though it will probably work.&lt;/P&gt;</description>
      <pubDate>Tue, 11 Jul 2023 14:36:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/python-api-add-group-layer-to-webmap/m-p/1307283#M8859</guid>
      <dc:creator>Scoth</dc:creator>
      <dc:date>2023-07-11T14:36:32Z</dc:date>
    </item>
  </channel>
</rss>

