/// <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(); } } } } }
Solved! Go to Solution.