Ok, but highly advise you work on a copy of the feature layer until you get it working correctly (I just re-publish the same project with different name).
View details for the layer, then click on the "View" link in lower right after URL to open the service. Then click on the layer you want to modify, and make note of it's number for later in the script.
Just below the Extent in the service window, you will see Drawing Info: Copy that entire text string, as this is what needs to be modified. Easiest to paste into JSON validator, I used JSONlint, and validate it to make sure it copied correctly.
This will also reformat it so it's easy to read.
Then you need to modify the JSON to make the updates. The label info is part of drawingInfo, so if you have symbology, etc. set in the map, make sure to not change/delete that portion in the JSON or it will go away also.
So, my drawingInfo looked like this originally (everything after "labelingInfo" is the label part) :
{
"drawingInfo": {
"renderer": {
"type": "simple",
"symbol": {
"type": "esriSMS",
"style": "esriSMSCircle",
"color": [140, 39, 165, 255],
"size": 4,
"angle": 0,
"xoffset": 0,
"yoffset": 0,
"outline": {
"color": [0, 0, 0, 255],
"width": 0.69999999999999996
}
}
},
"scaleSymbols": true,
"transparency": 0,
"labelingInfo": [{
"labelExpressionInfo": null,
"labelPlacement": "esriServerPointLabelPlacementAboveRight",
"deconflictionStrategy": "dynamic",
"stackLabel": true,
"stackRowLength": 24,
"stackAlignment": "dynamic",
"removeDuplicates": "none",
"useCodedValues": false,
"maxScale": 0,
"minScale": 0,
"name": "Class 1",
"priority": -1,
"symbol": {
"type": "esriTS",
"color": [0, 0, 0, 255],
"backgroundColor": null,
"borderLineColor": null,
"borderLineSize": null,
"verticalAlignment": "bottom",
"horizontalAlignment": "left",
"rightToLeft": false,
"angle": 0,
"xoffset": 0,
"yoffset": 0,
"kerning": true,
"haloColor": null,
"haloSize": null,
"font": {
"family": "Tahoma",
"size": 10,
"style": "normal",
"weight": "normal",
"decoration": "none"
}
}
}]
}
}
And I left the drawing info in there, but removed the labeling properties so it now looks like ("labelingInfo": null) being the important part here:
{
"renderer": {
"type": "simple",
"symbol": {
"type": "esriSMS",
"style": "esriSMSCircle",
"color": [140, 39, 165, 255],
"size": 4,
"angle": 0,
"xoffset": 0,
"yoffset": 0,
"outline": {
"color": [0, 0, 0, 255],
"width": 0.69999999999999996
}
}
},
"scaleSymbols": true,
"transparency": 0,
"labelingInfo": null
}
Make sure it validates correctly, then strip out the line returns so it is all on a single line or won't be "valid" in the python script, and this is the string I used in the python.
{"renderer": {"type": "simple","symbol": {"type": "esriSMS","style": "esriSMSCircle","color": [140, 39, 165, 255],"size": 4,"angle": 0, "xoffset": 0,"yoffset": 0,"outline": {"color": [0, 0, 0, 255],"width": 0.69999999999999996} }}, "scaleSymbols": true,"transparency": 0,"labelingInfo": null}
This is the code I used in python to make the changes:
from arcgis.gis import GIS
gis = GIS("https://YourOrg.maps.arcgis.com", username = "AdminUser", password = "UserPassword")
layerid = 'dd58573csdfhrdhs83a6b94c5b78cb34'
lay = gis.content.get(layerid)
lay
lay.layers[0]
props = (lay.layers[0])
(props.properties['drawingInfo'])
newprops = '{"renderer": {"type": "simple","symbol": {"type": "esriSMS","style": "esriSMSCircle","color": [140, 39, 165, 255],"size": 4,"angle": 0, "xoffset": 0,"yoffset": 0,"outline": {"color": [0, 0, 0, 255],"width": 0.69999999999999996} }}, "scaleSymbols": true,"transparency": 0,"labelingInfo": null}'
newprops
props.manager.update_definition({'drawingInfo':newprops})
(props.properties['drawingInfo'])
I actually used a python Notebook in Pro to make it easier to cobble together, and report values along the way to ensure I'm working on the right data. Here is the snapshot of the Notebook to give an idea (with some documentation):
Then, make sure you load the test dataset into a map viewer to make sure you didn't break/corrupt anything and you are good to switch the layer ID to the actual dataset instead of the test copy, and run.
R_