Cannot programmatically change the visibility of a ArcWebServices layer using IMapFunctionality.
上次发布: August 25, 2014No Product Found
漏洞 ID 编号
NIM034021
已提交
April 8, 2008
上次修改时间
June 5, 2024
适用范围
No Product Found
找到的版本
9.2
编程语言
VB.Net
状态
Known Limit
经开发团队审核,已确定此问题与不受 Esri 控制的软件的已知限制有关。 问题的“其他信息”部分可能包含进一步说明。
附加信息
No Public Explanation
解决办法
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