laptop and a wrench

Bug

Cannot programmatically change the visibility of a ArcWebServices layer using IMapFunctionality.

Last Published: August 25, 2014 No Product Found
Bug ID Number NIM034021
SubmittedApril 8, 2008
Last ModifiedJune 5, 2024
Applies toNo Product Found
Version found9.2
Program languageVB.Net
StatusKnown Limit

Additional Information

No Public Explanation

Workaround

I found that the SetLayerVisibility method works fine in a IMapServerCommandAction.ServerAction as long as a TOC.Refresh is NOT called in order to synchronize the TOC with the current visibility settings of the layer. When you do this, the layer visibility reverts back to the default setting in the Map service. Secondly, I found that the GetLayerVisibility method always returns true no matter what the current visibility setting of the layer is. At this time, the only work around that I could come up with is to make the ArcWebService service not visible in the TOC so you do not have to synchronize the Map with the TOC when the layer visibility changes, then maintain the visibility of the layers in the ArcWebService Map service in the Session (to work around the problem with GetLayerVisibility) and then use it to toggle the visibility of one or more layers.Implementation of the work around in <a href="http://VB.NET" target="_blank">VB.NET</a>: 'Store the visibility of the layers into the Session state by using a unique key created based on the layer name and layer id Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load If Not (IsPostBack) Then Dim func As ESRI.ArcGIS.ADF.Web.DataSources.IMapFunctionality = CType(Map1.GetFunctionality("MapResourceItem0"), ESRI.ArcGIS.ADF.Web.DataSources.IMapFunctionality) Dim strLyrID As String() = Nothing Dim strLyrName As String() = Nothing func.GetLayers(strLyrID, strLyrName) Dim i As Integer For i = 0 To strLyrID.Length - 1 Dim strTemp As String = strLyrName(i).ToString().ToLower() + "_" + strLyrID(i) If (Session.Item(strTemp) Is Nothing) Then Session.Add(strTemp, func.GetLayerVisibility(strLyrID(i))) End If Next End If End Sub 'IMapServerCommandAction.ServerAction implementation Public Sub ServerAction(ByVal info As ESRI.ArcGIS.ADF.Web.UI.WebControls.Tools.ToolbarItemInfo) Implements ESRI.ArcGIS.ADF.Web.UI.WebControls.Tools.IServerAction.ServerAction Dim map1 As ESRI.ArcGIS.ADF.Web.UI.WebControls.Map = CType(info.BuddyControls(0), ESRI.ArcGIS.ADF.Web.UI.WebControls.Map) Dim func As ESRI.ArcGIS.ADF.Web.DataSources.IMapFunctionality = CType(map1.GetFunctionality("MapResourceItem0"), ESRI.ArcGIS.ADF.Web.DataSources.IMapFunctionality) Dim toc As ESRI.ArcGIS.ADF.Web.UI.WebControls.Toc = CType(map1.Page.FindControl("Toc1"), ESRI.ArcGIS.ADF.Web.UI.WebControls.Toc) Dim toolbar As ESRI.ArcGIS.ADF.Web.UI.WebControls.Toolbar = CType(info.Toolbar, ESRI.ArcGIS.ADF.Web.UI.WebControls.Toolbar) Dim page As System.Web.UI.Page = map1.Page Dim strLyrID As String() = Nothing Dim strLyrName As String() = Nothing func.GetLayers(strLyrID, strLyrName) Dim i As Integer = 0 For i = 0 To strLyrID.Length - 1 '"U.S. Cities" If (strLyrName(i).ToString().ToLower() = "u.s. cities") Then 'First check if the setting is present in the session Dim strTemp As String = strLyrName(i).ToString().ToLower() + "_" + strLyrID(i) If (page.Session.Item(strTemp) Is Nothing) Then page.Session.Add(strTemp, True) End If System.Diagnostics.Debug.WriteLine("Layer ID : " & strLyrID(i) & ", Visibility : " & func.GetLayerVisibility(strLyrID(i))) If (page.Session.Item(strTemp)) Then func.SetLayerVisibility(strLyrID(i), False) 'toc.Nodes.FindByValue("MapResourceItem0").Nodes(i).Checked = False page.Session.Item(strTemp) = False Else func.SetLayerVisibility(strLyrID(i), True) 'toc.Nodes.FindByValue("MapResourceItem0").Nodes(i).Checked = True page.Session.Item(strTemp) = True End If End If Next If map1.ImageBlendingMode = ESRI.ArcGIS.ADF.Web.UI.WebControls.ImageBlendingMode.Browser Then map1.RefreshResource("MapResourceItem0") Else map1.Refresh() End If 'toc.Refresh() 'toolbar.CallbackResults.CopyFrom(map1.CallbackResults) 'toolbar.CallbackResults.CopyFrom(toc.CallbackResults) End Sub

Steps to Reproduce

Bug ID: NIM034021

Software:

  • No Product Found

Get notified when the status of a bug changes

Download the Esri Support App

Discover more on this topic

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options