Editing feature layers
Access to the feature service through feature layers
Web editing requires a feature service to provide the symbology and feature geometry of your data. The feature service is just a map service with the Feature Access capability enabled. This capability allows the map service to expose feature geometries and their symbols in a way that is easy for applications to use and update.
Before you build an application that performs editing, you need to do some work to create a feature service exposing the layers that you want to be edited. This involves setting up a map document and, optionally, defining some templates for editing. Templates allow you to pre-configure the symbology and attributes for some commonly-used feature types. For example, to prepare for editing roads, you might configure templates for "Controlled Access Freeway", "Other Divided Highway", "State Highway", and "Local Road". Templates are optional, but they make it easy for the end user of the application to create common features.
Once your map is finished, you need to decide how your feature layer will be accessed and used by your application. If your application will be getting the layer from a remote ArcGIS Web Service, you need to publish the map as a Feature Service to ArcGIS Server with the Feature Access capability enabled. This creates REST URLs, or endpoints, to both a map service and a feature service. You will use these URLs to reference the services in your application.
Feature services are accessible in the Runtime SDKs through a type of layer called a feature layer. Feature layers can do a variety of things and can reference either map services or feature services; however, when you use a feature layer for editing purposes you need to reference a feature service.
The following code shows how to programmatically add an editable Feature Layer from an ArcGIS Server instance to your application. A URL string to the Feature Service is used in the constructor of an ArcGISFeatureLayer object.
Adding a feature layer to your map from an ArcGIS Server service
ArcGISFeatureLayer incidentsLayer = new ArcGISFeatureLayer( "http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/SanFrancisco/311Incidents/FeatureServer/0"); map.getLayers().add(incidentsLayer);
If your feature layer is going to be accessed locally (not from an ArcGIS Server Service, for example), you will create a Map Package from your prepared map document. This packages all of the layer information, templates, symbology and data sources into a single '.mpk' file. In your application code, you will access the feature layer by referencing this Map Package in the constructor of an ArcGISLocalFeatureLayer object, as shown in the following code example. Also in the constructor, you'll indicate the index position of the layer in the Map Package, and whether or not the features are to be edited. Since this is a topic on editing, this argument is "true".
Adding a feature layer to your map from a local Map Package
ArcGISLocalFeatureLayer featureLayer = new ArcGISLocalFeatureLayer("/data/mpks/pois.mpk",0,true); map.getLayers().add(featureLayer);
When you perform editing, your application tells the feature layer which attributes have changed and, if applicable, how the geometry changed. The feature layer also displays the updated features after editing. You can call the applyEdits method on the feature layer to apply the edits, which then commits them to the database.