FeatureLayer dataChanged fails.

1830
4
05-24-2011 03:02 PM
MichaelMurphy8
New Contributor
So far I've tried to refresh the FeatureLayer after I apply edits to it by calling dataChanged.  The point gets added at Lat/Lon of 0/0, instead of at the correct location.  If I remove/add the layer to the mapView, it shows up in the correct location. 

                AGSFeatureLayer *flayer = (AGSFeatureLayer*)theLayer;
                NSArray *types = flayer.types;
                AGSFeatureType *theType = [types objectAtIndex:0];
                NSArray *templates = theType.templates;
                AGSFeatureTemplate *theTemplate = [templates objectAtIndex:0];
                AGSGraphic *theFeature = [flayer createFeatureWithTemplate:theTemplate];
                
                [theFeature.attributes setValue:message forKey:@"Description"];
                [theFeature setGeometry:[AGSPoint pointWithX:longitude y:latitude spatialReference:[AGSSpatialReference wgs84SpatialReference]]];
                NSOperation *result = [flayer addFeatures:[NSArray arrayWithObject:theFeature]];
                [flayer dataChanged];


Also, I tried in the class where I implemented AGSFeatureLayerEditingDelegate...  Still no joy.

- (void)featureLayer:(AGSFeatureLayer *)featureLayer operation:(NSOperation *)op didFeatureEditsWithResults:(AGSFeatureLayerEditResults *)editResults {
    NSArray *addResults = editResults.addResults;
    AGSEditResult *addResult = [editResults.addResults objectAtIndex:0];
    
    if(addResult.success) {
        [featureLayer dataChanged];
        mICATViewController *ref = [mICATViewController sharedManager];
        if (ref.image != nil) {
            NSString *filename = [ref.imagePickerDelegate saveImageToTempFile:ref.image];
            [featureLayer addAttachment:addResult.objectId filepath:filename];
            [ref setImage:nil];
        }
    } else {
        NSLog(@"UGH. NOW WHAT");
    }
}


Any ideas????
0 Kudos
4 Replies
MichaelMurphy8
New Contributor
To follow up:  I was able to specify set

featureLayer.expirationInterval = 30;
featureLayer.autoRefreshOnExpiration = YES;


But this is kind of kludgy.  If I'm successful in adding the feature, it should get updated immediately on the client without having to wait for the timer to expire.
0 Kudos
PaulLohr
Occasional Contributor III
This is kind of old but what the heck.

Is the spatial reference of the first layer added to the mapView the same as the feature layer you add afterwards? Or perhaps I am misunderstanding.

Also, you mentioned that you remove the feature layer and then add it back in to get the features to display at the correct location. And, if you don't remove/add your features, they show up at 0,0. I did not see the remove/add operation in your code. You don't have to share this but I am interested since this is similar to a problem I am having with AGSGraphic.

Paul Lohr
0 Kudos
DiveshGoyal
Esri Regular Contributor
This is in response to madgame's original post.

I'm wondering if geometry of the new feature being added is NOT in the same spatial reference as the map. I notice that in the code he is explicitly assigning WGS84 to the feature's geometry, and this should be okay if the map is in WGS84 too.

Else, the lat/long values should be projected into the map's spatial reference (using AGSGeometryEngine) and then the projected values should be used with the feature's geometry. Ofcourse, the feature's geometry's spatial reference should be set to the map's spatial reference too.
0 Kudos
PaulLohr
Occasional Contributor III
This makes sense, Nimesh.

madgame,
What is the URL of the REST endpoint for the first layer that is added to the map? I think this will help us determine if we are talking about a spatial reference issue.
0 Kudos