In this topic
XWhen the feature layer displays features, with an editable ArcGIS feature service, you can make changes to those features, delete them, or add new features to the service. It is possible that the server administrator may have disabled the editing capability of the feature service so make sure that the layer is editable before making any edits. You can determine if a layer is editable by looking for edit operations on the Services Directory page for the feature service layer.
You can also programmatically check if a layer is editable by inspecting the
editable property as follows:
NSLog(@"Layer does not support editing");
To modify an existing feature, you need a reference to the
AGSGraphic object. You can get the graphic in a
variety of ways, for example, in response to a user clicking the
map, or by iterating through the graphics collection of the layer. If you
know the ObjectID of the feature you're looking for, you can find
its corresponding graphic by using the convenience
Once you have a reference to the graphic, you can make changes
to its geometry or attributes. These changes are only applied
on the computer and the service remains unmodified. Call
updateFeatures: when you are ready
to post your changes to the service.
//modify the graphic
AGSGraphic* graphic = ... ;
graphic.geometry = newGeometry;
[graphic.attributes setValue:@"<new-value>" forKey:@"<field-name>"];
//update the service
[featureLayer updateFeatures:[NSArray arrayWithObject:graphic]];
The feature layer informs its
editingDelegate when edit
operations succeed or encounter errors. Set one of your
classes as the feature layer's
editingDelegate to receive results
of successful operations and to handle errors.
To delete features, use
deleteFeaturesWithObjectIds:passing in an array of ObjectIDs of features that need to be
deleted, or you can delete features based on attribute or spatial
deleteFeaturesWithWhereClause:geometry:spatialRelation:. In both
cases, features are removed from the layer and service.
[featureLayer deleteFeaturesWithWhereClause:@"<field-name> = <value>" geometry:nil spatialRelation:nil];
To add a new feature, construct a graphic for it. To construct a graphic, specify a feature type or feature template.
Features in a layer can be of many types. For example, schools can be of type public or private. Each type may display with a different symbol on the map. To create a new school feature, specify its type (if it should be a public school or a private school).
A feature template provides default settings for a feature, for
example, its attribute values. Templates make it easy to create new
features. A layer can have multiple templates or if the layer
has feature types, each type can have one or more templates. Feature types and feature templates are defined by the service, and are available on the layer through the types and templates properties.
AGSFeatureType* privateSchool = [featureLayer.types objectAtIndex:index];
AGSGraphic* newSchool = [featureLayer featureWithType:privateSchool];
Even when you have constructed the graphic, note that it is still not added to the layer and won't display on the map. Call
addFeatures: if you are ready to add the feature to the service. When this operation succeeds, the graphic is automatically added to the feature layer and displays on the map.
[featureLayer addFeatures:[NSArray arrayWithObject:newSchool]];
If you do not want to immediately persist the graphic to the feature service, manually add it to the feature layer's
graphics collection by using
addGraphic:. If the graphic has a valid geometry, it is displayed by the map. You can later call
addFeatures: to persist the graphic to the service. If you decide not to persist the graphic, manually remove it from the feature layer by using
Each add, delete, and update operation is performed over a separate network request. If you are performing a large number of edits, it is expensive to perform them as separate operations. When possible, it is more efficient to perform all edits in a batch over a single network request using