How to get the fields in each layer of a DynamicMapServiceLayer?

2564
4
Jump to solution
01-22-2016 01:42 PM
FrancisGagne
New Contributor

Here's a bit of code I got:

('layer' is a ArcGISDynamicMapServiceLayer already initialized)

ArcGISLayerInfo[] childLayers = layer.getAllLayers();

for (ArcGISLayerInfo child : childLayers) {

     LayerServiceInfo serviceInfo = child.getLayerServiceInfo();

     for (Field field : serviceInfo.getFields()) {

            childInfo.addFieldName(field.getName());

     }

....

}

When I print the serviceInfo.toString(), I get:

Layers [id=4, name=Lage druk, defaultVisibility=true, parentLayerId=-1,

             subLayerIds=[5, 19, 20, 21, 22],

             geometryType=null,

             fields=null,

             objectIdField=null, globalIdField=null, typeIdField=null,

             featureTypes=null,

             hasAttachments=false,

             definitionExpression=null]

Can I have access to the fields of an DynamicMapServiceLayer like this?

Thanks,

0 Kudos
1 Solution

Accepted Solutions
MengyiGuo
Occasional Contributor

Yes. You need to fetch the information once in your application, otherwise it will be null. Once you fetched it, it will be stored.

fetchLayerServiceInfo asynchronously fetches the LayerServiceInfo for the specified sublayer. If the LayerServiceInfo has already been fetched, then it will simply return that. Otherwise a network request will be made to fetch it. Once it has been fetched, it will be cached so thatgetLayerServiceInfo(int) will return it, and so that it won't be fetched more than once.

View solution in original post

4 Replies
MengyiGuo
Occasional Contributor

getLayerServiceInfo method asked for an integer as sublayerId parameter.

public LayerServiceInfo getLayerServiceInfo (int sublayerId)

ArcGISDynamicMapServiceLayer |  ArcGIS Android 10.2.7 API

You may put this line into the loop with sublayerId and test, change:

LayerServiceInfo serviceInfo = child.getLayerServiceInfo();

to

LayerServiceInfo serviceInfo = child.getLayerServiceInfo(sublayerId);

FrancisGagne
New Contributor

child is a ArcGISLayerInfo

So I tried :

layer.getLayerServiceInfo(child.getId());

but the LayerServiceInfo returned is null.

Do I really need to call fetchLayerServiceInfo(int, CallbackListener). on each sublayers in each of my services?

Thanks,

0 Kudos
MengyiGuo
Occasional Contributor

Yes. You need to fetch the information once in your application, otherwise it will be null. Once you fetched it, it will be stored.

fetchLayerServiceInfo asynchronously fetches the LayerServiceInfo for the specified sublayer. If the LayerServiceInfo has already been fetched, then it will simply return that. Otherwise a network request will be made to fetch it. Once it has been fetched, it will be cached so thatgetLayerServiceInfo(int) will return it, and so that it won't be fetched more than once.

FrancisGagne
New Contributor

Okay, I'll implement that and return here with the result.

Thank you

0 Kudos