I have published a Web Map that I have styled in Pro and am trying to figure out a workflow to keep the web map and update the feature layer.
My workflow looks like this:
Publish map from pro to AGOL -> make changes to symbology, pop ups etc in pro -> remove layer from web map->overwrite the layer->add layer back to map ->finish.
The issue is that the added layer no longer holds any of the symbology, pop up information, extents, etc. that were defined in Pro.
This is curious to me because if I were to manually remove each layer and re-add them in the map it works fine; however, using remove_layer and add_layer with the API doesn't do the same.
Can this be accomplished?
Hello Patrick, this is an interesting question. In short, this is a limit that is by design. The reason is, unlike and application (like Pro or web app viewer), the Python API (since it is an API), does not "remember" the symbology and renderers of a layer once you remove it. All render info is stored in the layer dictionary and when you make an API call to remove it, you lose it.
Can you workaround it? Sure, you can. Before you call the remove_layer, just get a copy of its dictionary. After you call the add_layer, update it by applying the parts from the older layer. You need to be careful as your new layer may have fields with different names, and such differences. Hope this helps.