Save a web scene

Loading...

Note: Support for 3D on mobile devices may vary, view the system requirements for more information.

This sample demonstrates how to save a WebScene to an ArcGIS for Portal item by either creating a new item or overwriting an existing item that has been loaded from an ArcGIS for Portal item.

Saving a web scene is easy. All that's required is a WebScene and a valid Portal to save the scene to.

Saving to a new item

Create a new empty WebScene instance and a Portal instance where the WebScene should be saved to. Loading the Portal will trigger user authentication, and if successful the item will be saved to the given Portal.

/************************************************************
* Creates a new empty WebScene instance. An empty WebScene
* must have at least the basemap property defined to be
* functional.
************************************************************/
var scene = new WebScene({
  basemap: "topo"
});

/************************************************************
* Create a new Portal instance and request immediate user
* authentication.
************************************************************/
var portal = new Portal({
  authMode: "immediate"
});

/************************************************************
* Loading the portal will trigger authentication and once the
* returned Promise is resolved, the WebScene will be saved as
* a new PortalItem using the given title.
************************************************************/
portal.load().then(function(){
  scene.saveAs({
    title: "Empty WebScene",
    portal: portal
  });
});

Overwriting an existing item

Create a new WebScene instance and set the portal item ID inside the portalItem property of the WebScene. Loading the Portal will trigger user authentication, and if successful the item will be saved to the given Portal.

/************************************************************
* Creates a new WebScene instance. A WebScene can reference
* a PortalItem ID that represents a WebScene saved to
* arcgis.com or an on-premise portal.
************************************************************/
var scene = new WebScene({
  portalItem: {
    id: "3a9976baef9240ab8645ee25c7e9c096"
  }
});

/************************************************************
* Create a new Portal instance and request immediate user
* authentication.
************************************************************/
var portal = new Portal({
  authMode: "immediate"
});

/************************************************************
* Loading of either the scene or the portal will trigger
* authentication and once both Promises are resolved, the
* Webscene will be saved thereby overwriting the previously
* loaded PortalItem with any changes that have occurred.
************************************************************/
scene.load().then(function(){
  portal.load().then(function(){
    scene.portalItem.title = "Modified WebScene";
    scene.portalItem.portal = portal;
    scene.save();
  });
})

To use load or save items from an on-premise portal, set the URL of the portal in esriConfig.portalUrl.

Please refer to the Working with the ArcGIS Platform for information on how the ArcGIS API for JavaScript makes use of working with portal items.

Sample search results

TitleSample
Loading...