This sample demonstrates how to save a new or previously loaded web scene to ArcGIS Online or an ArcGIS Enterprise Portal.
Create or load a scene
Use the Scene component to create a new scene or load an existing web scene. When loading a web scene from ArcGIS Online, providing its
// Url of the Portal or the ArcGIS Online organizationconfig.portalUrl = "https://myorg.com/portal";Retrieve a reference to the Scene component from the DOM:
const viewElement = document.querySelector("arcgis-scene");// Wait for the view to fully initialize.await viewElement.viewOnReady();// Get a reference to the WebScene.const scene = viewElement.map;Just before saving, you can choose to update the scene’s properties from the current view state (camera, environment, basemap, etc.):
await scene.updateFrom(viewElement.view);Save as a new item
A previously loaded web scene includes a unique item ID, title, and other metadata. When saved using saveAs(), a new portal item is created and assigned a unique item ID, while the existing properties are copied to the new item. If you are saving a new web scene that does not yet exist as a portal item, or want to update metadata such as the title, tags, or description of an existing scene, create a PortalItem and update or specify the desired properties before saving.
// Item automatically casts to a PortalItem instance when passed to saveAs().const item = { title: "My new web scene", tags: ["tag1", "tag2", "..."],};Now you can save the web scene as a new portal
try { // Using saveAs(item) will create a new portal item. const portalItem = await scene.saveAs(item); // Saved successfully // ... console.log(`"${portalItem.title}" saved successfully!`);} catch (error) { // Save didn't work correctly, learn why // ... console.error(error.details);}If you were not authenticated beforehand, the saveAs() method will trigger authentication, which must be completed before the web scene is successfully saved.
Overwriting an existing item
Overwriting an existing item assumes you are working within a single portal and have loaded an existing web scene (that already has an item ID). Use the PortalItem to modify the desired property of the existing web scene, then use save() method, to overwrite it.
try { // Rename the web scene's title scene.portalItem.title = "Modified WebScene"; // Using save() will overwrite the existing scene. const portalItem = await scene.save(); // Saved successfully // ... console.log(`"${portalItem.title}" saved successfully!`);} catch (error) { // Save didn't work correctly // ... console.error(error);}For more information on how the