ebrightc

Spatial Reference from local Feature Layer

Discussion created by ebrightc on Jun 14, 2011
Latest reply on Jun 24, 2011 by muratdzhusupov
I am trying to build an app that can function entirely independent of network connections. I have successfully mapped data that is stored on the device as JSON formatted text files to feature layers. But, if I don't first load a map service layer from a server, the map layers will not display. In the documentation, it reads that the mapview will take on the spatial reference of the first layer that is loaded. Unfortunately, I can't get that to work with my local file. 

Here is my code to load the local file:

 NSString *filePath_states = [[NSBundle mainBundle] pathForResource:@"ESRI_States" ofType:@"json"];
 NSString *text_states = [NSString stringWithContentsOfFile:filePath_states];
 SBJsonParser *parser = [[SBJsonParser alloc] init];
NSDictionary *dict_states = [parser objectWithString:text_states];
 NSDictionary *layerDef_states = [[NSDictionary alloc] initWithObjectsAndKeys:[dict_states objectForKey:@"geometryType"] ,@"geometryType",nil];
 NSDictionary *featureSet_states = [[NSDictionary alloc] initWithObjectsAndKeys:[dict_states objectForKey:@"features"],@"features",[dict_states objectForKey:@"displayFieldName"],@"displayFieldName",
          [dict_states objectForKey:@"spatialReference"],@"spatialReference",nil];
 self.statesLayer = [[AGSFeatureLayer alloc] initWithLayerDefinitionJSON:layerDef_states featureSetJSON:featureSet_states];
self.statesView = [self.mapView addMapLayer:self.statesLayer withName:@"States"];


I have omitted my renderer, because i didn't think it was relevant. The layer renders fine if the map service layer is there.

Outcomes