Hi Developers,
Background
I am developing a script to set up a Feature Layer Collection (point, polyline, polygon) including fields and styles. To set the styles, I add a renderer to the lines layer, which works fine (attached image, right side).
# Lines
unique_value_renderer = {
"renderer": {
"type": "uniqueValue",
"field1": "CATEGORY",
"defaultSymbol": {
"color": [0, 0, 255, 255],
"width": 5,
"type": "esriSLS",
},
"uniqueValueInfos": [
{
"value": "Good_Route",
"symbol": {
"color": [0, 255, 0, 255],
"width": 5,
"type": "esriSLS",
},
},
{
"value": "Blocked_Route",
"symbol": {
"color": [255, 0, 0, 255],
"width": 5,
"type": "esriSLS",
},
}
]
}
}
# Set the renderer for the feature layer
fl = FeatureLayer(url=url_lines)
fl.manager.update_definition({"drawingInfo": unique_value_renderer})
My Question
Using ArcGIS Online, I visualize the line feature layer in new Map Viewer, change the styles and save the layer (not a map, but the layer). After doing so, how can I revert back to have my renderer as default style for adding the layer to maps or visualizing the data?
What I tried
fl.manager.update_definition({"web_style_id": None})
Setup
Edit
See attached my Notebook that shows the different behavior. Dev4 section is a Feature Layer Collection to which I made changes in symbology online. My goal is to get Dev4 Variant A running the same way as Dev5.
Solved! Go to Solution.
I found out that manual changes of the symbology get stored in the item data behind the feature layer collection instead of into the collection or the layer. When the item data contains drawing info, the layer's drawing info will be ignored. So, I delete all item drawing info like this:
# Delete item renderers
def delete_items_renderer(url):
# delete all keys in a json object
def delete_key(obj, key):
if isinstance(obj, dict):
if key in obj:
del obj[key]
for k in obj:
delete_key(obj[k], key)
elif isinstance(obj, list):
for item in obj:
delete_key(item, key)
return obj
flc = FeatureLayerCollection(url, gis)
itemid = flc.properties['serviceItemId']
item = Item(gis=gis, itemid=itemid)
data = item.get_data()
data = delete_key(data, "renderer")
# Update the item properties
item.update(data=data)
delete_items_renderer(url_feature_layer_collection)
I found out that manual changes of the symbology get stored in the item data behind the feature layer collection instead of into the collection or the layer. When the item data contains drawing info, the layer's drawing info will be ignored. So, I delete all item drawing info like this:
# Delete item renderers
def delete_items_renderer(url):
# delete all keys in a json object
def delete_key(obj, key):
if isinstance(obj, dict):
if key in obj:
del obj[key]
for k in obj:
delete_key(obj[k], key)
elif isinstance(obj, list):
for item in obj:
delete_key(item, key)
return obj
flc = FeatureLayerCollection(url, gis)
itemid = flc.properties['serviceItemId']
item = Item(gis=gis, itemid=itemid)
data = item.get_data()
data = delete_key(data, "renderer")
# Update the item properties
item.update(data=data)
delete_items_renderer(url_feature_layer_collection)