Get drawing info (symbology/renderer) of a WebMap layer and apply it to a hosted feature layer view layer

222
1
Jump to solution
04-17-2024 06:42 AM
Dirk_Vandervoort
New Contributor III

In ArcGIS Online:

I have a WebMap with layers, that consumes directly from a hosted feature layer. I also have a hosted feature layer view that consumes directly from the same hosted feature layer. There is a corresponding layer between the hosted feature layer view and the WebMap.

I would like to take the symbology from the layer in the WebMap and apply it to the layer in the hosted feature layer view. I need to do this about a thousand times.

My code looks pretty simple, it returns a success, the hosted feature layer view indicates that is has been updated. However, there is no visible change to the rendering of the layer in the hosted feature view.

 

webmap_item = gis.content.get('UggaBuggaUggaBuggaUggaBugga') #  WebMap 
webmap = WebMap(webmap_item)
source_hfl_sublayer = webmap.layers[2].layers[39] # SOURCE webmap layer

target_hflv = gis.content.get('ChunkyMonkeyChunkyMonkey') #  Hosted Feature Layer View

target_hflv_sublayer = target_hflv.layers[2] # TARGET hosted feature layer view

the_layer_definition = source_hfl_sublayer.layerDefinition
source_drawingInfo = the_layer_definition['drawingInfo'] # dict instead of a PropertyMap get accepted by update_definition
result = target_hflv_sublayer.manager.update_definition({'drawingInfo':source_drawingInfo})

 

For reference, this post is close, but does not use a webmap as a source.

My question is: how to I get there from here?

TIA as always.

1 Solution

Accepted Solutions
GIS_utahDEM
Occasional Contributor II

Hello, I believe this could be fixed using a similar solution to this question. Here is a pared down version of a  similar process that worked for me:

layer_data=ucip_locs.get_data()
drawingInfo = layer_data["layers"][0]["layerDefinition"]["drawingInfo"]

view_search = my_agol.content.search(view_name)[0]
view_layer = view_search.get_data()
view_layer["layers"][0]["layerDefinition"]["drawingInfo"]=drawingInfo

update_dict = {}
update_dict = {"text":json.dumps(view_layer)}
view_search.update(update_dict)

 

View solution in original post

1 Reply
GIS_utahDEM
Occasional Contributor II

Hello, I believe this could be fixed using a similar solution to this question. Here is a pared down version of a  similar process that worked for me:

layer_data=ucip_locs.get_data()
drawingInfo = layer_data["layers"][0]["layerDefinition"]["drawingInfo"]

view_search = my_agol.content.search(view_name)[0]
view_layer = view_search.get_data()
view_layer["layers"][0]["layerDefinition"]["drawingInfo"]=drawingInfo

update_dict = {}
update_dict = {"text":json.dumps(view_layer)}
view_search.update(update_dict)