Select to view content in your preferred language

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

2765
4
Jump to solution
01-22-2016 01:42 PM
FrancisGagne
Emerging 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
Deactivated User

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
Deactivated User

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
Emerging 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
Deactivated User

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
Emerging Contributor

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

Thank you

0 Kudos