ArcGIS Feature Layer
An ArcGIS Feature Layer displays features from a layer of an ArcGIS Server Feature Service or an ArcGIS Server Map Service. You can perform queries and selections on features, and work with feature attachments. When using an ArcGIS Server Feature Service, you can also edit features and their attachments. The feature layer honors defintion queries, scale dependencies, and other properties configured on the service layer.
Feature Services, like Map Services, are based on map documents (*.mxd and *.msd files). A map document contains references to GIS datasets. These datasets contain the features that need to displayed in the map. Features are real world entities such as buildings, pipes, and parcels. Features are organized into layers in a map document. For example, the map document of a national park may contain separate layers for hiking trails, picnic areas and campgrounds. Map documents can be published to ArcGIS Server to create Map and Feature services.
ArcGIS Server Map and Feature services are accessible on the web as SOAP and REST web services. You can find the URL of these web services using the ArcGIS Server Services Directory.
The feature layer retrieves features from the service layer, holds them in memory on the device, and then draws them onto the map using the device's graphics capabilities. This is different from a dynamic layer or a tiled layer which rely on the service to render features into images which are then displayed on the map. Whenever you navigate the map, dynamic and tiled layers fetch new map images to display, but the feature layer may already have all the features it needs to display, or it may fetch some more features. In some cases, a feature layer can be more efficient than a dynamic or tiled layer because it does not have to make frequent round trips to the server.
The feature layer inherits its drawing capabilities from the graphics layer. Thus, in a way, they both provide the same functionality for displaying features. However, one key difference is that the graphics layer requires you to provide the graphics that need to be displayed, whereas the feature layer automatically retrieves them from the service layer. Thus, you should never directly add or remove any graphics from the feature layer like you do with the graphics layer.
Another difference is that the graphics layer requires you to provide either a renderer or the symbols needed for displaying the graphics, whereas the feature layer inherits its symbology from the service layer when the service is hosted on an ArcGIS Server 10 or above. If the service is from an older server, you will need to assign a renderer for the feature layer to symbolize the features.
To instantiate a feature layer you need to provide a URL to a layer in a Map Service of Feature Service REST endpoint. This URL is usually of the form http:<server:port>/<instance>/rest/services/<service>/MapServer/<layerid> or http:<server:port>/<instance>/rest/services/<service>/FeatureServer/<layerid>. You also need to specify a mode while creating the feature layer. The mode decides how the layer will retrieve features from the service layer.
Instantiate a feature layer with REST URL and mode:
String URL = "http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StateCityHighway_USA/MapServer/0";
ArcGISFeatureLayer fLayer = new ArcGISFeatureLayer(URL, MODE.ONDEMAND);
Feature Service Modes
Feature Layers can operate under 3 modes. The default mode is SNAPSHOT mode which you can change when instantiating the layer.
- SNAPSHOT
In snapshot mode, all features belonging to the service layer are retrieved when the feature layer is loaded. This mode is useful only if the number of features is reasonably small. Android applications are constrained by the amount of memory available to them on a device, and it is not practical to hold large numbers of features in memory. The number of features actually retrieved depends upon the limits set on the service. By default, ArcGIS Server 10 services only allow 1000 features to be retrieved, but this could be configured differently by the server administrator. Once the features are retrieved, the layer does not request more features from the service.
- ONDEMAND
In on-demand mode, only features within the map's extent are retrieved from the service layer when the feature layer is loaded. As the user navigates the map, the layer fetches more features for subsequent map extents. Thus, at any time, only those features that need to be displayed are retrieved.
You can customize, to a certain degree, how many and how often features are fetched from the service by adjusting the layer's setBufferFactor() and setExpirationInterval properties. The buffer factor allows the layer to fetch more features than just those that are within the current map extent. For instance, a buffer factor of 2 would allow the layer to fetch features that are within an extent twice as large as the current extent. This could help reduce network requests if subsequent extents fall within the buffered extent. Features will only be fetched when the map's extent goes beyond the buffered extent. The expiration interval forces the layer to re-fetch features that were fetched before the specified interval. This is useful if the data in the service changes frequently and you don't want the layer to display stale features. The etAutoRefreshOnExpiration() method allows you to specify whether the features should be fetched as soon as the expiration interval elapses, or wait until the user navigates the map.
This mode could potentially require more network requests than Snapshot mode because features may be fetched every time you navigate the map. But it also has the potential to use less memory than Snapshot mode as long as the map extents require only a subset of features to fetched from the service layer.
- SELECTION
In selection mode, no features are retrieved when the layer is loaded. Features are retrieved when selection operations are performed. Thus, only those features that are displayed as selected are ever retrieved from the service. This mode is useful if you want to only retrieve specific features and highlight them on the map. You would typically use a feature layer in selection mode on top of a dynamic layer using the same service. Features would normally be displayed by the dynamic layer and the feature layer would be empty. When the user wants to edit some features, a selection operation would be performed on the feature layer and the resulting features would be displayed as selected. User would edit the selected features, and then the selected features would be cleared. The feature layer would go back to being empty and the updated features would be displayed by the dynamic layer.