Dynamic Populating list of available Layers?????

297
3
06-23-2011 06:16 AM
JeffPapirtis
New Contributor III
Hi All,

I have created applications in the past by hard coding an NSArray of available layers that my company currently serves in our MapServices, but the services are constantly changing and layers are added or removed constantly within the map service.

I have looked at trying to access the mapLayers function to return an array of available layers in the service but have not had any luck.

So in Summary I am looking to:
Create Dynamic List of Layers to display in a UITableView

I am not sure if JSON is the correct route, or if there is an alternative.  Any suggestions or hints on the direction to follow would be appreciated.

Thanks,
Jeff
0 Kudos
3 Replies
JeffPapirtis
New Contributor III
Add another wrinkle...

I have half got this figured out.  I have gone down the json route and am able to pull out the information that I need dynamically to populate a list. 

to do this I created a dictionary and read in the values from my rest service:

- (void)viewDidLoad
NSURL *_serviceURL = [NSURL URLWithString:@"yourWebServerAddress=json&pretty=true "];
    NSString *_layerNames = [[NSString alloc] initWithContentsOfURL:_serviceURL encoding:NSASCIIStringEncoding error:NULL];
   
    //Pick my dictionary from the rest service
    NSMutableDictionary* jSonDict = [_layerNames JSONValue];
    _keys = [jSonDict valueForKey:@"layers"]; //_keys is an array that I have defined in the header.

   
    //get my array that I am interested in:
    _name = [_keys valueForKey:@"name"]; //_name is an array that I have defined in the header.
   
   //print the array to make sure it works
   NSLog(@"_name %@",_name);

}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [_name count];
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
   
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }
//set up my tableview to populate the list.
   [[cell textLabel]
    setText:[_name objectAtIndex:indexPath.row]];
    // Configure the cell.
    return cell;
}


My only issue now is that get a sigbart error when I scroll the list.

hope this helps anyone else curious about dynamic lists.

Will post if I find the issue with sigbart.

jeff
0 Kudos
JeffPapirtis
New Contributor III
found that if I copy the array my project does not crash.

_name = [[_keys valueForKey:@"name"] copy];

Jeff
0 Kudos
NimeshJarecha
Esri Regular Contributor
Jeff,

You can populate your list of all available layers in a dynamic map service.

All map service layers (Tiled and Dynamic) has property "mapServiceInfo" of type AGSMapServiceInfo. The AGSMapServiceInfo has layerInfos property which has all information of available layers in the map service and their default visibility as an array of AGSMapServiceLayerInfo objects.

Regards,
Nimesh
0 Kudos