Select to view content in your preferred language

Legend

1040
5
07-30-2012 10:23 AM
BrianGustafson
Occasional Contributor
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
Emerging Contributor
I dont see any samples currently available. What are the errors produced?
0 Kudos
BrianGustafson
Occasional Contributor
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
Emerging Contributor
Do you get the same result when accessing any other services, or is it specific to that service?
0 Kudos
SimonKlein
Regular Contributor
Are you using 10.1 on your server?
0 Kudos
EgorFedorov
Occasional 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