Attribute editing

Complexity: Advanced Data Requirement: ArcGIS.com

The purpose of this sample is to demonstrate how to view and edit the attributes of a map layer provided from an ArcGIS Server feature layer (exposed from within a feature server service). It also uses a map server service of the same data and a cached tiled map service from ArcGIS.com as a basemap. Users can click a feature on the map to view the attributes in a dialog box. If the fields are editable, a user can change the attributes of the field. Validation of the field type provides the user with different ways of adding attributes; number fields do not allow text input, date fields provide a date picker dialog box, and fields that are used for defining a subtype provide drop-down lists. Once attributes have been changed, they can be posted to the feature layer in an edit operation.

Sample design

The most important classes in the sample are the classes that extend Activity (AttributeEditorActivity) and BaseAdapter (AttributeListAdapter).

AttributeEditorActivity initializes the MapView and ArcGISFeatureLayer objects with the appropriate onStatusChangedListener and onClickListener method. Activity also contains the logic to launch the attributes dialog box and apply edits once the user has finished changing the attributes.

The AttributeListAdapter class contains the logic to use information from the feature layer and the feature returned from the on-click query to build the attributes dialog box. This includes parsing the field, subtype, and graphic attributes to build up some additional POJO (Plain Old Java Objects) classes to store this information for retrieval when the list is built and for applying the edits. The dialog box is constructed from an Android ListView; each row in the list view is built from other View elements depending on the field type.

The feature layer is added to the map as ArcGISFeatureLayer in Selection mode and is backed by an ArcGIS dynamic map service layer based on the exact data. Clicking the map performs a query on the feature layer, returns the first feature found, and places its attributes into the dialog box. Changes in attribute values are detected from the dialog box, and if changes are found, they are applied to the server using an apply edits operation on the feature service. If an edit has been performed on the subtype field, the underlying ArcGIS dynamic map service layer is also refreshed to show any rendering changes of the edited features (in this example, the subtype field is that which is associated with feature rendering). This approach ensures that the minimum amount of data is passed over the network and is therefore suitable for mobile access using a 3G network. This is due to the often smaller size and quicker display of images returned from an ArcGIS dynamic map service layer than the feature information returned for the same extent for an ArcGIS feature layer (where the JSON response from the server has to be parsed and each feature drawn).

How to use the sample

1. Launch the sample on your device.

2. Click on the map to highlight a feature and view its attributes in a dialog box.

3. Edit the attributes of the feature. Notice how decimal fields don't allow alphanumeric characters but do allow dots (.) and minus signs (-) in the right place, text fields allow all characters, date fields provide a date picker dialog box, and type fields display a list of available types.

4. Choose to apply the changes you have made to the server or discard the changes.

If you have changed the subtype of the feature, the underlying map service is redrawn and the symbology of the feature you have edited is updated to the appropriate renderer.

5/31/2012