Legend

831
5
07-30-2012 10:23 AM
BrianGustafson
New Contributor III
Are there any samples on using a legend with a service that is hosted from my ArcGIS Server.  I keep getting errors when I try to usethe get legend method on the LayerInfos.
0 Kudos
5 Replies
tempJamiePowell
New Contributor
I dont see any samples currently available. What are the errors produced?
0 Kudos
BrianGustafson
New Contributor III
The return from requesting the legend items is always null.  Then when I try and access that collection it throws a nullpointerexception.
0 Kudos
tempJamiePowell
New Contributor
Do you get the same result when accessing any other services, or is it specific to that service?
0 Kudos
SimonKlein
Occasional Contributor
Are you using 10.1 on your server?
0 Kudos
EgorFedorov
New Contributor

According to documentation, to have layer legend info available for your ArcGISDynamicMapServiceLayer you must call retrieveLegendInfo() method on this layer instance. Also it must be called in separate thread. The following seems to be good approach:

mapView.setOnStatusChangedListener(new OnStatusChangedListener() {

                    @Override

                    public void onStatusChanged(Object o, STATUS status) {

                        if (status == STATUS.LAYER_LOADED) {

                            if (o instanceof ArcGISDynamicMapServiceLayer) {

                                //retrieving legend info

                                new AsyncTask<Void, Void, Void>() {

                                    @Override

                                    protected Void doInBackground(Void... voids) {

                                        dynamicLayer.retrieveLegendInfo();

                                        return null;

                                    }

                                }.execute();

                            }

                        }

                    }

                });

0 Kudos