Popup and Symbology Automation

Overview

There doesn't appear to be direct support for automating a feature layer's popup or symbology definitions. We know from the functionality of the online map viewer that this is possible through the REST API, and through inspection we've found a workable approach.

The text parameter

When creating or updating an item using the ArcGIS API for Python we can pass JSON in the TEXT parameter. For example:

item = { ... 'text': '{"json": "content"}'} gis.content.add(item_properties=item)

Popups

Popups are defined using the following format for your text JSON, which should be formatted as a one-line string.

text = '{ "layers":[ { "id":0, "popupInfo":{ "title":"Census Division: {{CDNAME}}", "fieldInfos":[ { "fieldName":"OBJECTID", "label":"OBJECTID", "tooltip":"", "visible":false, "stringFieldOption":"textbox" }, { "fieldName":"Shape", "label":"Shape", "tooltip":"", "visible":false, "stringFieldOption":"textbox" }, { "fieldName":"CDUID", "label":"CDUID", "tooltip":"", "visible":true, "stringFieldOption":"textbox" }, ... ], "description":"<div style=\"background-color: lightblue; border: dashed darkblue 1px; color: black;\">html popup: {{CDNAME}}</div>", "showAttachments":true, "mediaInfos":[ ] } }'

Symbology

Symbology is definedusing the following format for your text JSON, which should be formatted as a one-line string.

text = '{ "layers":[ { "id":0, "popupInfo":{...}, "layerDefinition":{ "source":{ "type":"mapLayer", "mapLayerId":0 }, "drawingInfo":{ "renderer":{ "type":"uniqueValue", "field1":"PRNAME", "defaultSymbol":{ "color":[ 170, 170, 170, 255 ], "outline":{ "color":[ 153, 153, 153, 255 ], "width":0.75, "type":"esriSLS", "style":"esriSLSSolid" }, "type":"esriSFS", "style":"esriSFSSolid" }, "defaultLabel":"Other", "uniqueValueInfos":[ { "value":"Quebec / Québec", "label":"Quebec / Québec", "symbol":{ "color":[ 237, 81, 81, 255 ], "outline":{ "color":[ 153, 153, 153, 255 ], "width":0.75, "type":"esriSLS", "style":"esriSLSSolid" }, "type":"esriSFS", "style":"esriSFSSolid" } }, ... ] }, "transparency":50 } }

Sample

A toy popup and symbology have been configured for Census Divisions in this commit. See the last item.

In practice

In practice these JSON strings are had to author to ensure proper syntax and desired results. The suggested approach is to use ArcGIS Portal (sandbox, dev, unshared content) to defined the popup and symbology you desire, and inspect the web traffic to see the JSON that results.

Steps:

  • Add your content to portal

  • Add the layer to a map

  • Edit the popup and symbology as desired

  • Hit F12 and select the network tab

  • Click Save layer on your new layer

  • Inspect the network traffic for an item update request

    • eg. https://devweb.tcgis.ca/portal/sharing/rest/content/users/josh.hevenor/items/1a84ef86cca945368d4c03ac0bf5f434/update

  • Look at the headers->Form data of the update request and capture the JSON needed.