Select to view content in your preferred language

Creating a Group Layer Item

243
2
Jump to solution
08-29-2024 07:36 AM
Labels (1)
Desharin
New Contributor

I've been trying to add a Group Layer to ArcGIS Online using the Python API, but my attempts have only been partly succesful. Below you'll find some code similar to what I've been doing. I've used the Group Layer spec as shown here.

 

from arcgis import GIS
import json
gis = GIS(url = AGO_URL, username = AGO_USER, password = AGO_PASS)

itemProperties = {
    'type': 'Group Layer',
    'description': 'Some Description',
    'title': 'Some Title',
    'tags': ['Tag1', 'Tag2'],
    'snippet': 'Some Snippet',
    'accessInformation': 'Some Access Information',
    'licenseInfo': 'Some License Info',
    'commentsEnabled': False,
    'access': 'org',
    'text': json.dumps(
        {
            "id": "groupLayer",
            "layerType": "GroupLayer",
            "title": "US Census",
            "layers": [
                {
                    "id": "Census_6999",
                    "title": "Census - states",
                    "url": "https://sampleserver6.arcgisonline.com/arcgis/rest/services/Census/MapServer/3",
                    "layerType": "ArcGISFeatureLayer"
                },
                {
                    "id": "Census_616",
                    "title": "Census - Detailed Counties",
                    "url": "https://sampleserver6.arcgisonline.com/arcgis/rest/services/Census/MapServer/2",
                    "layerType": "ArcGISFeatureLayer"
                }
            ]
        }
    )
}

gis.content.add(
    item_properties = itemProperties,
    thumbnail = 'Some thumbnail url',
    metadata = None,
    owner = None,
    folder = None
)

  

This will successfully add the item as a Group Layer to ArcGIS Online, with title, description, etc. all working. The 2 layers will also show up as layers in the item. However, if I open the item in the Map Viewer, no layers will be shown.

Please advise.

1 Solution

Accepted Solutions
Clubdebambos
Frequent Contributor

Hi @Desharin 

Add the following typeKeywords to your itemProperties.

    "typeKeywords": [
        "ArcGIS API for JavaScript",
        "Group Layer",
        "Map"
    ]

 

There is also no need for json.dumps in the "text" property.

Let me know if that works for you?

Cheers,

Glen

 

~ learn.finaldraftmapping.com

View solution in original post

2 Replies
Clubdebambos
Frequent Contributor

Hi @Desharin 

Add the following typeKeywords to your itemProperties.

    "typeKeywords": [
        "ArcGIS API for JavaScript",
        "Group Layer",
        "Map"
    ]

 

There is also no need for json.dumps in the "text" property.

Let me know if that works for you?

Cheers,

Glen

 

~ learn.finaldraftmapping.com
Desharin
New Contributor

Sorry for the late response, but this seems  to work! Thank you very much!