Get layer names for ArcGIS.com webmap

1821
2
Jump to solution
07-16-2012 01:53 PM
TerryGiles
Occasional Contributor III
I'm using code similar to the Load WebMap sample here and have a question.  When I add the layers from the WebMap to my map, the Legend control associated with my map shows GUIDs for the various layer names.  Is there some way to get the names as shown both in the description in ArcGIS.com and the ArcGIS.com map viewer?



I want the 'nice' names as shown in the map description -
[ATTACH=CONFIG]16139[/ATTACH]

Not the IDs that seem to come across from GetMapAsync
[ATTACH=CONFIG]16140[/ATTACH]

Thanks, Terry
0 Kudos
1 Solution

Accepted Solutions
by Anonymous User
Not applicable
Original User: dbroux

Which ArcGIS for SL version are you using?

In 3.0, a DisplayName property has been added on the Layer class.
The DisplayName is a friendly name for printing and legend control.

View solution in original post

0 Kudos
2 Replies
by Anonymous User
Not applicable
Original User: dbroux

Which ArcGIS for SL version are you using?

In 3.0, a DisplayName property has been added on the Layer class.
The DisplayName is a friendly name for printing and legend control.
0 Kudos
TerryGiles
Occasional Contributor III
Thank you for the information Dominique.  I'm still using 2.3 at this time - we're just starting to install & test 10.1 but may move the API to v3.0 to get this working.  In the meantime, it looks like I can hit www.arcgis.com/sharing/content/items/<Item ID>/data?f=json to grab what I need and update the legend control.

Thanks again,

Terry


edit - here's the code to implement my idea above
                       webMap = new Document();
                        webMap.GetMapCompleted += (s, a) =>
                        {
                            if (a.Error == null)
                            {
                                MyMap.Extent = a.Map.Extent;


                                WebClient web = new WebClient();
                                web.OpenReadCompleted += (send, arg) => 
                                {
                                    JsonObject jsObj = (JsonObject)JsonObject.Load(arg.Result);
                                    if (jsObj.ContainsKey("error"))
                                    {
                                        return;
                                    }
                                    if (jsObj.ContainsKey("operationalLayers"))
                                    {
                                        JsonArray layers = (JsonArray)jsObj["operationalLayers"];
                                        foreach (JsonObject jOb in layers)
                                        {
                                            if (jOb.ContainsKey("itemId"))
                                            {
                                                try
                                                {
                                                    MyMap.Layers[jOb["itemId"]].ID = jOb["title"];
                                                }
                                                catch { }
                                            }
                                            else if (jOb.ContainsKey("id"))
                                            {
                                                try
                                                {
                                                    MyMap.Layers[jOb["id"]].ID = jOb["title"];
                                                }
                                                catch { }
                                            }
                                        }
                                    }
                                    if (jsObj.ContainsKey("baseMap"))  
                                    {
                                        JsonObject jOb = (JsonObject)jsObj["baseMap"]; 
                                        if (jOb.ContainsKey("baseMapLayers"))
                                        {                                            
                                            try
                                            {
                                                MyMap.Layers[jOb["baseMapLayers"][0]["id"]].ID = jOb["title"];
                                            }
                                            catch { }
                                        }
                                    }
                                };
                                web.OpenReadAsync(new Uri("http://www.arcgis.com/sharing/content/items/" + mapservice.MapServiceName + "/data?f=json"));
                                LayerCollection layerCollection = new LayerCollection();
                                foreach (Layer lyr in a.Map.Layers)
                                {
                                    layerCollection.Add(lyr);
                                    lyr.InitializationFailed += Layer_InitializationFailed;
                                }

                                a.Map.Layers.Clear();
                                MyMap.Layers = layerCollection;
0 Kudos