Class ArcGISSublayer
- java.lang.Object
-
- com.esri.arcgisruntime.layers.ArcGISSublayer
-
- All Implemented Interfaces:
RemoteResource
,LayerContent
,Loadable
,PopupSource
- Direct Known Subclasses:
ArcGISMapImageSublayer
,ArcGISTiledSublayer
,SubtypeSublayer
public abstract class ArcGISSublayer extends java.lang.Object implements Loadable, RemoteResource, LayerContent, PopupSource
ArcGISSublayer represents the base class for all sublayer types. A sublayer is a subcomponent from which a layer can be composed; sublayers can also have zero or more sublayers themselves. For example, an ArcGISMapImageLayer is a type of layer that can contain one or more ArcGISMapImageSublayers, which in turn can have ArcGISMapImageSublayers.The code below shows how you can access the sublayers of an ArcGISMapImageLayer, and change the visibility of a sublayer:
String urlMsUsa = "http://sampleserver6.arcgisonline.com/arcgis/rest/services/USA/MapServer"; final ArcGISMapImageLayer mapImageLayer = new ArcGISMapImageLayer(urlMsUsa); // Add a listener that is invoked when layer loading has completed. mapImageLayer.addDoneLoadingListener(() -> { if (mapImageLayer.getLoadStatus() == LoadStatus.LOADED) { // Set visibility of a sublayer of this layer ListenableList<ArcGISSublayer> sublayerList = mapImageLayer.getSublayers(); sublayerList.get(0).setVisible(false); } }); mapImageLayer.loadAsync();
Some of the properties of a sublayer can be accessed before it is loaded:- ID
- name
- minimum/maximum scale
- visibility
All the remaining properties can only be accessed once the sublayer has loaded.
Setting properties of a sublayer before calling loadAsync will not overwrite once the sublayer has loaded.
- Since:
- 100.0.0
- See Also:
Layer
-
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
addDoneLoadingListener(java.lang.Runnable listener)
Adds a listener to the loadable resource that is invoked when loading has completed.void
addLoadStatusChangedListener(LoadStatusChangedListener listener)
Adds aLoadStatusChangedListener
to the loadable resource that is invoked whenever the load status changes.void
cancelLoad()
Cancels loading metadata for the object.boolean
canChangeVisibility()
Checks whether we can change the visibility of this layer.boolean
canScaleSymbols()
Returns whether the text and symbols on this sublayer will change as the map scale varies.boolean
canShowInLegend()
Checks if this layer will be listed in the legend.abstract ArcGISSublayer
copy()
Creates a deep copy of this ArcGISSublayer instance.protected void
copyTo(ArcGISSublayer copy)
Copies fields in this class to the copy instance.ListenableFuture<java.util.List<LegendInfo>>
fetchLegendInfosAsync()
Gets properties from the legend information of this sublayer.Credential
getCredential()
Gets the credential used to authenticate the user with the sublayer.java.lang.String
getDefinitionExpression()
Gets the definition expression for this sublayer by which data in the layer is filtered.long
getId()
Gets the unique id that is associated to this sublayer.ArcGISRuntimeException
getLoadError()
Returns the most recent error that was encountered when the loadable resource transitioned to theLoadStatus.FAILED_TO_LOAD
state, either due to calling theLoadable.loadAsync()
orLoadable.retryLoadAsync()
method.LoadStatus
getLoadStatus()
Returns theLoadStatus
of the loadable resource.ArcGISMapServiceSublayerInfo
getMapServiceSublayerInfo()
Gets the metadata for this sublayer.double
getMaxScale()
Gets the maximum viewing level at which this sublayer can be visible on a map.double
getMinScale()
Gets the minimum viewing level at which this sublayer can be visible on a map.java.lang.String
getName()
Gets the name property of this sublayer.float
getOpacity()
Gets the opacity of this sublayer.PopupDefinition
getPopupDefinition()
Gets the PopupDefinition defined in the ArcGISSublayer definition or set viasetPopupDefinition(PopupDefinition)
, or null if one is not defined and one has not been set.Renderer
getRenderer()
Gets the renderer for this sublayer.RequestConfiguration
getRequestConfiguration()
Gets the RequestConfiguration in use by this sublayer.ListenableList<LayerContent>
getSubLayerContents()
Returns a list of sub layers, if any.ListenableList<ArcGISSublayer>
getSublayers()
Gets a list of sublayers that make up this sublayer.java.lang.String
getUri()
Gets the URL for this sublayer.boolean
isLabelsEnabled()
Returns whether or not labels are enabled for this sublayer.boolean
isPopupEnabled()
Checks if the pop-up definition returned fromPopupSource.getPopupDefinition()
is enabled or disabled.boolean
isVisible()
Indicates if the sublayer is visible on the map.boolean
isVisibleAtScale(double scale)
Checks if this layer has effective visibility at the given scale.void
loadAsync()
Loads the metadata of the loadable resource asynchronously.boolean
removeDoneLoadingListener(java.lang.Runnable listener)
Removes a done loading listener from the loadable resource.boolean
removeLoadStatusChangedListener(LoadStatusChangedListener listener)
Removes aLoadStatusChangedListener
from the loadable resource.void
retryLoadAsync()
Loads or retries loading metadata for the object asynchronously.void
setCanShowInLegend(boolean canShowInLegend)
Sets whether or not this layer should be visible in the legend.void
setCredential(Credential credential)
Sets the credential used to authenticate the user with the sublayer.void
setPopupDefinition(PopupDefinition popupDefinition)
Sets the PopupDefinition for the ArcGISSublayer, overriding the previous one (for example, the one defined in the ArcGISSublayer definition).void
setPopupEnabled(boolean enabled)
Sets whether the pop-up definition returned fromPopupSource.getPopupDefinition()
is enabled or disabled.protected void
setRenderer(Renderer renderer)
Allows sub-classes to set the renderer reference e.g.void
setRequestConfiguration(RequestConfiguration requestConfiguration)
Sets the configuration parameters used for sending a network request using this sublayer object.void
setVisible(boolean isVisible)
Shows or hides this sublayer from a map.
-
-
-
Method Detail
-
getId
public long getId()
Gets the unique id that is associated to this sublayer.- Returns:
- the id of this sublayer
- Since:
- 100.0.0
-
getSublayers
public ListenableList<ArcGISSublayer> getSublayers()
Gets a list of sublayers that make up this sublayer.If the sublayer has no sublayers of its own then the list will be empty.
- Returns:
- a list of sublayers, can be empty
- Since:
- 100.0.0
-
getMinScale
public double getMinScale()
Gets the minimum viewing level at which this sublayer can be visible on a map.- Returns:
- the minimum scale that this sublayer will be visible
- Since:
- 100.0.0
-
getMaxScale
public double getMaxScale()
Gets the maximum viewing level at which this sublayer can be visible on a map.- Returns:
- the maximum scale that this sublayer will be visible
- Since:
- 100.0.0
-
getDefinitionExpression
public java.lang.String getDefinitionExpression()
Gets the definition expression for this sublayer by which data in the layer is filtered.The definition expression string uses the SQL-92 where clause syntax. Be sure to escape special characters in the expression string as required for your platform. The DATE keyword expects the date format yyyy-mm-dd and the TIMESTAMP keyword expects the time stamp format yyyy-mm-dd hh:mm:ss. See the ArcGIS Blog article entitled "Querying Feature Services Date-Time Queries" for more information.
- Returns:
- the definition expression
- Since:
- 100.1.0
-
getMapServiceSublayerInfo
public ArcGISMapServiceSublayerInfo getMapServiceSublayerInfo()
Gets the metadata for this sublayer.- Returns:
- the metadata, or null if this sublayer is not loaded
- Since:
- 100.1.0
-
getOpacity
public float getOpacity()
Gets the opacity of this sublayer.- Returns:
- the opacity
- Since:
- 100.1.0
-
getRenderer
public Renderer getRenderer()
Gets the renderer for this sublayer.- Returns:
- the renderer, or null if the sublayer is not loaded
- Since:
- 100.1.0
-
setRenderer
protected void setRenderer(Renderer renderer)
Allows sub-classes to set the renderer reference e.g.ArcGISMapImageSublayer
allows a renderer to be set.- Parameters:
renderer
- the renderer to set- Since:
- 100.1.0
-
canScaleSymbols
public boolean canScaleSymbols()
Returns whether the text and symbols on this sublayer will change as the map scale varies.- Returns:
- true if the text and symbols will change as the map scale varies, false otherwise
- Since:
- 100.1.0
-
isLabelsEnabled
public boolean isLabelsEnabled()
Returns whether or not labels are enabled for this sublayer.- Returns:
- true if labels are enabled, false otherwise
- Since:
- 100.1.0
-
getName
public java.lang.String getName()
Gets the name property of this sublayer.- Specified by:
getName
in interfaceLayerContent
- Returns:
- the name of this sublayer
- Since:
- 100.0.0
-
getPopupDefinition
public PopupDefinition getPopupDefinition()
Gets the PopupDefinition defined in the ArcGISSublayer definition or set viasetPopupDefinition(PopupDefinition)
, or null if one is not defined and one has not been set.- Specified by:
getPopupDefinition
in interfacePopupSource
- Returns:
- the ArcGISSublayer's PopupDefinition
- Since:
- 100.0.0
- See Also:
PopupSource.setPopupDefinition(PopupDefinition)
-
setPopupDefinition
public void setPopupDefinition(PopupDefinition popupDefinition)
Sets the PopupDefinition for the ArcGISSublayer, overriding the previous one (for example, the one defined in the ArcGISSublayer definition).- Specified by:
setPopupDefinition
in interfacePopupSource
- Parameters:
popupDefinition
- the PopupDefinition to set- Since:
- 100.0.0
- See Also:
PopupSource.getPopupDefinition()
-
isPopupEnabled
public boolean isPopupEnabled()
Description copied from interface:PopupSource
Checks if the pop-up definition returned fromPopupSource.getPopupDefinition()
is enabled or disabled.- Specified by:
isPopupEnabled
in interfacePopupSource
- Returns:
- true if the pop-up definition is enabled; false otherwise. Will return false if an error occurs.
- See Also:
PopupSource.setPopupEnabled(boolean)
-
setPopupEnabled
public void setPopupEnabled(boolean enabled)
Description copied from interface:PopupSource
Sets whether the pop-up definition returned fromPopupSource.getPopupDefinition()
is enabled or disabled.- Specified by:
setPopupEnabled
in interfacePopupSource
- Parameters:
enabled
- true to enable the PopupDefinition; false otherwise- See Also:
PopupSource.isPopupEnabled()
-
isVisible
public boolean isVisible()
Indicates if the sublayer is visible on the map.The visibility of a sublayer can change if it is manually set,
setVisible(boolean)
, or the map's scale is outside of the sublayer's scale.- Specified by:
isVisible
in interfaceLayerContent
- Returns:
- true if sublayer is visible; false otherwise
- Since:
- 100.0.0
- See Also:
getMaxScale()
,getMinScale()
-
setVisible
public void setVisible(boolean isVisible)
Shows or hides this sublayer from a map.The default value for a sublayer's visibility is set to true.
- Specified by:
setVisible
in interfaceLayerContent
- Parameters:
isVisible
- true makes the sublayer visible, false makes it invisible- Since:
- 100.0.0
- See Also:
LayerContent.isVisible()
-
fetchLegendInfosAsync
public ListenableFuture<java.util.List<LegendInfo>> fetchLegendInfosAsync()
Gets properties from the legend information of this sublayer.These properties allow access to a Feature's name and symbol.
- Specified by:
fetchLegendInfosAsync
in interfaceLayerContent
- Returns:
- a listenable future that supplies a list of legend information.
- Since:
- 100.0.0
- See Also:
Feature
-
canShowInLegend
public boolean canShowInLegend()
Description copied from interface:LayerContent
Checks if this layer will be listed in the legend.- Specified by:
canShowInLegend
in interfaceLayerContent
- Returns:
- true if this layer will be visible in the legend; false otherwise
-
setCanShowInLegend
public void setCanShowInLegend(boolean canShowInLegend)
Description copied from interface:LayerContent
Sets whether or not this layer should be visible in the legend.- Specified by:
setCanShowInLegend
in interfaceLayerContent
- Parameters:
canShowInLegend
- true to show in the legend; false to omit it from the legend
-
getSubLayerContents
public ListenableList<LayerContent> getSubLayerContents()
Description copied from interface:LayerContent
Returns a list of sub layers, if any. If there are no sub-layers, an empty list will be returned. This list cannot be used to add or remove sub-layers.- Specified by:
getSubLayerContents
in interfaceLayerContent
- Returns:
- a read only list of sub-layers, if any
-
isVisibleAtScale
public boolean isVisibleAtScale(double scale)
Description copied from interface:LayerContent
Checks if this layer has effective visibility at the given scale. This effective visibility takes care of the effective visibility of the parents at the specified scale.- Specified by:
isVisibleAtScale
in interfaceLayerContent
- Parameters:
scale
- the scale the visibility has to be calculated for- Returns:
- true if the layer will be visible at the given scale; false otherwise
-
canChangeVisibility
public boolean canChangeVisibility()
Description copied from interface:LayerContent
Checks whether we can change the visibility of this layer.- Specified by:
canChangeVisibility
in interfaceLayerContent
- Returns:
- true if we can change this layer's visibility; false otherwise
-
getLoadStatus
public LoadStatus getLoadStatus()
Description copied from interface:Loadable
Returns theLoadStatus
of the loadable resource.- Specified by:
getLoadStatus
in interfaceLoadable
- Returns:
- the LoadStatus of the loadable resource
- Since:
- 100.1.0
-
getLoadError
public ArcGISRuntimeException getLoadError()
Description copied from interface:Loadable
Returns the most recent error that was encountered when the loadable resource transitioned to theLoadStatus.FAILED_TO_LOAD
state, either due to calling theLoadable.loadAsync()
orLoadable.retryLoadAsync()
method.If the resource subsequently transitions to
LoadStatus.LOADED
(for example, if a call toretryLoadAsync
completes successfully) the error is cleared out.- Specified by:
getLoadError
in interfaceLoadable
- Returns:
- the most recent error that was encountered when the loadable resource transitioned to the
LoadStatus.FAILED_TO_LOAD
state. - Since:
- 100.1.0
-
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
toLoadStatus.LOADING
. A listener can be added viaLoadable.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 callingLoadable.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) whenloadAsync
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
orLoadStatus.FAILED_TO_LOAD
state) whenloadAsync
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 callingLoadable.cancelLoad()
.
-
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 interfaceLoadable
- Since:
- 100.1.0
-
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 fromLoadStatus.LOADING
toLoadStatus.FAILED_TO_LOAD
state. If the load operation was successfully cancelled, a CancellationException will be returned fromLoadable.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 interfaceLoadable
- Since:
- 100.1.0
-
addDoneLoadingListener
public void addDoneLoadingListener(java.lang.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, use the
Loadable.addLoadStatusChangedListener(LoadStatusChangedListener)
method instead.- Specified by:
addDoneLoadingListener
in interfaceLoadable
- Parameters:
listener
- a Runnable that is invoked upon completion of the load operation- Since:
- 100.1.0
-
removeDoneLoadingListener
public boolean removeDoneLoadingListener(java.lang.Runnable listener)
Description copied from interface:Loadable
Removes a done loading listener from the loadable resource.- Specified by:
removeDoneLoadingListener
in interfaceLoadable
- Parameters:
listener
- the listener to be removed- Returns:
- true if the listener was removed, otherwise false
- Since:
- 100.1.0
-
addLoadStatusChangedListener
public void addLoadStatusChangedListener(LoadStatusChangedListener listener)
Description copied from interface:Loadable
Adds aLoadStatusChangedListener
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 interfaceLoadable
- Parameters:
listener
- theLoadStatusChangedListener
to be added- Since:
- 100.1.0
-
removeLoadStatusChangedListener
public boolean removeLoadStatusChangedListener(LoadStatusChangedListener listener)
Description copied from interface:Loadable
Removes aLoadStatusChangedListener
from the loadable resource.- Specified by:
removeLoadStatusChangedListener
in interfaceLoadable
- Parameters:
listener
- theLoadStatusChangedListener
to be removed- Returns:
- true if the listener was removed, otherwise false
- Since:
- 100.1.0
-
setCredential
public void setCredential(Credential credential)
Sets the credential used to authenticate the user with the sublayer.- Specified by:
setCredential
in interfaceRemoteResource
- Parameters:
credential
- the credential used to authenticate the user with the sublayer- Since:
- 100.1.0
-
getCredential
public Credential getCredential()
Gets the credential used to authenticate the user with the sublayer.- Specified by:
getCredential
in interfaceRemoteResource
- Returns:
- the credential used to authenticate the user with the sublayer
- Since:
- 100.1.0
-
setRequestConfiguration
public void setRequestConfiguration(RequestConfiguration requestConfiguration)
Sets the configuration parameters used for sending a network request using this sublayer object. The global RequestConfiguration is used if no RequestConfiguration is set or null is set (seeRequestConfiguration.getGlobalRequestConfiguration()
).- Specified by:
setRequestConfiguration
in interfaceRemoteResource
- Parameters:
requestConfiguration
- a RequestConfiguration containing the parameters to use- Since:
- 100.1.0
-
getRequestConfiguration
public RequestConfiguration getRequestConfiguration()
Gets the RequestConfiguration in use by this sublayer. If null is returned, it indicates that the global RequestConfiguration is used instead.- Specified by:
getRequestConfiguration
in interfaceRemoteResource
- Returns:
- the RequestConfiguration, or null if none is set
- Since:
- 100.1.0
-
getUri
public java.lang.String getUri()
Gets the URL for this sublayer.- Specified by:
getUri
in interfaceRemoteResource
- Returns:
- the URL, or null if the sublayer is not loaded
- Since:
- 100.1.0
-
copy
public abstract ArcGISSublayer copy()
Creates a deep copy of this ArcGISSublayer instance.- Returns:
- a deep copy of this ArcGISSublayer instance
- Since:
- 100.1.0
-
copyTo
protected void copyTo(ArcGISSublayer copy)
Copies fields in this class to the copy instance.- Parameters:
copy
- instance to copy the fields of this class to- Since:
- 100.1.0
-
-