Class ArcGISSublayer

  • All Implemented Interfaces:
    RemoteResource, LayerContent, Loadable, PopupSource
    Direct Known Subclasses:
    ArcGISMapImageSublayer, ArcGISTiledSublayer, SubtypeSublayer

    public abstract class ArcGISSublayer
    extends 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 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 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 String getName()
        Gets the name property of this sublayer.
        Specified by:
        getName in interface LayerContent
        Returns:
        the name of this sublayer
        Since:
        100.0.0
      • 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 interface PopupSource
        Parameters:
        popupDefinition - the PopupDefinition to set
        Since:
        100.0.0
        See Also:
        PopupSource.getPopupDefinition()
      • 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 interface LayerContent
        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 interface LayerContent
        Parameters:
        isVisible - true makes the sublayer visible, false makes it invisible
        Since:
        100.0.0
        See Also:
        LayerContent.isVisible()
      • fetchLegendInfosAsync

        public ListenableFuture<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 interface LayerContent
        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 interface LayerContent
        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 interface LayerContent
        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 interface LayerContent
        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 interface LayerContent
        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 interface LayerContent
        Returns:
        true if we can change this layer's visibility; false otherwise
      • getLoadStatus

        public LoadStatus getLoadStatus()
        Description copied from interface: Loadable
        Returns the LoadStatus of the loadable resource.
        Specified by:
        getLoadStatus in interface Loadable
        Returns:
        the LoadStatus of the loadable resource
        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 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
        Since:
        100.1.0
      • 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
        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 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
        Since:
        100.1.0
      • 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, use the Loadable.addLoadStatusChangedListener(LoadStatusChangedListener) method instead.

        Specified by:
        addDoneLoadingListener in interface Loadable
        Parameters:
        listener - a Runnable that is invoked upon completion of the load operation
        Since:
        100.1.0
      • 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
        Since:
        100.1.0
      • 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
        Since:
        100.1.0
      • 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
        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 interface RemoteResource
        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 interface RemoteResource
        Returns:
        the credential used to authenticate the user with the sublayer
        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 interface RemoteResource
        Returns:
        the RequestConfiguration, or null if none is set
        Since:
        100.1.0
      • getUri

        public String getUri()
        Gets the URL for this sublayer.
        Specified by:
        getUri in interface RemoteResource
        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