ArcGIS Runtime SDK for Android

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 ArcGIS Enterprise.
  • Folder—a portal folder (PortalFolder) 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 ( byte array containing raw data for an image) that will be associated with the portal item and is shown on the portal item details page in ArcGIS Online or ArcGIS Enterprise.
  • 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 example illustrates saving a new map with the asynchronous saveAsAsync method call, and getting the new PortalItem from the method's future.

// Define a set of tags for the new map
ArrayList<String> tags = new ArrayList<>(4);
tags.add("Forest Management");
tags.add("Wildlife");
tags.add("Conservation");
tags.add("Avian");

// Save the map to an authenticated Portal, with specified title, tags, description, and thumbnail.
// Passing 'null' as portal folder parameter saves this to users root folder.
final ListenableFuture<PortalItem> saveAsFuture = map.saveAsAsync(portal, null, "Forest management for the Great " +
    "Gray Owl", tags, "Their breeding habitat is the dense coniferous forests of the taiga..", thumbnailDataArray, true);
saveAsFuture.addDoneListener(new Runnable() {
  @Override
  public void run() {
    // Check the result of the save operation.
    try {
      newMapPortalItem = saveAsFuture.get();
      showMessage("Map saved");
    } catch (InterruptedException | ExecutionException e) {
      // If saving failed, deal with failure depending on the cause...
      dealWithException(e);
    }
  }
});

You can use an Android Drawable to create a byte array to use as the thumbnail for the new portal item as shown below.

// Get a Drawable to use as the default thumbnail and convert to byte[].
Drawable drawable = getResources().getDrawable(R.drawable.webmap_thumbnail);
Bitmap bitmap = ((BitmapDrawable)drawable).getBitmap();
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);
byte[] thumbnailDataArray = stream.toByteArray();

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.

// Report current properties of the PortalItem of the Map.
SimpleDateFormat localDateFormat = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault());
localDateFormat.setTimeZone(TimeZone.getDefault());
String modifiedDate = localDateFormat.format(map.getItem().getModified());
String itemId = map.getItem().getItemId();
showMessage(String.format("Item '%s' was modified on %s", itemId, modifiedDate));

// Make changes to the properties as required.
map.getItem().setTitle("A brand new title");
map.getItem().setSnippet("A short description to be included in the UI");

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.

// Setting forceSaveToSupportedVersion parameter to true means any unknown data in the map will not be saved.
final ListenableFuture<PortalItem> mapSaveFuture = map.saveAsync(true);
mapSaveFuture.addDoneListener(new Runnable() {
  @Override
  public void run() {
    // Check the result of the save operation.
    try {
      newMapPortalItem = mapSaveFuture.get();
      showMessage("Map changes saved");
    } catch (InterruptedException | ExecutionException e) {
      // If saving failed, deal with failure depending on the cause...
      dealWithException(e);
    }
  }
});