Hi Folks,
I created two webmaps with some views for editing control. One webmap is used by the field crew to census trees. This webmap contains labels with 3 attributes:
$feature.TAG + " - " + $feature.SPP + " - " + $feature["DBH_DAP"]
I saved the original map AS another webmap, which is used by supervisors. To make their work easy, the label for the trees needs to have 6 fields concatenated:
$feature.TAG + " - " + $feature.SPP + " - " + $feature["DBH_DAP"]
+ " - " + $feature["DBH_DAP2022"] + " - " + $feature.CODES
+ " - " + $feature.CODES2022
When opening the Supervisors map, the labels are shown perfectly (see the attached image named Labels_Online.jpg) when in online mode. If we take the same map offline and the open it, the labels default to other labels (see the Labels_Offline.jpg).
Is the saved map using a default label for this layer? Why is not using the labels defined on the map? Is there a limit on the number of fields used to create a label?
Thanks!
Milton
Solved! Go to Solution.
Hi @RhettZufelt ,
Thank you for looking into this issue. It seems like a bug and you basically can't fix it without deleting and re-publishing the layers. It happened once with a domain for a field: I wasn't able to delete the domain and had to delete de FC and re-create everything again.
I edited the JSON definition directly for the FC and Views with no luck. After updating the FC JSON definition, I created another view (to inherit the new definition) and the labels problem persist. I think is more than just editing the FC JSON definition.
Your findings were correct and I tried that way. The solution then is to re-publish the FC, recreate the views, maps, smart forms, etc. Thank you for your time!
Trying to update the JSON definition in REST, I get success result, but, when you reload and look at it, the update doesn't take affect.
Further testing shows that the Python API manager.update_definition on the drawingInfo will let you clear the labeling schema from the feature service. This way, don't have to re-publish everything.
R_
I'm really interested in learning how to clear the default labeling issue rather than having to recreate everything. Can you show me how to use the Python API to clear the labeling issue?
I'll really appreciate this.
Milton
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_
My man! I owe you a couple of beers. I couldn't figured it out by myself in a million years. Lessons learned through your help:
1. Never publish a Feature class with Labels defined from ArcGIS Pro. It's a headache.
2. JSON Lint. Thank you for sharing this tool.
3. A real world example to use Notebooks. I used AGOL Notebooks to make these changes instead of ArcGIS Pro.
4. I executed the Python code against the Feature Layer (the original layer) and the 3 Views created from there. Although, the original layer changed the definition, the views kept the original one. After running the notebook, I checked the REST endpoints and the Drawing Info was changed.
Now the labels are showing just fine on FieldMaps online and offline.
Sometimes I feel a little bit dismayed by the amount of tools we need to know in order to have everything running top notch (ArcGIS Pro, Cartography, Coordinate systems, Symbology, AGOL, FieldMaps, JSON, Python, REST manipulation, Ecology, maths, logic, etc. Thanks God there's people like you, available to help other people.