(转载)移动图层位置,刷新toc,不刷新整个页面
<esri:Toolbar ID="Toolbar3" runat="server" BuddyC Group="Toolbar3_Group" Height="50px" ToolbarItemDefaultStyle-BackColor="White" ToolbarItemDefaultStyle-Font-Names="Arial" ToolbarItemDefaultStyle-Font-Size="Smaller" ToolbarItemDisabledStyle-BackColor="White" ToolbarItemDisabledStyle-Font-Names="Arial" ToolbarItemDisabledStyle-Font-Size="Smaller" ToolbarItemDisabledStyle-ForeColor="Gray" ToolbarItemHoverStyle-BackColor="White" ToolbarItemHoverStyle-Font-Bold="True" ToolbarItemHoverStyle-Font-Italic="True" ToolbarItemHoverStyle-Font-Names="Arial" ToolbarItemHoverStyle-Font-Size="Smaller" ToolbarItemSelectedStyle-BackColor="White" ToolbarItemSelectedStyle-Font-Bold="True" ToolbarItemSelectedStyle-Font-Names="Arial" ToolbarItemSelectedStyle-Font-Size="Smaller" WebResourceLocation="/aspnet_client/ESRI/WebADF/" Width="126px">
<toolbaritems>
<esri:Command JavaScriptFile="" DisabledImage="~/images/up.jpg" ServerActi HoverImage="~/images/up.jpg" ClientAction="" SelectedImage="~/images/up.jpg" ServerActi Name="MoveUp" DefaultImage="~/images/up.jpg" Text="Move Up"></esri:Command>
<esri:Command JavaScriptFile="" DisabledImage="~/images/down.jpg" ServerActi HoverImage="~/images/down.jpg" ClientAction="" SelectedImage="~/images/down.jpg" ServerActi Name="MoveDown" DefaultImage="~/images/down.jpg" Text="Move Down"></esri:Command>
</toolbaritems>
<BuddyControls>
<esri:BuddyControl Name="Map1"></esri:BuddyControl>
</BuddyControls>
</esri:Toolbar>
<toolbaritems>
<esri:Command JavaScriptFile="" DisabledImage="~/images/up.jpg" ServerActi HoverImage="~/images/up.jpg" ClientAction="" SelectedImage="~/images/up.jpg" ServerActi Name="MoveUp" DefaultImage="~/images/up.jpg" Text="Move Up"></esri:Command>
<esri:Command JavaScriptFile="" DisabledImage="~/images/down.jpg" ServerActi HoverImage="~/images/down.jpg" ClientAction="" SelectedImage="~/images/down.jpg" ServerActi Name="MoveDown" DefaultImage="~/images/down.jpg" Text="Move Down"></esri:Command>
</toolbaritems>
<BuddyControls>
<esri:BuddyControl Name="Map1"></esri:BuddyControl>
</BuddyControls>
</esri:Toolbar>
(PS: the namespace is myControls and import it into default.aspx.vb)
****
Public Class SContext
Dim mapresource As MapResourceLocal = Nothing
Public Function GetServerContext(ByVal mapObject As ESRI.ArcGIS.ADF.Web.UI.WebControls.Map) As ESRI.ArcGIS.Server.IServerContext
Dim mf As IMapFunctionality = mapObject.GetFunctionality(0)
mapresource = mf.Resource
Dim servercontext As ESRI.ArcGIS.Server.IServerContext = mapresource.ServerContextInfo.ServerContext
Return servercontext
End Function
Public Sub RefreshResourceLocal()
mapresource.RefreshServerObjects()
End Sub
End Class
Public Class MoveUp
Implements ESRI.ArcGIS.ADF.Web.UI.WebControls.Tools.IMapServerCommandAction
Sub ServerAction(ByVal info As ToolbarItemInfo) Implements IMapServerCommandAction.ServerAction
'Get map object from toolbar
Dim map As ESRI.ArcGIS.ADF.Web.UI.WebControls.Map = CType(info.BuddyControls(0), ESRI.ArcGIS.ADF.Web.UI.WebControls.Map)
map.RaisePostDataChangedEvent()
'Set up server context and serverobjects
Dim servercontext As ESRI.ArcGIS.Server.IServerContext
Dim context As myControls.SContext = New myControls.SContext
servercontext = context.GetServerContext(map)
Dim mapper As IMapServer = servercontext.ServerObject
Dim mso As IMapServerObjects = servercontext.ServerObject
Dim map2 As IMap = mso.Map(mapper.DefaultMapName)
'Grab selected layer index stored in hidden field
Dim field As HiddenField = info.Toolbar.FindControl("Layer")
'Assign layer index, move to index variables
Dim layer As Integer = CType(field.Value, Integer)
Dim moved As Integer = layer - 1
Dim Toc1 As Toc = info.Toolbar.FindControl("Toc3")
'Move layer and refresh the map
map2.MoveLayer(map2.Layer(layer), moved)
context.RefreshResourceLocal()
mso.RefreshServerObjects()
Toc1.Refresh()
Dim sw As System.IO.StringWriter = New System.IO.StringWriter
Dim writer As HtmlTextWriter = New HtmlTextWriter(sw)
Toc1.RenderControl(writer)
Dim htmlContent As String = sw.ToString
sw.Close()
Dim cr As New CallbackResult(Toc1, "content", htmlContent)
info.Toolbar.CallbackResults.Add(cr)
info.Toolbar.CallbackResults.CopyFrom(Toc1.CallbackResults)
map.Refresh()
End Sub
End Class
Public Class MoveDown
Implements ESRI.ArcGIS.ADF.Web.UI.WebControls.Tools.IMapServerCommandAction
Sub ServerAction(ByVal info As ToolbarItemInfo) Implements IMapServerCommandAction.ServerAction
'Get map object from toolbar
Dim map As ESRI.ArcGIS.ADF.Web.UI.WebControls.Map = CType(info.BuddyControls(0), ESRI.ArcGIS.ADF.Web.UI.WebControls.Map)
map.RaisePostDataChangedEvent()
'Set up server context and serverobjects
Dim servercontext As ESRI.ArcGIS.Server.IServerContext
Dim context As myControls.SContext = New myControls.SContext
servercontext = context.GetServerContext(map)
Dim mapper As IMapServer = servercontext.ServerObject
Dim mso As IMapServerObjects = servercontext.ServerObject
Dim map2 As IMap = mso.Map(mapper.DefaultMapName)
'Grab selected layer index stored in hidden field
Dim field As HiddenField = info.Toolbar.FindControl("Layer")
'Assign layer index, move to index variables
Dim layer As Integer = CType(field.Value, Integer)
Dim moved As Integer = layer + 1
Dim Toc1 As Toc = info.Toolbar.FindControl("Toc3")
'Move layer and refresh the map
map2.MoveLayer(map2.Layer(layer), moved)
'Refresh whatever
context.RefreshResourceLocal()
mso.RefreshServerObjects()
Toc1.Refresh()
'render control to htmlContent
Dim sw As System.IO.StringWriter = New System.IO.StringWriter
Dim writer As HtmlTextWriter = New HtmlTextWriter(sw)
Toc1.RenderControl(writer)
Dim htmlContent As String = sw.ToString
sw.Close()
'Add changes to toc callback
Dim cr As New CallbackResult(Toc1, "content", htmlContent)
info.Toolbar.CallbackResults.Add(cr)
info.Toolbar.CallbackResults.CopyFrom(Toc1.CallbackResults)
'refresh the map
map.Refresh()
End Sub
End Class
****
Public Class SContext
Dim mapresource As MapResourceLocal = Nothing
Public Function GetServerContext(ByVal mapObject As ESRI.ArcGIS.ADF.Web.UI.WebControls.Map) As ESRI.ArcGIS.Server.IServerContext
Dim mf As IMapFunctionality = mapObject.GetFunctionality(0)
mapresource = mf.Resource
Dim servercontext As ESRI.ArcGIS.Server.IServerContext = mapresource.ServerContextInfo.ServerContext
Return servercontext
End Function
Public Sub RefreshResourceLocal()
mapresource.RefreshServerObjects()
End Sub
End Class
Public Class MoveUp
Implements ESRI.ArcGIS.ADF.Web.UI.WebControls.Tools.IMapServerCommandAction
Sub ServerAction(ByVal info As ToolbarItemInfo) Implements IMapServerCommandAction.ServerAction
'Get map object from toolbar
Dim map As ESRI.ArcGIS.ADF.Web.UI.WebControls.Map = CType(info.BuddyControls(0), ESRI.ArcGIS.ADF.Web.UI.WebControls.Map)
map.RaisePostDataChangedEvent()
'Set up server context and serverobjects
Dim servercontext As ESRI.ArcGIS.Server.IServerContext
Dim context As myControls.SContext = New myControls.SContext
servercontext = context.GetServerContext(map)
Dim mapper As IMapServer = servercontext.ServerObject
Dim mso As IMapServerObjects = servercontext.ServerObject
Dim map2 As IMap = mso.Map(mapper.DefaultMapName)
'Grab selected layer index stored in hidden field
Dim field As HiddenField = info.Toolbar.FindControl("Layer")
'Assign layer index, move to index variables
Dim layer As Integer = CType(field.Value, Integer)
Dim moved As Integer = layer - 1
Dim Toc1 As Toc = info.Toolbar.FindControl("Toc3")
'Move layer and refresh the map
map2.MoveLayer(map2.Layer(layer), moved)
context.RefreshResourceLocal()
mso.RefreshServerObjects()
Toc1.Refresh()
Dim sw As System.IO.StringWriter = New System.IO.StringWriter
Dim writer As HtmlTextWriter = New HtmlTextWriter(sw)
Toc1.RenderControl(writer)
Dim htmlContent As String = sw.ToString
sw.Close()
Dim cr As New CallbackResult(Toc1, "content", htmlContent)
info.Toolbar.CallbackResults.Add(cr)
info.Toolbar.CallbackResults.CopyFrom(Toc1.CallbackResults)
map.Refresh()
End Sub
End Class
Public Class MoveDown
Implements ESRI.ArcGIS.ADF.Web.UI.WebControls.Tools.IMapServerCommandAction
Sub ServerAction(ByVal info As ToolbarItemInfo) Implements IMapServerCommandAction.ServerAction
'Get map object from toolbar
Dim map As ESRI.ArcGIS.ADF.Web.UI.WebControls.Map = CType(info.BuddyControls(0), ESRI.ArcGIS.ADF.Web.UI.WebControls.Map)
map.RaisePostDataChangedEvent()
'Set up server context and serverobjects
Dim servercontext As ESRI.ArcGIS.Server.IServerContext
Dim context As myControls.SContext = New myControls.SContext
servercontext = context.GetServerContext(map)
Dim mapper As IMapServer = servercontext.ServerObject
Dim mso As IMapServerObjects = servercontext.ServerObject
Dim map2 As IMap = mso.Map(mapper.DefaultMapName)
'Grab selected layer index stored in hidden field
Dim field As HiddenField = info.Toolbar.FindControl("Layer")
'Assign layer index, move to index variables
Dim layer As Integer = CType(field.Value, Integer)
Dim moved As Integer = layer + 1
Dim Toc1 As Toc = info.Toolbar.FindControl("Toc3")
'Move layer and refresh the map
map2.MoveLayer(map2.Layer(layer), moved)
'Refresh whatever
context.RefreshResourceLocal()
mso.RefreshServerObjects()
Toc1.Refresh()
'render control to htmlContent
Dim sw As System.IO.StringWriter = New System.IO.StringWriter
Dim writer As HtmlTextWriter = New HtmlTextWriter(sw)
Toc1.RenderControl(writer)
Dim htmlContent As String = sw.ToString
sw.Close()
'Add changes to toc callback
Dim cr As New CallbackResult(Toc1, "content", htmlContent)
info.Toolbar.CallbackResults.Add(cr)
info.Toolbar.CallbackResults.CopyFrom(Toc1.CallbackResults)
'refresh the map
map.Refresh()
End Sub
End Class
来自:http://bbs.esrichina-bj.cn/ESRI/viewthread.php?tid=19143&extra=page%3D1
加油,哥们,现在开始!