Accessing Map service info?

1071
13
08-18-2010 07:37 AM
AndrewEgleton
New Contributor III
Hi,

I'm trying to read the visible status of individual layers in a map service at start up so I can set if they are visible or not, but I am having no luck accessing the Map Service Info, here is my code:

 // Get indexes of visible layers
 AGSMapServiceInfo *dynaServiceInfo = self.dynamicLayer.mapServiceInfo;
 AGSMapServiceLayerInfo *dynaLayerInfo;
 NSMutableArray *visibleLayers = [NSMutableArray arrayWithCapacity:[dynaServiceInfo.layerInfos count]];
 for (int i = 0; i < [dynaServiceInfo.layerInfos count]; i++) {
  dynaLayerInfo = [dynaServiceInfo.layerInfos objectAtIndex:i];
  if (dynaLayerInfo.visible == YES) {
   [visibleLayers addObject:[[NSNumber alloc] initWithInt:i]];
  }
 }


My AGSMapServiceInfo object is always empty, but I'm not sure what I'm doing wrong. I've also tried directly accessing the layerInfos, and creating an array from them with no success either.
Any help appreciated.

Andy.
0 Kudos
13 Replies
MarcoBrugna
New Contributor II
Use this way:

AGSMapServiceInfo *serviceInfo = [[AGSMapServiceInfo alloc] initWithURLSynchronous:[NSURL URLWithString:aLayer.url]]; 
AGSDynamicMapServiceLayer *dynLayer = [[AGSDynamicMapServiceLayer alloc] initWithMapServiceInfo:serviceInfo]; 



so when you access to dynLayer.mapServiceInfo it will be not empty.
0 Kudos
AndrewEgleton
New Contributor III
Thanks, that work perfectly!

I'm slowly getting my head around the iPhone SDK/Objective C, but its very different to C#!
0 Kudos
KOLDODUARTE
New Contributor
Use this way:

AGSMapServiceInfo *serviceInfo = [[AGSMapServiceInfo alloc] initWithURLSynchronous:[NSURL URLWithString:aLayer.url]]; 
AGSDynamicMapServiceLayer *dynLayer = [[AGSDynamicMapServiceLayer alloc] initWithMapServiceInfo:serviceInfo]; 



so when you access to dynLayer.mapServiceInfo it will be not empty.


In the new API 1.0 this is not works me, previusly with the Beta versions It is works perfectly, but now no, someone knows?

Thanks & Best Regards,
Koldo.
0 Kudos
NimeshJarecha
Esri Regular Contributor
The AGSMapServiceInfo::initWithURLSynchronous has been renamed to AGSMapServiceInfo::initWithURL:error:. Please refer Migration doc for detail of all changes.

You can refer ArcGIS Dynamic Map Service Layer doc as well.

Regards,
Nimesh
0 Kudos
KOLDODUARTE
New Contributor
The AGSMapServiceInfo::initWithURLSynchronous has been renamed to AGSMapServiceInfo::initWithURL:error:. Please refer Migration doc for detail of all changes.

You can refer ArcGIS Dynamic Map Service Layer doc as well.

Regards,
Nimesh


Hi Nimesh,

I read all changes and I applied it, now I have this code, for example:
NSURL *url = [NSURL URLWithString: @"http://services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer"];

AGSMapServiceInfo *serviceInfo = [AGSMapServiceInfo mapServiceInfoWithURL:url error:nil];

AGSDynamicMapServiceLayer *dynLayerInfo = [AGSDynamicMapServiceLayer dynamicMapServiceLayerWithMapServiceInfo:serviceInfo]; 
 
NSString *info = dynLayerInfo.mapServiceInfo.serviceDescription;


Just it breaks in first line and I don´t know why!

Attach the error!
0 Kudos
NimeshJarecha
Esri Regular Contributor
You should pass the 'error' like below. It'll be populated if there is an error in creating instance of AGSMapServiceInfo.

NSError *error = nil;
AGSMapServiceInfo *serviceInfo = [AGSMapServiceInfo mapServiceInfoWithURL:url error:&error];

Hope this helps!

Regards,
Nimesh
0 Kudos
KOLDODUARTE
New Contributor
You should pass the 'error' like below. It'll be populated if there is an error in creating instance of AGSMapServiceInfo.

NSError *error = nil;
AGSMapServiceInfo *serviceInfo = [AGSMapServiceInfo mapServiceInfoWithURL:url error:&error];

Hope this helps!

Regards,
Nimesh


Ok, now it is good, thank you!.. one more.
0 Kudos
KOLDODUARTE
New Contributor
I were mistaken, sorry!

Please, someone tries this code:

NSError *error = nil; 
 
 NSURL *url = [NSURL URLWithString: @"http://services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer"];
 
 AGSMapServiceInfo *serviceInfo = [AGSMapServiceInfo mapServiceInfoWithURL:url error:&error];
 
 AGSDynamicMapServiceLayer *dynLayerInfo = [AGSDynamicMapServiceLayer dynamicMapServiceLayerWithMapServiceInfo:serviceInfo]; 
 
 NSString *info = dynLayerInfo.mapServiceInfo.serviceDescription;
  
 UIAlertView *vModal = [[UIAlertView alloc]
         initWithTitle:@"Map Service error"
         message:info
         delegate:self
         cancelButtonTitle:@"Done"
         otherButtonTitles:nil, nil];
 [vModal show];
 [vModal release];


The error is:
0 Kudos
NimeshJarecha
Esri Regular Contributor
You are trying to access the layer information before it finished initialization. When the layer is ready, its loaded property will be enabled. You can then safely access its properties.

if(dynLayerInfo.loaded){
NSLog(@"Initial Envelope : %@", dynLayerInfo.initialEnvelope);
}

Regards,
Nimesh
0 Kudos