Hello All,
I'm trying to replace a FeatureLayer in an WebMap and retain all the layerDefinition, popupInfo, title, etc.
At first I just tried replacing the layer's url property with the new feature service URL but that didn't work.
Then I tried the remove_layer/add_layer as described in the Samples. Although the Feature Layer was updated with this approach, none of the popupInfo or layerDefintion information was. (code snippet below).
How can I transfer the attributes from the old layer to the new? Going through the UI to re-create the popup, symbology, etc. is not practical.
Thanks!
title = layer_to_be_replaced.title
layerDefinition = layer_to_be_replaced.layerDefinition
popupInfo = layer_to_be_replaced.popupInfo
webmap.remove_layer(layer_to_be_replaced)
webmap.add_layer(replacement_layer, options = {
'title': title,
'popupInfo': popupInfo,
'showLegend': True,
'layerDefinition': layerDefinition
})
webmap.update()