Class FeatureLayer

  • All Implemented Interfaces:
    TimeAware, LayerContent, Loadable, FloorAware, PopupSource
    Direct Known Subclasses:
    SubtypeFeatureLayer

    public class FeatureLayer
    extends Layer
    implements FloorAware, PopupSource, TimeAware
    A layer that can visualize vector/feature data.

    Feature layers display data from feature services or supported local data sources, including shapefiles, GeoPackages, and geodatabases. Feature layers can be used to display, select, and query features in a layer. If the underlying feature service or table supports editing, you can use it with a feature layer as a basis for editing geometry, attributes, and attachments. Feature layers are used to store features associated with a utility network.

    To display features in a FeatureCollectionTable, use FeatureCollectionLayer instead.

    Features are retrieved as needed by the app. Features can be downloaded from a sync-enabled feature service when the device is connected and cached locally for use when the device is offline. Edits can then be synchronized back to the service.

    Functional characteristics

    The following are sources that can be rendered using a feature layer.

    • Feature service — Backed by a service feature table; feature data from the service is cached locally in the table. New features are retrieved automatically when you navigate the map. The local table cache is discarded when the layer is disposed. If sync is enabled, features can be created, edited, and pushed to the server.
    • Geodatabase — Backed by a geodatabase feature table; The geodatabase can be a replica of a feature service, which allows synchronizing with a feature service, or taking the content of a feature service offline. Use a geodatabase sync task to synchronize the geodatabase with the service. The geodatabase can also be a mobile geodatabase created by ArcGIS Pro. Mobile geodatabases cannot be synced and use a default renderer.
    • Shapefile — Backed by a shapefile feature table; use feature layers to show the contents of shapefiles (.shp).
    • Geopackage — Backed by a geopackage feature table; use feature layers to render the tables in a GeoPackage (.gpkg). A GeoPackage is a data source that conforms to the OGC GeoPackage specification. Geopackage feature tables can be edited and saved, but can't support sync, because there is no backing feature service. ArcGIS Runtime supports GeoPackage versions 1.0, 1.1, and 1.2.
    • Web Feature Service (WFS) — Backed by a WFS feature table. You can populate the table using Runtime query parameters or raw XML-encoded GetFeature queries. A WFS feature table only supports manual cache feature request mode. Runtime supports OGC WFS versions 2.0.0 and 2.0.2.

      WFS server implementations are inconsistent in how they expect coordinates to be formatted. Some return and expect coordinates in (x,y) order, while others expect (y,x). Runtime guesses the correct order by default. This behavior can be configured with the WfsFeatureTable.setAxisOrder(OgcAxisOrder) and WfsFeatureTable.setFilterAxisOrder(OgcAxisOrder) methods.

    • OGC API Features - Backed by an OGC feature collection table. You can populate the table using Runtime query parameters. An OCG feature collection table only supports manual cache feature request mode. Runtime supports OGC API - Features - Part 1 and OGC API - Features - Part 2.
    Individual features can be queried and filtered based on spatial queries or SQL queries. Introduced at 100.3.0, string comparisons for features queried in service feature tables are case insensitive.

    The features displayed in a FeatureLayer are reprojected to match the spatial reference returned by GeoModel.getSpatialReference(), if necessary. Local tables cannot be re-projected automatically.

    Feature layers expose a getUnsupportedJson() method that, for feature layers based on a feature service, returns a dictionary of values known to the supported web map specification but not explicitly exposed through the Runtime API. This allows you to access information that was saved with the layer but not used by Runtime. Feature layers also provides a getUnknownJson() method to return JSON that was not recognized.

    Performance characteristics

    As full feature information is cached locally in a geodatabase, shapefile, or GeoPackage, and features are drawn natively, this layer type offers excellent display performance when zooming and panning the map within the extent of cached features. Querying features is also efficient, enabling app functions such as real-time updates of query results in a map.

    The local cache must be initially created, which can be resource-intensive for the server. The initial download to the device may require extensive network usage and subsequent local device storage. App memory increases with the number and complexity of the features cached. Network usage can be eliminated by provisioning the cache directly to the device in advance.

    Feature tables backed by a service define three feature request modes. The table's feature request mode controls how and when features are requested from the service.

    • On interaction cache — Features are requested automatically for the visible map or scene extent. As the user pans and zooms, features are cached locally. If the user returns to an area where features have already been loaded, the table won't need to download those features again.
    • Manual cache — Features must be manually populated using a call to ServiceFeatureTable.populateFromServiceAsync(QueryParameters, boolean, Iterable) Once populated, all queries are made against the local table only. ServiceFeatureTable.populateFromServiceAsync(QueryParameters, boolean, Iterable) can be called again to retrieve more features from the service.
    • On interaction, no cache — Features are requested automatically for the visible map extent. As the user pans and zooms, features outside the visible extent are not cached and must be downloaded again each time.
    Since:
    100.0.0
    See Also:
    Layer
    • Constructor Detail

      • FeatureLayer

        protected FeatureLayer​(com.esri.arcgisruntime.internal.jni.CoreFeatureLayer coreFeatureLayer,
                               PortalItem portalItem,
                               boolean addToCache)
        Constructor that creates a wrapper for coreFeatureLayer's CoreFeatureTable, rather than using a FeatureTable that's been passed in by the app.
        Parameters:
        coreFeatureLayer - the core layer to wrap
        portalItem - an existing PortalItem to use, or null if none exists yet and we need to ask the layer if it has a CorePortalItem in which case we create a wrapper for it
        addToCache - if true, adds this FeatureLayer instance to the wrapper cache
        Since:
        100.0.0
      • FeatureLayer

        public FeatureLayer​(PortalItem portalItem,
                            long layerId)
        Creates a new FeatureLayer based on a layer within a feature service PortalItem.

        If the portal item argument is not in LoadStatus#LOADED state it will be loaded automatically when this FeatureLayer instance is loaded.

        Parameters:
        portalItem - a feature service PortalItem
        layerId - the ID of a layer within the feature service
        Throws:
        IllegalArgumentException - if portalItem is null
        Since:
        100.0.0
    • Method Detail

      • copy

        public FeatureLayer copy()
        Creates a deep copy of this FeatureLayer instance.
        Returns:
        a deep copy of this FeatureLayer instance, which means that copies of all fields of this layer are made including its loading state
        Since:
        100.1.0
      • getRefreshInterval

        public long getRefreshInterval()
        Gets the refresh interval in milliseconds. The refresh interval is the time between automatic layer requests. A value of zero means the layer is never refreshed. The default value is zero.
        Returns:
        the refresh interval in milliseconds
        Since:
        100.1.0
      • setRefreshInterval

        public void setRefreshInterval​(long refreshIntervalMilliseconds)
        Sets the refresh interval in milliseconds. The refresh interval is the time between automatic layer requests. A value of zero means the layer is never refreshed. The default value is zero.
        Parameters:
        refreshIntervalMilliseconds - the refresh interval in milliseconds
        Throws:
        IllegalArgumentException - if milliseconds is less than zero
        Since:
        100.1.0
      • getDefinitionExpression

        public String getDefinitionExpression()
        Gets the definition expression applied to layer by the developer.
        Returns:
        the definition expression
        Since:
        100.0.0
        See Also:
        setDefinitionExpression(String)
      • setDefinitionExpression

        public void setDefinitionExpression​(String expression)
        Sets a definition expression which is a SQL statement where clause to filter out the features to be displayed. The definition expression is used to query the feature table related to the feature layer and only features meeting the query criteria will be displayed on the layer.

        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.

        Parameters:
        expression - the definition expression, it can be null
        Since:
        100.0.0
        See Also:
        getDefinitionExpression()
      • setPopupDefinition

        public void setPopupDefinition​(PopupDefinition popupDefinition)
        Sets the PopupDefinition for the FeatureLayer, overriding the previous one (for example, the one defined in the FeatureLayer definition).
        Specified by:
        setPopupDefinition in interface PopupSource
        Parameters:
        popupDefinition - the PopupDefinition to set
        Since:
        100.0.0
        See Also:
        PopupSource.getPopupDefinition()
      • isScaleSymbols

        public boolean isScaleSymbols()
        Gets whether the layer's symbols and labels honor the map reference scale.

        If the map has a positive reference scale, and the layer honors it, then symbols and labels will be drawn at their specified size when the viewing scale is the same as the reference scale, and will grow or shrink as the view zooms in or out, to keep the symbol a fixed size on the map. If the map has no reference scale, the reference scale is zero, or the FeatureLayer's scaleSymbols property is false, then the symbols and labels will be drawn at their fixed screen size.

        Returns:
        true if the layer's symbols and labels honor the map reference scale, false if not
        Since:
        100.5.0
      • setScaleSymbols

        public void setScaleSymbols​(boolean scaleSymbols)
        Sets whether the layer's symbols and labels honor the map reference scale.

        If the map has a positive reference scale, and the layer honors it, then symbols and labels will be drawn at their specified size when the viewing scale is the same as the reference scale, and will grow or shrink as the view zooms in or out, to keep the symbol a fixed size on the map. If the map has no reference scale, the reference scale is zero, or the FeatureLayer's scaleSymbols property is false, then the symbols and labels will be drawn at their fixed screen size.

        Parameters:
        scaleSymbols - true if the layer's symbols and labels should honor the map reference scale, false if not
        Since:
        100.5.0
      • setLabelsEnabled

        public void setLabelsEnabled​(boolean enabled)
        Enables or disables the labeling for the layer.
        Parameters:
        enabled - true to enable, false to disable labels
        Since:
        100.0.0
      • isLabelsEnabled

        public boolean isLabelsEnabled()
        Gets whether labels are enabled.
        Returns:
        true if labels are enabled, false if not
        Since:
        100.0.0
      • getLabelDefinitions

        public List<LabelDefinition> getLabelDefinitions()
        Gets a modifiable list of label definitions of the feature layer.
        Returns:
        a modifiable list of label definitions
        Since:
        100.1.0
      • getFeatureTable

        public FeatureTable getFeatureTable()
        Get the associated FeatureTable for FeatureLayer.
        Returns:
        the feature table
        Since:
        100.0.0
      • getRenderer

        public Renderer getRenderer()
        Gets the layer's current renderer.
        Returns:
        the renderer
        Since:
        100.0.0
      • setRenderer

        public void setRenderer​(Renderer renderer)
        Sets the layer's renderer
        Parameters:
        renderer - the renderer to be used for this layer
        Throws:
        IllegalArgumentException - if renderer is null
        Since:
        100.0.0
      • setSelectionColor

        @Deprecated
        public void setSelectionColor​(int selectionColor)
        Deprecated.
        As of 100.4.0, use SelectionProperties.setColor(int) from your GeoView.
        Sets the color that is applied to a selected feature.
        Parameters:
        selectionColor - an integer representing the selection color as 0xAARRGGBB
        Since:
        100.0.0
      • getSelectionColor

        @Deprecated
        public int getSelectionColor()
        Deprecated.
        As of 100.4.0, use SelectionProperties.getColor() from your GeoView.
        Returns the color applied to a selected feature.
        Returns:
        an integer representing the selection color as 0xAARRGGBB
        Since:
        100.0.0
      • getSelectionWidth

        @Deprecated
        public double getSelectionWidth()
        Deprecated.
        As of 100.4.0, no replacement.
        Gets the width of the selection highlight.
        Returns:
        the width of the selection highlight
        Since:
        100.0.0
      • setSelectionWidth

        @Deprecated
        public void setSelectionWidth​(double width)
        Deprecated.
        As of 100.4.0, no replacement.
        Sets the width of the selection highlight.
        Parameters:
        width - the width of the selection highlight
        Throws:
        IllegalArgumentException - if width is less than 0
        Since:
        100.0.0
      • getSelectedFeaturesAsync

        public ListenableFuture<FeatureQueryResult> getSelectedFeaturesAsync()
        Gets all the features selected.
        Returns:
        a future that represents the selected features
        Since:
        100.0.0
      • clearSelection

        public void clearSelection()
        Clears the selection.
        Since:
        100.0.0
      • resetFeaturesVisible

        public void resetFeaturesVisible()
        Resets all features back to the visible state.
        Since:
        100.0.0
      • resetRenderer

        public void resetRenderer()
        Resets the renderer to the layer's default renderer.
        Since:
        100.0.0
      • selectFeature

        public void selectFeature​(Feature feature)
        Adds the feature to the current selection.
        Parameters:
        feature - the feature to be added to selection
        Throws:
        IllegalArgumentException - if feature is null
        Since:
        100.0.0
      • selectFeatures

        public void selectFeatures​(Iterable<Feature> features)
        Adds features to the current selection.
        Parameters:
        features - the features to be added to selection
        Throws:
        IllegalArgumentException - if features is null
        Since:
        100.0.0
      • setFeatureVisible

        public void setFeatureVisible​(Feature feature,
                                      boolean visible)
        Makes a feature visible or invisible.
        Parameters:
        feature - feature to change visibility of
        visible - true to show, false to hide
        Throws:
        IllegalArgumentException - if feature is null
        Since:
        100.0.0
      • setFeaturesVisible

        public void setFeaturesVisible​(Iterable<Feature> features,
                                       boolean visible)
        Makes multiple features visible or invisible.
        Parameters:
        features - features to change visibility of
        visible - true to show, false to hide
        Throws:
        IllegalArgumentException - if features is null
        Since:
        100.0.0
      • unselectFeature

        public void unselectFeature​(Feature feature)
        Removes a feature from selection.
        Parameters:
        feature - feature to be unselected
        Throws:
        IllegalArgumentException - if feature is null
        Since:
        100.0.0
      • unselectFeatures

        public void unselectFeatures​(Iterable<Feature> features)
        Removes multiple features from selection.
        Parameters:
        features - features to be unselected
        Throws:
        IllegalArgumentException - if features is null
        Since:
        100.0.0
      • getSceneProperties

        public LayerSceneProperties getSceneProperties()
        Gets a layer scene properties object that can be used to make changes to how features are displayed in a SceneView.

        These settings will have no effect if the layer is displayed in a MapView.

        Returns:
        a layer scene properties object
        Since:
        100.2.0
      • setTilingMode

        public void setTilingMode​(FeatureTilingMode tilingMode)
        Sets the feature tiling mode in use by the feature layer.
        Parameters:
        tilingMode - the feature tiling mode to use
        Throws:
        IllegalArgumentException - if tilingMode is null
        Since:
        100.10.0
      • getFullTimeExtent

        public TimeExtent getFullTimeExtent()
        Description copied from interface: TimeAware
        Returns the full time extent of the object. Will be null if the object is not time aware.
        Specified by:
        getFullTimeExtent in interface TimeAware
        Returns:
        the time extent, or null if the object is not time aware
      • getTimeInterval

        public TimeValue getTimeInterval()
        Description copied from interface: TimeAware
        Returns the suggested time slider step size for this time aware object. Can be null if no time interval is suggested for this time aware object.
        Specified by:
        getTimeInterval in interface TimeAware
        Returns:
        the time interval, or null if there is no time interval
      • getTimeOffset

        public TimeValue getTimeOffset()
        Description copied from interface: TimeAware
        Returns the time offset applied to this object. The offset is subtracted from the time extent set on the owning GeoView. This allows for data from different periods of time to be compared.
        Specified by:
        getTimeOffset in interface TimeAware
        Returns:
        the time offset, or null if no offset has been set
      • isTimeFilteringEnabled

        public boolean isTimeFilteringEnabled()
        Description copied from interface: TimeAware
        Returns whether or not the object must use the time extent defined on the owning GeoView to filter its data.
        Specified by:
        isTimeFilteringEnabled in interface TimeAware
        Returns:
        true if time filtering is enabled; otherwise false
      • setIsTimeFilteringEnabled

        public void setIsTimeFilteringEnabled​(boolean enabled)
        Description copied from interface: TimeAware
        Enables or disables whether the object must use the time extent defined on the owning GeoView to filter its data.
        Specified by:
        setIsTimeFilteringEnabled in interface TimeAware
        Parameters:
        enabled - true to enable time filtering; otherwise false
      • isTimeFilteringSupported

        public boolean isTimeFilteringSupported()
        Description copied from interface: TimeAware
        Returns whether or not the object supports filtering its contents by time values with the extent set on the owning GeoView.
        Specified by:
        isTimeFilteringSupported in interface TimeAware
        Returns:
        true if time filtering is supported; otherwise false
      • setTimeOffset

        public void setTimeOffset​(TimeValue timeOffset)
        Description copied from interface: TimeAware
        Sets a time offset for this object. The time offset is subtracted from the time extent set on the owning GeoView. This allows for data from different periods of time to be compared. Can be null if there is no time offset.
        Specified by:
        setTimeOffset in interface TimeAware
        Parameters:
        timeOffset - the time offset, or null if there is no time offset
      • getFloorDefinition

        public LayerFloorDefinition getFloorDefinition()
        Description copied from interface: FloorAware
        Gets the floor definition that defines the properties that allow a layer to be floor-aware.

        When a layer is configured as floor-aware, it has a FloorAware.getFloorDefinition() property that defines properties that allow a layer to be floor-aware. When it is null (default value) the specific layer does not support floor filtering.

        Specified by:
        getFloorDefinition in interface FloorAware
        Returns:
        the floor definition that defines the properties that allow a layer to be floor-aware, or null if none
      • setFloorDefinition

        public void setFloorDefinition​(LayerFloorDefinition floorDefinition)
        Description copied from interface: FloorAware
        Sets the floor definition that defines the properties that allow a layer to be floor-aware.

        When a layer is configured as floor-aware, it has a FloorAware.getFloorDefinition() property that defines properties that allow a layer to be floor-aware. When it is null (default value) the specific layer does not support floor filtering.

        Specified by:
        setFloorDefinition in interface FloorAware
        Parameters:
        floorDefinition - the floor definition that defines the properties that allow a layer to be floor-aware
      • getUnknownJson

        public Map<String,​Object> getUnknownJson()
        Gets unknown data from the source JSON. Unknown JSON is a dictionary of values that was in the source JSON but was not parsed by the Runtime.
        Returns:
        an unmodifiable map with string keys and object values
        Since:
        100.7.0
      • getUnsupportedJson

        public Map<String,​Object> getUnsupportedJson()
        Gets unsupported data from the source JSON. Unsupported JSON is a dictionary of values that are supported by webmaps, but not exposed through the native Runtime API
        Returns:
        an unmodifiable map with string keys and object values
        Since:
        100.7.0