For services added programmatically, ID is not displayed in Map Contents

1903
4
02-16-2012 01:08 AM
SamitChakraborty
New Contributor
Hi,

I am trying to add FeatureLayer, ArcGISDynamicMapServiceLayer, and ArcGISTiledMapServiceLayer programmatically through code.
However although the services get added, I am unable to see their IDs.
Attached is a screenshot (IDs not displaying1.jpg).
Is this a bug with ArcGIS API for Sharepoint 2.1.1?
The code I am using used to work perfectly fine with ArcGIS API for Sharepoint 2.0, that is the ID for each service would appear.

Code I am using is below (Note: I am setting the ID property everywhere):-

                if (((SecuredServiceList)(lstBox.Items[index])).Tick == true && ((SecuredServiceList)(lstBox.Items[index])).LayerType == "FeatureLayer")
                {
                    FeatureLayer layer = new FeatureLayer()
                    {
                        Url = ((SecuredServiceList)(lstBox.Items[index])).Name,
                        ID = ((SecuredServiceList)(lstBox.Items[index])).ID,
                        ProxyUrl = proxyurl
                    };

                    layer.Where = "1=1";
                    layer.OutFields.Add("*");

                    layer.InitializationFailed += layer_InitializationFailed;
                    MapApplication.Current.Map.Layers.Add(layer);
                }

                if (((SecuredServiceList)(lstBox.Items[index])).Tick == true && ((SecuredServiceList)(lstBox.Items[index])).LayerType == "RasterLayer" && ((SecuredServiceList)(lstBox.Items[index])).ContainsTileInfo == true)
                {

                    ArcGISTiledMapServiceLayer layer = new ArcGISTiledMapServiceLayer()
                    {
                        Url = ((SecuredServiceList)(lstBox.Items[index])).Name,
                        ID = ((SecuredServiceList)(lstBox.Items[index])).ID,
                        ProxyURL = proxyurl
                    };

                    layer.InitializationFailed += layer_InitializationFailed;
                    MapApplication.Current.Map.Layers.Add(layer);
                }



                if (((SecuredServiceList)(lstBox.Items[index])).Tick == true && ((SecuredServiceList)(lstBox.Items[index])).LayerType == "RasterLayer" && ((SecuredServiceList)(lstBox.Items[index])).ContainsTileInfo == false)
                {

                    ArcGISDynamicMapServiceLayer layer = new ArcGISDynamicMapServiceLayer()
                    {
                        Url = ((SecuredServiceList)(lstBox.Items[index])).Name,
                        ID = ((SecuredServiceList)(lstBox.Items[index])).ID,
                        ProxyURL = proxyurl
                    };

                    layer.InitializationFailed += layer_InitializationFailed;
                    MapApplication.Current.Map.Layers.Add(layer);
                }

Has anyone faced a similar problem and come up with a resolution?
Thanks.


-- Samit
0 Kudos
4 Replies
SamitChakraborty
New Contributor
This fixed the problem!

layer.SetValue(MapApplication.LayerNameProperty, layer.ID);
0 Kudos
JulianStarke
New Contributor II
Wehre did you add your fixed line of code? Or which line did you replace?

I have not the same, but a simmiliar problem trying to add WMS-Layers. But at my side there is displayed just nothing in the Map-Contents.
0 Kudos
SamitChakraborty
New Contributor
Add that line before MapApplication.Current.Map.Layers.Add(layer);
In my code specifically, it was done at 3 places.
Hope that helps!

Regards,
Samit Chakraborty
0 Kudos
KatherineDalton
Esri Regular Contributor
Re:WMSLayer question - Chiming in here to add that you may instead want to use MapApplication.SetLayerName(wmsLayer, layerName);. If you use wmsLayer.SetValue(MapApplication.LayerNameProperty, layerName);, you'll need to explicitly set the wmsLayer.ID property. You can actually use MapApplication.SetLayerName(wmsLayer, layerName); for any layer, though.

Katy
Katy Dalton | Technical Consultant
THE SCIENCE OF WHERE™
0 Kudos