Esri / arcgis-python-api

Documentation and samples for ArcGIS API for Python
https://developers.arcgis.com/python/
Apache License 2.0
1.87k stars 1.1k forks source link

WebMap.add_layer() fails silently on raster published from local .tif in Jupyter Notebook #1484

Closed egorbn closed 1 year ago

egorbn commented 1 year ago

Describe the bug I am using ArcGIS API for Python to publish a local tiff raster to AGOL. I am then creating a local WebMap instance, adding the published raster item to this WebMap, and then saving this WebMap to AGOL. The issue is that the raster is not showing up in the WebMap. No errors or warning are raised in the code, but opening the WebMap in the Map Viewer in AGOL shows the following error message for the raster layer: "An error occurred loading this layer"

To Reproduce

Steps to reproduce the behavior: Python notebook with full steps to reproduce: https://github.com/egorbn/arcgis_api_python_testing/blob/main/raster_ops.ipynb

Screenshots Method 1:

image

Method 2:

image

Method 3:

image

Expected behavior The expected behavior is that the raster item is added to the WebMap and displayed automatically

Platform (please complete the following information):

Additional context

egorbn commented 1 year ago

Update:

I found that the layerType property of the operational layer was, indeed, the issue.

Thanks to https://community.esri.com/t5/arcgis-api-for-python-blog/snippets-to-manage-a-web-map-with-the-arcgis-api/ba-p/1043716

I was able to find a workaround by setting the layer type explicitly in the item data and updating the WebMap item.

The additional code is:

wm1_item_text = wm1_item.get_data()
wm1_item_text["operationalLayers"][0]["layerType"]="ArcGISTiledImageServiceLayer"
wm1_item.update(item_properties={"text":json.dumps(wm1_item_text)})

A notebook with the workaround implemented showing the working method is here: https://github.com/egorbn/arcgis_api_python_testing/blob/main/webmap_text_property.ipynb

Although this workaround is usable, the above bug still stands. add_layer() should know how to set the proper layerType, or give information about why it can't, etc.

Overwriting and updating the text based item properties manually feels like a band-aid.

rhea-j commented 1 year ago

@egorbn I am working on a fix for this. The workaround seems to be good. But yes, we will get the API enhanced to support this. Thanks for reporting.

egorbn commented 1 year ago

Thanks, @rhea-j ! Much appreciated. OK will use the WebMap.update() method for now.

nanaeaubry commented 1 year ago

This is being addressed for the next release :) Thank you for letting us know!