ArcGIS remote map service - cannot set sublayer visibility property

1316
1
Jump to solution
09-13-2012 01:30 AM
by Anonymous User
Not applicable
Original User: theskyishard

Hi all,

I am trying to connect to a remote ArcGIS map service (not using REST) and provide the ability for users to toggle the visibility of the sub layers defined within the retrieved map. I am working in C# and an integrating ArcGIS 10.1 into a stand-alone application.

I am able to pull down the main map and store a list of the sublayers in order to keep track of names and visibility (I am only interested in going one step deep, I am not worried about any sublayers beneath the first set), but when I attempt to set the visibility property on a sublayer, the property appears to immeadiately change itself back to the original value... which is confusing me slightly (a lot!).

This is the offending block of code, see the example app for more detail:

        /// <summary>         /// Loads the layer from the remote map server info contained in the MapLayer object         /// </summary>         /// <param name="layer">MapLayer to load</param>         public void LoadLayerFromRemoteServer(MapLayer layer)         {             AGSServerConnectionFactory AGSConnectionFactory = new AGSServerConnectionFactoryClass();              IPropertySet2 propertySet = new PropertySetClass();             propertySet.SetProperty("URL", layer.HostPath);              IAGSServerConnection AGSServerConnection = AGSConnectionFactory.Open(propertySet, 0);              var serverObjectNames = AGSServerConnection.ServerObjectNames;             var objectName = serverObjectNames.Next();              while (objectName != null)             {                 if ((objectName.Name == layer.ServiceName) && (objectName.Type == "MapServer"))                 {                     // Found our map service!                     break;                 }                  objectName = serverObjectNames.Next();             }              IName name = (IName)objectName;             var mapServer = (IMapServer)name.Open();              // Connect to the map service             IMapServerLayer mapServerLayer = new MapServerLayerClass();             mapServerLayer.ServerConnect(objectName, mapServer.DefaultMapName);              ICompositeLayer2 compositeLayer = mapServerLayer as ICompositeLayer2;              if (layer.MapSubLayers.Count > 0)             {                 for (int subLayerIndex = 0; subLayerIndex < compositeLayer.Count; subLayerIndex++)                 {                     ILayer2 mapSubLayer = compositeLayer.get_Layer(subLayerIndex) as ILayer2;                      foreach (var subLayer in layer.MapSubLayers)                     {                         if (string.Compare(subLayer.Name, mapSubLayer.Name, StringComparison.InvariantCultureIgnoreCase) == 0)                         {                             Console.WriteLine("Layer visible before change: {0}", mapSubLayer.Visible);                              // This is the line that fails to behave as expected!!!                             ((ILayer)mapSubLayer).Visible = subLayer.IsDisplayed;                              Console.WriteLine("Layer visible after change: {0}", mapSubLayer.Visible);                              Console.ReadLine();                         }                     }                 }             }         }


I have tried a few different ways of setting the visibility by casting the layers into different types now and have trawled google and the forums without any success, but being fairly new to working with ArcGIS (this being my crash course on the subject) I am hoping that I am just missing something trivial.

I have written a small console app to demonstrate the problem, which contains all the relevant logic from the application I am trying to integrate. You shouldn't have to do anything more than provide a couple of referenced ESRI DLLs to build it, but let me know if you have any issues.

Can anyone provide any insights into what could be causing the issue and possible solutions?
0 Kudos
1 Solution

Accepted Solutions
by Anonymous User
Not applicable
Original User: theskyishard

Just in case this helps anyone in future as the documentation is not too friendly to newbies or people who don't know exactly what they are looking for (a difficult problem to solve I admit), I have managed to find the reason that I could not set the layer visibility...

The map service I was attempting to connect to was using a fused cache, which restricts certain layer actions (one of which being able to change layer visibility) without providing any sort of helpful feedback through the property calls.

If any ESRI employees are watching, throwing an exception back to the user if the ILayer.Visibility property setter is incorrectly used against a fused cache or at least noting this restriction in the docs for the property (i.e. where people will first look when they encounter these issues) would be really handy!

Ultimately, the restrictions on fused caches mean that short of instructing our users to set up every sub layer as a separate map service with fused cache so they can be toggled, this cannot be easily worked around (at least in my situation) and as of 10.1, fused caching (I believe) will be the only option available to map services, meaning this is likely to be a recurring headache.

More details on fused caches can be found here in case it helps others.

Thanks for everyone who may have spent some time viewing or trying to help on this subject even if no one posted any solutions.

View solution in original post

0 Kudos
1 Reply
by Anonymous User
Not applicable
Original User: theskyishard

Just in case this helps anyone in future as the documentation is not too friendly to newbies or people who don't know exactly what they are looking for (a difficult problem to solve I admit), I have managed to find the reason that I could not set the layer visibility...

The map service I was attempting to connect to was using a fused cache, which restricts certain layer actions (one of which being able to change layer visibility) without providing any sort of helpful feedback through the property calls.

If any ESRI employees are watching, throwing an exception back to the user if the ILayer.Visibility property setter is incorrectly used against a fused cache or at least noting this restriction in the docs for the property (i.e. where people will first look when they encounter these issues) would be really handy!

Ultimately, the restrictions on fused caches mean that short of instructing our users to set up every sub layer as a separate map service with fused cache so they can be toggled, this cannot be easily worked around (at least in my situation) and as of 10.1, fused caching (I believe) will be the only option available to map services, meaning this is likely to be a recurring headache.

More details on fused caches can be found here in case it helps others.

Thanks for everyone who may have spent some time viewing or trying to help on this subject even if no one posted any solutions.
0 Kudos