Save a map

You can create a map by building a brand new map or by opening an existing map, as described in Display a map. Once constructed, the map includes both properties, for example:

  • Map title and description
  • Copyright information
  • A thumbnail image
  • Ratings

and map content, for example:

  • The map's basemap
  • A list of operational layers
  • Information about layer visibility and rendering
  • Layer scale thresholds
  • The map's initial viewpoints

No matter how you create this map you can save it either as a brand new map or, if you have made any changes to the map, you can save it back to its original map. This topic describes how to save a brand new map and how to save back any changes you've made to an existing map.

Save a new map to a portal

When you save a new map to the portal you will create a new portal item with a type of WebMap that has a new unique item ID. The new portal item will be placed in the My Content area of the user that was authenticated with the portal. When you save the map for the first time you must provide at least a map title and a loaded portal object. You can also set these properties if you wish.

  • Tags—an array of tag strings to be used when users search for maps in ArcGIS Online or Portal for ArcGIS.
  • Folder—a portal folder in which the map will be placed in My Content. By default the map will be saved to the user's root folder.
  • Description—a description of the map.
  • Thumbnail—an image ( via URL) that will be associated with the portal item and is shown on the portal item details page in ArcGIS Online or Portal for ArcGIS.
  • Force save to supported version—a boolean flag to indicate whether or not the map should be saved as the web map version supported by the API. This may cause data loss, as data unknown to the supported format will be lost when the map is saved.

The following JavaScript example shows how to save a map as a PortalItem object.

Save the map.

map1.saveAsNewPortalItem();

Then, get the new PortalItem from the result.

if (map1.saveAsNewPortalItemResult !== null) {
  portalItem = map1.saveAsNewPortalItemResult; 
}

Access the map's item properties

After the map saving has completed, the map’s portal item property is populated with the brand new portal item properties. You can access all of the properties and set any of the writeable properties, as you require.

If you wish to save any of these properties, call the map's save method as described in the following section.

Share the map

After the map has been saved to the portal, the map is available to share with other portal users. See the share a portal item topic for more information.

Save changes to an existing web map

If you have opened a map, made changes to the map content or properties, and you want to save changes back to that map, then call the asynchronous save method on the map. This method, of course, requires that the map has been previously saved to the portal and an exception will be raised if it has not. If a layer in your map allows users to edit offline, be sure to sync their edits in addition to saving the map.

Save the map in your JavaScript function.

map1.save();

In a handler for the signal saveStatusChanged check the map property saveStatus to see whether the save was successful.

if (map1.saveStatus === Enums.TaskStatusErrored) {
// ... handle the error
}