Class OfflineMapTask

java.lang.Object
com.esri.arcgisruntime.tasks.offlinemap.OfflineMapTask
All Implemented Interfaces:
RemoteResource, Loadable

public final class OfflineMapTask extends Object implements Loadable, RemoteResource
A task used to take a map offline. Taking a map offline involves downloading an online map and its data, including all the supported layers, tables, renderers, web map configuration etc. so that it can be used offline without a network connection.

There are two workflows available for taking maps offline:

  • the ahead-of-time workflow (also sometimes referred to as the preplanned workflow)
  • the on-demand workflow

Ahead-of-time workflow - In this workflow the author of a web map defines geographical areas (offline map areas) to take offline. ArcGIS Online, or ArcGIS Enterprise, uses these to prepare offline map content that is stored online. Download the offline map content to a device using the DownloadPreplannedOfflineMapJob. Note that this API refers to an offline map area as a PreplannedMapArea. For more information about authoring offline map areas, see Take web maps offline.

On-demand workflow - Here the app passes a specific area of interest to a GenerateOfflineMapJob to generate and download the map content to the device. Using this workflow, you can choose to keep online only services (e.g. those that require a network connection) in your offline map. Be aware that an offline map which uses online only services will require a network connection and may require authentication.

Since:
100.1.0
  • Property Details

  • Constructor Details

    • OfflineMapTask

      public OfflineMapTask(ArcGISMap onlineMap)
      Creates the offline map task for the provided online map. The online map must represent a web map.

      The online map must be of type PortalItem.Type.WEBMAP, either on ArcGIS Online or an on-premise ArcGIS Enterprise Portal.

      Parameters:
      onlineMap - an ArcGISMap that represents a web map
      Throws:
      IllegalArgumentException - if onlineMap is null
      IllegalArgumentException - if onlineMap is not a web map
      Since:
      100.1.0
    • OfflineMapTask

      public OfflineMapTask(PortalItem portalItem)
      Creates the offline map task with the provided portal item. The portal item must represent a web map.

      The PortalItem must be of type PortalItem.Type.WEBMAP, either on ArcGIS Online or an on-premise ArcGIS Enterprise Portal.

      Parameters:
      portalItem - a portal item that represents a web map
      Throws:
      IllegalArgumentException - if portalItem is null
      Since:
      100.1.0
      See Also:
  • Method Details

    • setCredential

      public void setCredential(Credential credential)
      Sets the credential used to authenticate the user with this task.
      Specified by:
      setCredential in interface RemoteResource
      Parameters:
      credential - the credential used to authenticate the user with this task
      Since:
      100.1.0
    • getCredential

      public Credential getCredential()
      Gets the credential used to authenticate the user with this task.
      Specified by:
      getCredential in interface RemoteResource
      Returns:
      the credential, or null if there is none
      Since:
      100.1.0
    • setRequestConfiguration

      public void setRequestConfiguration(RequestConfiguration requestConfiguration)
      Sets configuration parameters used for network requests sent using this task. The global RequestConfiguration is used if no RequestConfiguration is set.
      Specified by:
      setRequestConfiguration in interface RemoteResource
      Parameters:
      requestConfiguration - contains the parameters to use
      Since:
      100.1.0
    • getRequestConfiguration

      public RequestConfiguration getRequestConfiguration()
      Gets the RequestConfiguration object in use by this task.
      Specified by:
      getRequestConfiguration in interface RemoteResource
      Returns:
      the RequestConfiguration object, or null if none has been set
      Since:
      100.1.0
      See Also:
    • getUri

      public String getUri()
      Gets the URI of this task. This is the URI of the online map.
      Specified by:
      getUri in interface RemoteResource
      Returns:
      the URI of this task; may be null if the task is not loaded
      Since:
      100.1.0
    • getOnlineMap

      public ArcGISMap getOnlineMap()
      Gets the online map associated with this task.

      The online map will be of type PortalItem.Type.WEBMAP, either on ArcGIS Online or an on-premise ArcGIS Enterprise Portal.

      Returns:
      the online map; may be null if the task is not loaded
      Since:
      100.1.0
    • getPortalItem

      public PortalItem getPortalItem()
      Gets the portal item for the online map associated with this task.

      The PortalItem will be of type PortalItem.Type.WEBMAP, either on ArcGIS Online or an on-premise ArcGIS Enterprise Portal.

      Returns:
      the portal item, or null if none
      Since:
      100.1.0
    • createDefaultGenerateOfflineMapParametersAsync

      public ListenableFuture<GenerateOfflineMapParameters> createDefaultGenerateOfflineMapParametersAsync(Geometry areaOfInterest)
      Executes an asynchronous operation to create a set of default parameters that can be used to take an online map offline. The result is a GenerateOfflineMapParameters object.

      The supported geometry types for the area of interest are Envelope and Polygon. The area of interest must have a spatial reference.

      Where a Polygon is supplied, features and tiles will be filtered according to the polygon geometry, which can help reduce the size of the resulting offline map. Note that the filtered set of tiles may vary, depending on the underlying service.

      In the resultant GenerateOfflineMapParameters:

      • minScale and maxScale are zero, which will cause the full range of scales supported by the service to be taken offline
      • the itemInfo is initialized from the offline map task's portal item
      • the itemInfo's thumbnail is copied from the portal item's thumbnail

      If the map being taken offline contains a UtilityNetwork and is in an ArcGIS Enterprise 11.1 or later service, the Offline Capability selected for the UtilityNetwork such as "Trace utility network features" will automatically be reflected in the default parameters created by this method. If the map being taken offline contains an UtilityNetwork and is in an earlier version of ArcGIS Enterprise, the GenerateGeodatabaseParameters.getUtilityNetworkSyncMode() is set to UtilityNetworkSyncMode.SYNC_SYSTEM_TABLES for the Geodatabase containing the UtilityNetwork. Use createGenerateOfflineMapParameterOverridesAsync(GenerateOfflineMapParameters) to change the UtilityNetworkSyncMode if desired.

      Parameters:
      areaOfInterest - the region of the online map that is to be taken offline; must be an Envelope or a Polygon and must have a spatial reference
      Returns:
      a ListenableFuture for tracking when the operation is done and getting the result; also allows cancellation. Calling get() on the returned future may throw an ExecutionException with its cause set to:
      Throws:
      IllegalArgumentException - if areaOfInterest is null
      Since:
      100.1.0
      See Also:
    • createDefaultDownloadPreplannedOfflineMapParametersAsync

      public ListenableFuture<DownloadPreplannedOfflineMapParameters> createDefaultDownloadPreplannedOfflineMapParametersAsync(PreplannedMapArea preplannedMapArea)
      Executes an asynchronous operation to create a DownloadPreplannedOfflineMapParameters from the specified PreplannedMapArea.

      A convenience method to create DownloadPreplannedOfflineMapParameters with default values appropriate for taking the specified map area offline. The parameters will be populated using the values in the online map's OfflineSettings (if present).

      Parameters:
      preplannedMapArea - the offline map area that is to be downloaded from the online map
      Returns:
      a ListenableFuture for tracking when the operation is done and getting the result
      Throws:
      IllegalArgumentException - if preplannedMapArea is null
      Since:
      100.5.0
    • createDefaultGenerateOfflineMapParametersAsync

      public ListenableFuture<GenerateOfflineMapParameters> createDefaultGenerateOfflineMapParametersAsync(Geometry areaOfInterest, double minScale, double maxScale)
      Executes an asynchronous operation to create a GenerateOfflineMapParameters from the specified area of interest, min scale, and max scale.

      The supported geometry types for the area of interest are Envelope and Polygon. The area of interest must have a spatial reference.

      Where a Polygon is supplied, features and tiles will be filtered according to the polygon geometry, which can help reduce the size of the resulting offline map. Note that the filtered set of tiles may vary, depending on the underlying service.

      The returned GenerateOfflineMapParameters has its ItemInfo (see GenerateOfflineMapParameters.getItemInfo()) property initialized from the offline map task's portal item, if that is set. The ItemInfo's thumbnail will be copied from the portal item's thumbnail.

      If the online map contains an UtilityNetwork in the ArcGISMap.getUtilityNetworks(), the GenerateGeodatabaseParameters.getUtilityNetworkSyncMode() property is set to UtilityNetworkSyncMode.SYNC_SYSTEM_TABLES. This will include all the data layers and tables in the feature service in the GenerateGeodatabaseParameters.getLayerOptions(). The feature data of each layer or table is filtered by an area of interest if they are already part of the map, or by GenerateLayerOption.QueryOption.NONE if they are not. This allows the UtilityNetwork to query associations offline. To also enable tracing offline, you may use the result of createGenerateOfflineMapParameterOverridesAsync(GenerateOfflineMapParameters) to explicitly set GenerateGeodatabaseParameters.getUtilityNetworkSyncMode() to UtilityNetworkSyncMode.SYNC_SYSTEM_AND_TOPOLOGY_TABLES. Alternatively, you may set GenerateGeodatabaseParameters.getUtilityNetworkSyncMode() to UtilityNetworkSyncMode.NONE or clear ArcGISMap.getUtilityNetworks() before calling this method to opt-out of the necessary and automatic inclusion of data or system layers that permit an UtilityNetwork to function offline.

      The default parameters will be populated using the values in the online map's OfflineSettings (if present).

      Parameters:
      areaOfInterest - a Geometry defining the area of interest; must be an Envelope or a Polygon and must have a spatial reference. See GenerateOfflineMapParameters.setAreaOfInterest(Geometry).
      minScale - the minimum scale for offline tile caches. Use 0 to select all far out levels (those which are less detailed than the maxScale). See GenerateOfflineMapParameters.setMinScale(double).
      maxScale - the maximum scale for offline tile caches. Use 0 to select all closer in levels (those which are more detailed than the minScale). See GenerateOfflineMapParameters.setMaxScale(double).
      Returns:
      a ListenableFuture for tracking when the operation is done and getting the result
      Throws:
      IllegalArgumentException - if areaOfInterest is null, or minScale or maxScale is negative
      Since:
      100.5.0
    • createGenerateOfflineMapParameterOverridesAsync

      public ListenableFuture<GenerateOfflineMapParameterOverrides> createGenerateOfflineMapParameterOverridesAsync(GenerateOfflineMapParameters parameters)
      Executes an asynchronous operation to create a GenerateOfflineMapParameterOverrides object that is populated to reflect the values in the provided GenerateOfflineMapParameters. The overrides may be inspected and modified to change the offline data before creating a job with generateOfflineMap(GenerateOfflineMapParameters, String, GenerateOfflineMapParameterOverrides).

      If there are errors with loading individual layers or tables, or they cannot be taken offline due to service settings, the outcome depends on the value of GenerateOfflineMapParameters.isContinueOnErrors():

      • If isContinueOnErrors is true, the overrides correspond to the remaining layers and tables that can go offline. The resulting offline map will not contain the layers or tables which had errors.
      • If isContinueOnErrors is false, this operation will fail and calling get() on the returned future will throw an ExecutionException with its cause set to the layer or table error that caused the failure.

      To check upfront which layers or tables are valid for taking offline see getOfflineMapCapabilitiesAsync(GenerateOfflineMapParameters).

      If the reference basemap directory is set (see GenerateOfflineMapParameters.setReferenceBasemapDirectory(String)), the overrides corresponding to online basemap layers will be omitted, since no basemap layers will be downloaded.

      Parameters:
      parameters - the GenerateOfflineMapParameters from which the overrides will be populated
      Returns:
      a ListenableFuture for tracking when the operation is done and getting the result; also allows cancellation. Calling get() on the returned future may throw an ExecutionException with its cause set to:
      Throws:
      IllegalArgumentException - if parameters is null
      Since:
      100.4.0
    • getOfflineMapCapabilitiesAsync

      public ListenableFuture<OfflineMapCapabilities> getOfflineMapCapabilitiesAsync(GenerateOfflineMapParameters parameters)
      Executes an asynchronous operation to get the OfflineMapCapabilities containing information on which layers will be included in an offline map.
      Parameters:
      parameters - the parameters to be used for taking the map offline
      Returns:
      a ListenableFuture for tracking when the operation is done and getting the result; also allows cancellation. Calling get() on the returned future may throw an ExecutionException with its cause set to:
      Throws:
      IllegalArgumentException - if parameters is null
      Since:
      100.1.0
    • generateOfflineMap

      public GenerateOfflineMapJob generateOfflineMap(GenerateOfflineMapParameters parameters, String downloadDirectoryPath)
      Creates a GenerateOfflineMapJob that can be used to generate an offline map from an online map, using the specified parameters. The job will fail if the last directory in the download directory path cannot be created or is not empty.
      Parameters:
      parameters - the parameters to be used for the generate offline map operation
      downloadDirectoryPath - The path to a folder where the map content is stored on the device. For example, to create a new mobile map package my_mobile_map_package in a parent directory [my root path]/my_mobile_maps, this property would be [my root path]/my_mobile_maps/my_mobile_map_package.
      Returns:
      a GenerateOfflineMapJob that will generate the offline map. The result is a GenerateOfflineMapResult object if the job completed successfully. Note you must call Job.start() to start the Job.
      Throws:
      IllegalArgumentException - if parameters is null, or if downloadDirectoryPath is null or empty
      Since:
      100.1.0
    • generateOfflineMap

      public GenerateOfflineMapJob generateOfflineMap(GenerateOfflineMapParameters parameters, String downloadDirectoryPath, GenerateOfflineMapParameterOverrides parameterOverrides)
      Creates a GenerateOfflineMapJob that can be used to generate an offline map from an online map, using the specified parameters and overrides. The job will fail if the last directory in the download directory path cannot be created or is not empty.

      The GenerateOfflineMapParameterOverrides allows more control over the extracted data. Use createGenerateOfflineMapParameterOverridesAsync(GenerateOfflineMapParameters) to create an instance of GenerateOfflineMapParameterOverrides.

      Some properties on GenerateOfflineMapParameters will be ignored when using GenerateOfflineMapParameterOverrides and replaced with equivalent properties for each service. The overridden properties are:

      Parameters:
      parameters - the parameters to be used for the generate offline map operation
      downloadDirectoryPath - The path to a folder where the map content is stored on the device. For example, to create a new mobile map package my_mobile_map_package in a parent directory [my root path]/my_mobile_maps, this property would be [my root path]/my_mobile_maps/my_mobile_map_package.
      parameterOverrides - the overrides to the parameters
      Returns:
      a GenerateOfflineMapJob that will generate the offline map. The result is a GenerateOfflineMapResult object if the job completed successfully. Note you must call Job.start() to start the Job.
      Throws:
      IllegalArgumentException - if parameters or parameterOverrides is null, or if downloadDirectoryPath is null or empty
      Since:
      100.4.0
    • getPreplannedMapAreasAsync

      public ListenableFuture<List<PreplannedMapArea>> getPreplannedMapAreasAsync()
      Executes an asynchronous operation to get a list of preplanned map areas. The result is an unmodifiable list of PreplannedMapArea objects, which is empty if there are no preplanned areas for this map.

      Note that calling this method will load the OfflineMapTask if it is not already loaded.

      Returns:
      a ListenableFuture for tracking when the operation is done and getting the result; also allows cancellation. Calling get() on the returned future may throw an ExecutionException with its cause set to:
      Since:
      100.2.0
    • downloadPreplannedOfflineMap

      public DownloadPreplannedOfflineMapJob downloadPreplannedOfflineMap(DownloadPreplannedOfflineMapParameters parameters, String downloadDirectoryPath)
      Creates a DownloadPreplannedOfflineMapJob that can be used to download the preplanned map area specified by the given parameters object. The job will fail if the last directory in the download directory path cannot be created or is not empty.
      Parameters:
      parameters - specifies parameters for the job including the preplanned map area to be downloaded
      downloadDirectoryPath - The path to a folder where the map content is stored on the device. For example, to create a new mobile map package my_mobile_map_package in a parent directory [my root path]/my_mobile_maps, this property would be [my root path]/my_mobile_maps/my_mobile_map_package.
      Returns:
      a DownloadPreplannedOfflineMapJob that will download the preplanned map area. The result is a DownloadPreplannedOfflineMapResult object if the job completed successfully. Note you must call Job.start() to start the Job.
      Throws:
      IllegalArgumentException - if parameters is null, or if downloadDirectoryPath is null or empty
      Since:
      100.4.0
    • getLoadStatus

      public LoadStatus getLoadStatus()
      Gets the value of the loadStatus property.
      Specified by:
      getLoadStatus in interface Loadable
      Property description:
      Returns:
      the value of the loadStatus property
      See Also:
    • getLoadError

      public ArcGISRuntimeException getLoadError()
      Gets the value of the loadError property.
      Specified by:
      getLoadError in interface Loadable
      Property description:
      Returns:
      the value of the loadError property
      See Also:
    • cancelLoad

      public void cancelLoad()
      Description copied from interface: Loadable
      Cancels loading metadata for the object.

      Cancels loading the metadata if the object is loading, and always invokes the done loading listener.

      A load operation that is in progress (LoadStatus.LOADING state) can be cancelled by calling this method and the resource will transition from LoadStatus.LOADING to LoadStatus.FAILED_TO_LOAD state. If the load operation was successfully cancelled, a CancellationException will be returned from Loadable.getLoadError().

      Cancellation should be used carefully because all enqueued done loading listeners for that resource instance will get invoked with an error stating that the operation was cancelled. Thus, one component in the application can cancel the load operation initiated by other components.

      This method does nothing if the resource is not in LoadStatus.LOADING state.

      Specified by:
      cancelLoad in interface Loadable
    • loadAsync

      public void loadAsync()
      Description copied from interface: Loadable
      Loads the metadata of the loadable resource asynchronously.

      The load status changes from LoadStatus.NOT_LOADED to LoadStatus.LOADING. A listener can be added via Loadable.addDoneLoadingListener(java.lang.Runnable) that is invoked upon completion of the asynchronous load operation.

      If the load operation completes successfully, the load status will be LoadStatus.LOADED, which means the resource has loaded its metadata.

      If the load operation failed, the load status will be LoadStatus.FAILED_TO_LOAD and the error can be retrieved by calling Loadable.getLoadError().

      This method can be called concurrently and repeatedly, but only one attempt is ever made to perform the load operation. If a load operation is already in progress (LoadStatus.LOADING state) when loadAsync is called, it simply piggy-backs on the outstanding operation and the done loading listener added to the loadable resource is enqueued to be invoked when that operation completes. If the operation has already completed (LoadStatus.LOADED or LoadStatus.FAILED_TO_LOAD state) when loadAsync is called, the done loading listener is immediately invoked when added to the loadable resource.

      If a loadable resource has failed to load, calling loadAsync on it subsequently will not change its state. The done loading listener will be invoked immediately when added to the loadable resource. In order to retry loading the resource, Loadable.retryLoadAsync() needs to be used.

      A load operation that is in progress (LoadStatus.LOADING state) can be cancelled by calling Loadable.cancelLoad().

      Specified by:
      loadAsync in interface Loadable
    • retryLoadAsync

      public void retryLoadAsync()
      Description copied from interface: Loadable
      Loads or retries loading metadata for the object asynchronously.

      Will retry loading the metadata if the object's load status is LoadStatus.FAILED_TO_LOAD. Will load the object if it is not loaded. Will not retry to load the object if the object is loaded.

      For more details on the load process see Loadable.loadAsync().

      Specified by:
      retryLoadAsync in interface Loadable
    • addDoneLoadingListener

      public void addDoneLoadingListener(Runnable listener)
      Description copied from interface: Loadable
      Adds a listener to the loadable resource that is invoked when loading has completed.

      The listener may be added at any point, whether the loadable resource has already completed loading or not.

      • For resources that are not loaded when the listener is added (LoadStatus is NOT_LOADED or LOADING): When the resource completes loading, the listener will be invoked on the UI thread if it is added from the UI thread, otherwise it is not guaranteed on which thread the listener is invoked.
      • For resources that are already loaded when the listener is added (LoadStatus is LOADED or FAILED_TO_LOAD): The listener will be called immediately, on the current thread.

      Alternatively, to be notified when there is any change in the load status, add a listener to the Loadable.loadStatusProperty() instead.

      Specified by:
      addDoneLoadingListener in interface Loadable
      Parameters:
      listener - a Runnable that is invoked upon completion of the load operation
    • removeDoneLoadingListener

      public boolean removeDoneLoadingListener(Runnable listener)
      Description copied from interface: Loadable
      Removes a done loading listener from the loadable resource.
      Specified by:
      removeDoneLoadingListener in interface Loadable
      Parameters:
      listener - the listener to be removed
      Returns:
      true if the listener was removed, otherwise false
    • addLoadStatusChangedListener

      public void addLoadStatusChangedListener(LoadStatusChangedListener listener)
      Description copied from interface: Loadable
      Adds a LoadStatusChangedListener to the loadable resource that is invoked whenever the load status changes.

      Adding this listener on the UI thread will cause it to be invoked on the UI thread, otherwise it is not guaranteed on which thread the listener is invoked.

      The listener will not be called if added to a loadable resource that has already completed loading. To be notified when a loadable resource has completed loading, including if the resource is already loaded when the listener is added, use the Loadable.addDoneLoadingListener(Runnable) method.

      Specified by:
      addLoadStatusChangedListener in interface Loadable
      Parameters:
      listener - the LoadStatusChangedListener to be added
    • removeLoadStatusChangedListener

      public boolean removeLoadStatusChangedListener(LoadStatusChangedListener listener)
      Description copied from interface: Loadable
      Removes a LoadStatusChangedListener from the loadable resource.
      Specified by:
      removeLoadStatusChangedListener in interface Loadable
      Parameters:
      listener - the LoadStatusChangedListener to be removed
      Returns:
      true if the listener was removed, otherwise false
    • loadStatusProperty

      public ReadOnlyObjectProperty<LoadStatus> loadStatusProperty()
      Description copied from interface: Loadable
      The load status.
      Specified by:
      loadStatusProperty in interface Loadable
      Returns:
      the loadStatus property
      See Also:
    • loadErrorProperty

      public ReadOnlyObjectProperty<ArcGISRuntimeException> loadErrorProperty()
      Description copied from interface: Loadable
      The load error.
      Specified by:
      loadErrorProperty in interface Loadable
      Returns:
      the loadError property
      See Also: