remove_layer, add_layer from Web Map

1500
3
07-25-2018 09:06 AM
PatrickFilipelli1
New Contributor

Hello - 

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?

Tags (2)
0 Kudos
3 Replies
by Anonymous User
Not applicable

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.

0 Kudos
PatrickFilipelli1
New Contributor

Hello Atma -

Thank you for the response! What is the appropriate way to get a copy of the dictionary and then apply it afterwards?  

0 Kudos
ThomasColson
MVP Frequent Contributor
0 Kudos