cannot edit/add on feature layer

3141
2
Jump to solution
09-02-2015 08:39 PM
QKunZhu
New Contributor II

My testing server has the following functions:

Screen Shot 2015-09-03 at 11.31.46.png

I want to draw a polygon and add the new polygon to this layer, but all the property canCreate/canDelete/canUpdate/canUpdateGeometry return NO, and of course, I failed to add graphic to this layer. Is anything I missing?

AGSGraphic *newGraphic = [AGSGraphic graphicWithGeometry:self.sketchLayer.geometry symbol:[self getMapSymbolByType:eIfosMapSymbolTypePolygon] attributes:@{@"attire":@"testttt", @"attr2":@"test22"}];
AGSFeatureLayer *inspectionLayer = [AGSFeatureLayer featureServiceLayerWithURL:[NSURL URLWithString:LAYER_URL_STR] mode:AGSFeatureLayerModeSnapshot];
inspectionLayer.editingDelegate = self;
// return NO
if (inspectionLayer.canCreate) {
     NSLog(@"can create");
}

// return NO
if (inspectionLayer.canDelete) {
     NSLog(@"can delete");
}

// return NO
if (inspectionLayer.canUpdate) {
     NSLog(@"can update");
}

// return NO
if (inspectionLayer.canUpdateGeometry) {
     NSLog(@"can  update geometry");
}

[inspectionLayer applyEditsWithFeaturesToAdd:[NSArray arrayWithObject:newGraphic] toUpdate:nil toDelete:nil];
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
Nicholas-Furness
Esri Regular Contributor

It looks like the inspectionLayer will not have had a chance to reach out to the REST endpoint to interrogate whether it can handle edits yet or not. The inspectionLayer.loaded property will be false, and you can't use the layer until it's true.

Either instantiate the AGSFeatureLayer earlier in your app (perhaps on viewDidLoad) and store it as a property, or else set its delegate property and wait to receive the AGSLayerDelegate::layerDidLoad message before inspecting the properties or saving the feature. I recommend the former. It's a lightweight object and fine to keep around like that.

As some background: To avoid blocking the main thread, the action of reaching out to the REST endpoint is queued up and requires the run loop to free up before the round-trip HTTP request happens. This won't happen anywhere between lines 2 and 24 in your sample (the "AGSFeatureLayer::loaded" property will be false). This is true of all components in the runtime that make potentially lengthy URL requests (tasks, layers, portals, etc.).

View solution in original post

0 Kudos
2 Replies
Nicholas-Furness
Esri Regular Contributor

It looks like the inspectionLayer will not have had a chance to reach out to the REST endpoint to interrogate whether it can handle edits yet or not. The inspectionLayer.loaded property will be false, and you can't use the layer until it's true.

Either instantiate the AGSFeatureLayer earlier in your app (perhaps on viewDidLoad) and store it as a property, or else set its delegate property and wait to receive the AGSLayerDelegate::layerDidLoad message before inspecting the properties or saving the feature. I recommend the former. It's a lightweight object and fine to keep around like that.

As some background: To avoid blocking the main thread, the action of reaching out to the REST endpoint is queued up and requires the run loop to free up before the round-trip HTTP request happens. This won't happen anywhere between lines 2 and 24 in your sample (the "AGSFeatureLayer::loaded" property will be false). This is true of all components in the runtime that make potentially lengthy URL requests (tasks, layers, portals, etc.).

0 Kudos
QKunZhu
New Contributor II

Thank you so much Nicholas. I use the AGSLayerDelegate::layerDidLoad to dismiss my loading screen after loading and then it's able to commit the new created graphic.It works fine now.

0 Kudos