java.lang.Object
com.esri.arcgisruntime.mapping.Basemap
All Implemented Interfaces:
ApiKeyResource, JsonSerializable, RemoteResource, Loadable

public final class Basemap extends Object implements Loadable, JsonSerializable, RemoteResource, ApiKeyResource
A basemap is a non-editable layer that provides background, or reference information, in your map or scene.

A basemap provides a background of geographical context for the content you display in a map or scene. It provides a visual reference to help orient users and a framework on which you can overlay operational layers, perform analysis, and visualize geographic information. The content of a basemap is typically static and does not change frequently.

A basemap is composed of a collection of base layers (getBaseLayers()) and reference layers (getReferenceLayers()). Base layers are displayed at the bottom of a map or scene, and reference layers are displayed at the top, with the GeoModel.getOperationalLayers() between them.

Typically, you construct a basemap using a basemap style:

  • Use image tile basemap styles for satellite imagery and hillshade.
  • Use vector tile basemap styles such as streets navigation, light gray canvas, and OpenStreetMap (OSM).
  • Create custom basemap styles with your own colors, glyphs, and fonts using the ArcGIS Vector Tile Style Editor.

See BasemapStyle for the full range of the basemap styles provided by Esri. Basemap styles allow you to take advantage of geographically load-balanced services and monitor usage with API keys or named users. See Basemap layers for more information.

If your app works offline, you can construct a local basemap from a tiled layer using a TileCache, such as a tile package (.tpk, .tpkx, .vtpk) or a compact cache, stored on the device.

Since:
100.0.0
See Also:
  • Property Details

  • Constructor Details

    • Basemap

      public Basemap()
      Creates a basemap. Layers need to be added to the basemap before it can be used.
      Since:
      100.0.0
    • Basemap

      public Basemap(Layer baseLayer)
      Creates a basemap with a single base layer.
      Parameters:
      baseLayer - the Layer that serves as base layer, which can be retrieved via getBaseLayers()
      Since:
      100.0.0
    • Basemap

      public Basemap(Iterable<Layer> baseLayers, Iterable<Layer> referenceLayers)
      Creates a basemap with collections of base and reference layers.
      Parameters:
      baseLayers - a collection of layers that serve as base layers, may be null
      referenceLayers - a collection of layers that serve as reference layers, may be null
      Since:
      100.0.0
    • Basemap

      public Basemap(PortalItem portalItem)
      Creates a basemap with a portal item of type PortalItem.Type.WEBMAP.

      The PortalItem automatically loads when the Basemap loads. If the loaded PortalItem is not a portal item of type Type.WEBMAP, the basemap fails to load.

      Parameters:
      portalItem - a web map PortalItem
      Throws:
      IllegalArgumentException - if a null argument is passed
      Since:
      100.0.0
      See Also:
    • Basemap

      public Basemap(String webMapUrl)
      Creates a basemap with the URL.

      If the specified URL is a portal item URL (see PortalItem(Portal, String) for the supported URL formats), the underlying PortalItem will be created and accessible through getItem().

      Parameters:
      webMapUrl - the URL of the basemap, commonly the URL of a web map portal item
      Throws:
      IllegalArgumentException - if the URL is null or empty
      IllegalArgumentException - if the URL does not match the basic URL types
      Since:
      100.0.0
    • Basemap

      public Basemap(BasemapStyle basemapStyle)
      Creates a basemap with a BasemapStyle. These basemaps are secured and access requires either an API key or a named user.
      Parameters:
      basemapStyle - the basemap style
      Throws:
      IllegalArgumentException - if basemapStyle is null
      Since:
      100.10.0
      See Also:
    • Basemap

      public Basemap(BasemapStyle basemapStyle, BasemapStyleParameters basemapStyleParameters)
      Creates a basemap from an initial BasemapStyle with additional parameters to control settings like language.

      These basemaps are secured and access requires either an API key or an authenticated user.

      The initial state of the Basemap is LoadStatus.NOT_LOADED. When the Basemap is loaded the values specified in the BasemapStyleParameters are evaluated. See BasemapStyleParameters for information about the expected behavior for each parameter when the Basemap is loaded.

      Parameters:
      basemapStyle - the initial basemap style
      basemapStyleParameters - parameters that control how the BasemapStyle is used - for example by adjusting the language used for basemap labels
      Throws:
      NullPointerException - if basemapStyle is null
      NullPointerException - if basemapStyleParameters is null
      Since:
      200.3.0
      See Also:
  • Method Details

    • 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:
    • 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
    • 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
    • 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:
    • getApiKey

      public String getApiKey()
      Description copied from interface: ApiKeyResource
      Gets the API key to access API key enabled services and resources in ArcGIS Online.

      An API key is a unique long-lived access token that is used to authenticate and monitor requests to ArcGIS location services and private portal items. You can create and manage an API key using your portal when you sign in with an ArcGIS Location Platform account or an ArcGIS Online account with administrator access or a custom role that has the Generate API keys privilege. To learn how to create and manage API keys, go to the Create an API Key tutorial. You must ensure that your API key has the correct privileges to access secure resources.

      In addition to setting an API key at a global level for your application using ArcGISRuntimeEnvironment.setApiKey(String), you can call ApiKeyResource.setApiKey(String) on any class that implements ApiKeyResource. When you call setApiKey(String) on an APIKeyResource, it will override the default key at the global level (the key returned by ArcGISRuntimeEnvironment.getApiKey(), in other words), enabling more granular usage telemetry and management for ArcGIS Online resources used by your app.

      Classes that expose an API key property by implementing APIKeyResource include:

      Specified by:
      getApiKey in interface ApiKeyResource
      Returns:
      the API key to access API key enabled services and resources in ArcGIS Online
      See Also:
    • setApiKey

      public void setApiKey(String apiKey)
      Description copied from interface: ApiKeyResource
      Sets the API key to access API key enabled services and resources in ArcGIS Online.

      An API key is a unique key used to authorize access to specific services and resources in ArcGIS Online. It is also used to monitor access to those services. An API key is created and managed in the ArcGIS developer dashboard and is tied to a specific ArcGIS account.

      In addition to setting an API key at a global level for your application using ArcGISRuntimeEnvironment.setApiKey(String), you can call setApiKey(String) on any class that implements ApiKeyResource. When you call setApiKey(String) on an APIKeyResource, it will override the default key at the global level (the key returned by ArcGISRuntimeEnvironment.getApiKey(), in other words), enabling more granular usage telemetry and management for ArcGIS Online resources used by your app.

      Classes that expose an API key property by implementing APIKeyResource include:

      Specified by:
      setApiKey in interface ApiKeyResource
      Parameters:
      apiKey - the API key to access API key enabled services and resources in ArcGIS Online
      See Also:
    • getBaseLayers

      public LayerList getBaseLayers()
      Gets the collection of base layers in this basemap.

      Base layers are drawn beneath all other layers in the ArcGISMap or ArcGISScene. They are designed to provide a visual reference to help orient the user. Aerial imagery, terrain, and streets are examples of basemap layers. The collection can be empty but it is never null.

      This collection is specific to this basemap so you cannot reuse a collection coming from another Basemap.

      Returns:
      the collection of base layers in this basemap
      Since:
      100.0.0
      See Also:
    • getReferenceLayers

      public LayerList getReferenceLayers()
      Gets the collection of reference layers in this basemap.

      Reference layers are drawn on top all other layers in the ArcGISMap or ArcGISScene to display information such as boundaries, labels, and traffic networks. The collection can be empty but it is never null.

      This collection is specific to this basemap so you cannot reuse a collection coming from another Basemap.

      Returns:
      the collection of reference layers in this basemap
      Since:
      100.0.0
      See Also:
    • getName

      public String getName()
      Gets the name of this basemap.
      Returns:
      the name of this Basemap, or an empty string if the basemap has no name.
      Since:
      100.0.0
    • setName

      public void setName(String name)
      Sets the name of the basemap.
      Parameters:
      name - the name of this Basemap
      Since:
      100.0.0
    • getItem

      public Item getItem()
      Gets the portal item associated with this basemap.
      Returns:
      the associated Item or null if this Basemap is not associated with an Item
      Since:
      100.0.0
    • fromJson

      public static Basemap fromJson(String json)
      Creates a Basemap instance from a JSON string.
      Parameters:
      json - a JSON string that represents a Basemap
      Returns:
      a Basemap instance
      Throws:
      IllegalArgumentException - if json is null or empty
      Since:
      100.0.0
    • toJson

      public String toJson()
      Serializes a Basemap to a JSON string.
      Specified by:
      toJson in interface JsonSerializable
      Returns:
      a JSON string
      Since:
      100.0.0
    • getUnknownJson

      public Map<String,Object> getUnknownJson()
      Description copied from interface: JsonSerializable
      Gets unknown data from the source JSON.

      Unknown JSON is a Map of values not defined in the ArcGIS specification used to create this object but found in the source JSON. If the object is written back to JSON, any unknown JSON data is not persisted. The ArcGIS specification may be for a web map, web scene, REST API, and so on.

      Specified by:
      getUnknownJson in interface JsonSerializable
      Returns:
      an unmodifiable Map containing unknown data from the source JSON
    • getUnsupportedJson

      public Map<String,Object> getUnsupportedJson()
      Description copied from interface: JsonSerializable
      Gets unsupported data from the source JSON.

      Unsupported JSON is a Map of values defined in the ArcGIS specification used to create this object but not currently used in this API. If the object is written back to JSON, any unsupported JSON data is persisted. The ArcGIS specification may be from a web map, web scene, REST API, and so on.

      Specified by:
      getUnsupportedJson in interface JsonSerializable
      Returns:
      an unmodifiable Map containing unsupported data from the source JSON
    • copy

      public Basemap copy()
      Creates a copy of this Basemap instance.

      The method performs a deep copy of the Basemap, i.e. all objects referenced by the Basemap, such as layers or portal item, are copied as well.

      Returns:
      a copy of this Basemap instance
      Since:
      100.0.0
    • getUri

      public String getUri()
      Description copied from interface: RemoteResource
      Gets the URI of this RemoteResource. Typically this is the URI used to instantiate the object.
      Specified by:
      getUri in interface RemoteResource
      Returns:
      the URI of this RemoteResource
    • getCredential

      public Credential getCredential()
      Description copied from interface: RemoteResource
      Gets the Credential that is set on the network-enabled resource.

      Only applicable if the resource is secured.

      Specified by:
      getCredential in interface RemoteResource
      Returns:
      the Credential, or null if there is none
    • setCredential

      public void setCredential(Credential credential)
      Description copied from interface: RemoteResource
      Sets a Credential to be used by the network-enabled resource in the event of an authentication challenge. The default credential is null.

      Only applicable if the resource is secured.

      Specified by:
      setCredential in interface RemoteResource
      Parameters:
      credential - the Credential to be used for authentication
    • getRequestConfiguration

      public RequestConfiguration getRequestConfiguration()
      Description copied from interface: RemoteResource
      Gets the RequestConfiguration used to modify the parameters of network requests made by this RemoteResource.
      Specified by:
      getRequestConfiguration in interface RemoteResource
      Returns:
      the RequestConfiguration used to modify network requests
    • setRequestConfiguration

      public void setRequestConfiguration(RequestConfiguration requestConfiguration)
      Description copied from interface: RemoteResource
      Sets the RequestConfiguration used to modify the parameters of network requests made by this RemoteResource. If not set, the global RequestConfiguration will be used (see RequestConfiguration.getGlobalRequestConfiguration()).
      Specified by:
      setRequestConfiguration in interface RemoteResource
      Parameters:
      requestConfiguration - the RequestConfiguration used to modify network requests