Save a web map

This sample demonstrates how to save a WebMap to a Portal for ArcGIS item by creating a new item. Saving a web map is easy. All that's required is a WebMap and a valid Portal to save the map to.

Saving to a new item

Create a new empty WebMap instance or load an existing web map in your application. To save an existing webmap as a new portal item call saveAs() method. This saves the web map to a new portal item. Saving will trigger user authentication, and if successful the item will be saved to the given Portal.

Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
/************************************************************
 * Creates a new WebMap instance. A WebMap can reference
 * a PortalItem ID that represents a WebMap saved to
 * arcgis.com or an on-premise portal.
 ************************************************************/
const webmap = new WebMap({
  portalItem: {
    id: "06ca49d0ddb447e7817cfc343ca30df9"
  },
});

// Update properties of the WebMap related to the view.
// This should be called just before saving a webmap.
webmap.updateFrom(viewElement.view).then(() => {
  webmap.saveAs(item).then((item) => {
    console.log("WebMap saved successfully");
   })
   // Save didn't work correctly
   .catch((error) => {
     console.error("Webmap did not save.")
   });
});

Please refer to the ArcGIS Organization portals for information on how the ArcGIS Maps SDK for JavaScript makes use of working with portal items.

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.