I've come across what I believe to be a bug in ArcGIS Javascript API versions 4.16 or greater. I have a simple webscene with elevation layer, basemap and tiled aerial imagery layer. The elevation and aerial imagery were created in Pro using Manage Tiles Cache, then exported to .tpkx, shared with Portal and published through the Portal interface. The web scene works perfectly in the Scene Viewer:
However when I load the same webscene using the Javascript API I get an Invalid layer item type 'Map Service', expected 'Image Service' error, and the aerial imagery does not display:
Here's a CodePen showing the error: https://codepen.io/TimMcG/pen/yLEXweG (just using the Load A Basic Web Scene sample, with config for my portal)
If you change the API version to 4.15 it works, but 4.16 or later shows the error.
ArcGIS Enterprise \ Portal version is 10.8.1.
Why it's a bug:
Well, the web scene works perfectly well in Scene Viewer. It's created in the standard way using Pro and Portal - I really can't do anything differently on my side of things. The fault is clearly with the Javascript API being unable to display my scene. And 10.8.1 and 4.16 were released in the same month, so they should work together.
Thanks for any assistance.
Solved! Go to Solution.
Just adding to above reply, which adequately explains the problem.
As far as I can tell from the data, the bug was in SceneViewer 10.8.1, which somehow wrote the wrong layerType into the webscene json. How and why this happened is hard to track down now.
This combination still worked with the less strict API 4.15, but is now "correctly" rejected with API >= 4.16.
As mentioned, one way to fix it is to manually adjust the webscene json:
change
"layerType": "ArcGISTiledImageServiceLayer"
to
"layerType": "ArcGISTiledMapServiceLayer"
. This can be done with https://ago-assistant.esri.com/ for example.
Option 2, likely simpler: delete and re-add the problematic layer in SceneViewer, and resave the webscene.
Yes, this is a bug. It should be the wrong type of this layer recorded in the webscene. Maybe you can go to the \arcgisportal\content\items directory to find the corresponding item of the webscene and modify the content of this item file.
There is no problem with the version before 4.16 because ImageryTileLayer was added in version 4.16. If the layer type is recorded incorrectly on the server side, it affects client-side layer loading from version 4.16 onwards.
Just adding to above reply, which adequately explains the problem.
As far as I can tell from the data, the bug was in SceneViewer 10.8.1, which somehow wrote the wrong layerType into the webscene json. How and why this happened is hard to track down now.
This combination still worked with the less strict API 4.15, but is now "correctly" rejected with API >= 4.16.
As mentioned, one way to fix it is to manually adjust the webscene json:
change
"layerType": "ArcGISTiledImageServiceLayer"
to
"layerType": "ArcGISTiledMapServiceLayer"
. This can be done with https://ago-assistant.esri.com/ for example.
Option 2, likely simpler: delete and re-add the problematic layer in SceneViewer, and resave the webscene.
Thanks Andreas - that did the trick. Unfortunately whenever you save the web scene it changes it back to ArcGISTiledImageServiceLayer. We are currently upgrading from 10.8.1 to 11 so hopefully that will fix the issue with Scene Viewer.
Thanks for getting back Tim.
Yes, this problem is supposed to be gone with 11. Please let us know in case you still have issues.