About the Server spatial query server object extension Sample
[C#]
VegTool.cs
/// <summary> /// Defines logic that executes when the user clicks the map with the Vegetation Summary Proximity Search Tool. /// Uses the Spatial Query custom server object extension to retrieve buffer geometry and summary statistics for a /// user-specified distance around the click point. /// </summary> public class VegTool : ESRI.ArcGIS.ADF.Web.UI.WebControls.Tools.IMapServerToolAction { #region IMapServerToolAction Members public void ServerAction(ESRI.ArcGIS.ADF.Web.UI.WebControls.ToolEventArgs toolEventArgs) { // Get the map control that was clicked ESRI.ArcGIS.ADF.Web.UI.WebControls.Map adfMap = toolEventArgs.Control as ESRI.ArcGIS.ADF.Web.UI.WebControls.Map; // Get the page containing the map control System.Web.UI.Page page = adfMap.Page; // Get the request parameters System.Collections.Specialized.NameValueCollection requestParameters = null; if (System.Web.UI.ScriptManager.GetCurrent(page) == null) requestParameters = ESRI.ArcGIS.ADF.Web.UI.WebControls.CallbackUtility.ParseStringIntoNameValueCollection( page.Request.Params["__CALLBACKPARAM"]); else requestParameters = page.Request.Params; // Get the search distance double searchDistance; if (!System.Double.TryParse(requestParameters["SearchDistanceTextBox"], out searchDistance)) searchDistance = 10000; // Get the value of the Show Results checkbox bool showSummaryStats; if (!bool.TryParse(requestParameters["ShowResultsCheckBox"], out showSummaryStats)) showSummaryStats = false; // Get MapFunctionality and MapResource for the Vegetation Layers resource item ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapFunctionality agsMapFunctionality = adfMap.GetFunctionality("Vegetation Layers") as ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapFunctionality; ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapResourceLocal agsMapResourceLocal = (ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapResourceLocal) agsMapFunctionality.MapResource; // Get the server context ESRI.ArcGIS.Server.IServerContext serverContext = agsMapResourceLocal.ServerContextInfo.ServerContext; // Get the click point as an ArcObjects point ESRI.ArcGIS.ADF.Web.UI.WebControls.MapPointEventArgs mapPointEventArgs = toolEventArgs as ESRI.ArcGIS.ADF.Web.UI.WebControls.MapPointEventArgs; ESRI.ArcGIS.Geometry.IPoint clickPoint = (ESRI.ArcGIS.Geometry.IPoint)serverContext.CreateObject("esriGeometry.Point"); clickPoint.X = mapPointEventArgs.MapPoint.X; clickPoint.Y = mapPointEventArgs.MapPoint.Y; // Get the Spatial Query server object extension ESRI.ArcGIS.Carto.IMapServer mapServer = agsMapResourceLocal.MapServer; ESRI.ArcGIS.Server.IServerObjectExtensionManager serverObjectExtensionManager = mapServer as ESRI.ArcGIS.Server.IServerObjectExtensionManager; ESRI.ArcGIS.Server.IServerObjectExtension serverObjectExtension = serverObjectExtensionManager.FindExtensionByTypeName("SpatialQuerySOE"); SpatialQuerySOE.Interfaces.IExtension spatialQuerySOE = serverObjectExtension as SpatialQuerySOE.Interfaces.IExtension; // Execute the SOE's logic SpatialQuerySOE.Interfaces.IResults spatialQueryResults = spatialQuerySOE.QueryPoint(clickPoint, searchDistance); // Get the results graphics ESRI.ArcGIS.ADF.ArcGISServer.GraphicElement[] resultsGraphics = ESRI.ArcGIS.ADF.ArcGISServer.Converter.ComObjectToValueObject( spatialQueryResults.ResultsGraphics, serverContext, typeof(ESRI.ArcGIS.ADF.ArcGISServer.GraphicElement[])) as ESRI.ArcGIS.ADF.ArcGISServer.GraphicElement[]; // Create a symbol for the graphics' outlines ESRI.ArcGIS.ADF.ArcGISServer.RgbColor rgbColor = new ESRI.ArcGIS.ADF.ArcGISServer.RgbColor(); rgbColor.Red = 155; rgbColor.Green = 0; rgbColor.Blue = 0; rgbColor.AlphaValue = 255; ESRI.ArcGIS.ADF.ArcGISServer.SimpleLineSymbol simpleLineSymbol = new ESRI.ArcGIS.ADF.ArcGISServer.SimpleLineSymbol(); simpleLineSymbol.Style = ESRI.ArcGIS.ADF.ArcGISServer.esriSimpleLineStyle.esriSLSSolid; simpleLineSymbol.Color = rgbColor; simpleLineSymbol.Width = 0.2; // Apply the symbol to the graphics foreach (ESRI.ArcGIS.ADF.ArcGISServer.PolygonElement polygonElement in resultsGraphics) { ESRI.ArcGIS.ADF.ArcGISServer.SimpleFillSymbol simpleFillSymbol = polygonElement.Symbol as ESRI.ArcGIS.ADF.ArcGISServer.SimpleFillSymbol; simpleFillSymbol.Outline = simpleLineSymbol; } // Add the graphics to the map agsMapFunctionality.MapDescription.CustomGraphics = resultsGraphics; // Get the grid view for displaying summary stats System.Web.UI.WebControls.GridView summaryStatsGridView = adfMap.Page.FindControl("GridView1") as System.Web.UI.WebControls.GridView; // Update the summary stats grid view if the stats are to be shown if (showSummaryStats) { // Get the summary statistics as a value object record set ESRI.ArcGIS.ADF.ArcGISServer.RecordSet summaryStatsRecordSet = ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.Converter.ComObjectToValueObject( spatialQueryResults.SummaryStatistics, serverContext, typeof(ESRI.ArcGIS.ADF.ArcGISServer.RecordSet)) as ESRI.ArcGIS.ADF.ArcGISServer.RecordSet; // Convert the record set to a DataTable System.Data.DataTable summaryStatsDataTable = ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.Converter.ToDataTable(summaryStatsRecordSet); if (summaryStatsDataTable.Rows.Count > 0) { // Bind the summary stats to the grid view summaryStatsGridView.DataSource = summaryStatsDataTable; summaryStatsGridView.DataBind(); // Get the grid view's HTML System.IO.StringWriter stringWriter = new System.IO.StringWriter(); System.Web.UI.HtmlTextWriter htmlTextWriter = new System.Web.UI.HtmlTextWriter(stringWriter); summaryStatsGridView.RenderControl(htmlTextWriter); htmlTextWriter.Flush(); string gridViewHtml = stringWriter.ToString(); // Create a callback result that will update the summary stats grid view ESRI.ArcGIS.ADF.Web.UI.WebControls.CallbackResult updateStatsTableCallbackResult = ESRI.ArcGIS.ADF.Web.UI.WebControls.CallbackResult.CreateSetInnerContent("summaryStatsDiv", gridViewHtml); adfMap.CallbackResults.Add(updateStatsTableCallbackResult); } else { showSummaryStats = false; } } // Create a callback result that will update the visibility of the summary stats div and busy indicator via JavaScript string statsDivVisibility = showSummaryStats ? "" : "none"; string setElementVisibilityScript = @" var summaryStatsDiv = $get('summaryStatsDiv'); summaryStatsDiv.style.display = '{0}'; var busyIndicator = $get('busyIndicator'); busyIndicator.style.display = 'none';"; setElementVisibilityScript = string.Format(setElementVisibilityScript, statsDivVisibility); ESRI.ArcGIS.ADF.Web.UI.WebControls.CallbackResult setStatsDivVisibilityCallbackResult = ESRI.ArcGIS.ADF.Web.UI.WebControls.CallbackResult.CreateJavaScript(setElementVisibilityScript); adfMap.CallbackResults.Add(setStatsDivVisibilityCallbackResult); adfMap.RefreshResource(agsMapResourceLocal.Name); } #endregion }
[Visual Basic .NET]
VegTool.vb
Imports Microsoft.VisualBasic Imports System ''' <summary> ''' Defines logic that executes when the user clicks the map with the Vegetation Summary Proximity Search Tool. ''' Uses the Spatial Query custom server object extension to retrieve buffer geometry and summary statistics for a ''' user-specified distance around the click point. ''' </summary> Public Class VegTool Implements ESRI.ArcGIS.ADF.Web.UI.WebControls.Tools.IMapServerToolAction #Region "IMapServerToolAction Members" Public Sub ServerAction(ByVal args As ESRI.ArcGIS.ADF.Web.UI.WebControls.ToolEventArgs) Implements ESRI.ArcGIS.ADF.Web.UI.WebControls.Tools.IMapServerToolAction.ServerAction ' Get the map control that was clicked Dim adfMap As ESRI.ArcGIS.ADF.Web.UI.WebControls.Map = TryCast(args.Control, ESRI.ArcGIS.ADF.Web.UI.WebControls.Map) ' Get the page containing the map control Dim page As System.Web.UI.Page = adfMap.Page ' Get the request parameters Dim requestParameters As System.Collections.Specialized.NameValueCollection = Nothing If System.Web.UI.ScriptManager.GetCurrent(page) Is Nothing Then requestParameters = ESRI.ArcGIS.ADF.Web.UI.WebControls.CallbackUtility.ParseStringIntoNameValueCollection(page.Request.Params("__CALLBACKPARAM")) Else requestParameters = page.Request.Params End If ' Get the search distance Dim searchDistance As Double If (Not System.Double.TryParse(requestParameters("SearchDistanceTextBox"), searchDistance)) Then searchDistance = 10000 End If ' Get the value of the Show Results checkbox Dim showSummaryStats As Boolean If (Not Boolean.TryParse(requestParameters("ShowResultsCheckBox"), showSummaryStats)) Then showSummaryStats = False End If ' Get MapFunctionality and MapResource for the Vegetation Layers resource item Dim agsMapFunctionality As ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapFunctionality = TryCast(adfMap.GetFunctionality("Vegetation Layers"), ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapFunctionality) Dim agsMapResourceLocal As ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapResourceLocal = CType(agsMapFunctionality.MapResource, ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapResourceLocal) ' Get the server context Dim serverContext As ESRI.ArcGIS.Server.IServerContext = agsMapResourceLocal.ServerContextInfo.ServerContext ' Get the click point as an ArcObjects point Dim mapPointEventArgs As ESRI.ArcGIS.ADF.Web.UI.WebControls.MapPointEventArgs = TryCast(args, ESRI.ArcGIS.ADF.Web.UI.WebControls.MapPointEventArgs) Dim clickPoint As ESRI.ArcGIS.Geometry.IPoint = CType(serverContext.CreateObject("esriGeometry.Point"), ESRI.ArcGIS.Geometry.IPoint) clickPoint.X = mapPointEventArgs.MapPoint.X clickPoint.Y = mapPointEventArgs.MapPoint.Y ' Get the Spatial Query server object extension Dim mapServer As ESRI.ArcGIS.Carto.IMapServer = agsMapResourceLocal.MapServer Dim serverObjectExtensionManager As ESRI.ArcGIS.Server.IServerObjectExtensionManager = TryCast(mapServer, ESRI.ArcGIS.Server.IServerObjectExtensionManager) Dim serverObjectExtension As ESRI.ArcGIS.Server.IServerObjectExtension = serverObjectExtensionManager.FindExtensionByTypeName("SpatialQuerySOE_VBNet") Dim spatialQuerySOE As SpatialQuerySOE.Interfaces_VBNet.IExtension = TryCast(serverObjectExtension, SpatialQuerySOE.Interfaces_VBNet.IExtension) ' Execute the SOE's logic Dim spatialQueryResults As SpatialQuerySOE.Interfaces_VBNet.IResults = spatialQuerySOE.QueryPoint(clickPoint, searchDistance) ' Get the results graphics Dim resultsGraphics() As ESRI.ArcGIS.ADF.ArcGISServer.GraphicElement = TryCast(ESRI.ArcGIS.ADF.ArcGISServer.Converter.ComObjectToValueObject(spatialQueryResults.ResultsGraphics, serverContext, GetType(ESRI.ArcGIS.ADF.ArcGISServer.GraphicElement())), ESRI.ArcGIS.ADF.ArcGISServer.GraphicElement()) ' Create a symbol for the graphics' outlines Dim rgbColor As New ESRI.ArcGIS.ADF.ArcGISServer.RgbColor() rgbColor.Red = 155 rgbColor.Green = 0 rgbColor.Blue = 0 rgbColor.AlphaValue = 255 Dim simpleLineSymbol As New ESRI.ArcGIS.ADF.ArcGISServer.SimpleLineSymbol() simpleLineSymbol.Style = ESRI.ArcGIS.ADF.ArcGISServer.esriSimpleLineStyle.esriSLSSolid simpleLineSymbol.Color = rgbColor simpleLineSymbol.Width = 0.2 ' Apply the symbol to the graphics For Each polygonElement As ESRI.ArcGIS.ADF.ArcGISServer.PolygonElement In resultsGraphics Dim simpleFillSymbol As ESRI.ArcGIS.ADF.ArcGISServer.SimpleFillSymbol = TryCast(polygonElement.Symbol, ESRI.ArcGIS.ADF.ArcGISServer.SimpleFillSymbol) simpleFillSymbol.Outline = simpleLineSymbol Next polygonElement ' Add the graphics to the map agsMapFunctionality.MapDescription.CustomGraphics = resultsGraphics ' Get the grid view for displaying summary stats Dim summaryStatsGridView As System.Web.UI.WebControls.GridView = TryCast(adfMap.Page.FindControl("GridView1"), System.Web.UI.WebControls.GridView) ' Update the summary stats grid view if the stats are to be shown If showSummaryStats Then ' Get the summary statistics as a value object record set Dim summaryStatsRecordSet As ESRI.ArcGIS.ADF.ArcGISServer.RecordSet = TryCast(ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.Converter.ComObjectToValueObject(spatialQueryResults.SummaryStatistics, serverContext, GetType(ESRI.ArcGIS.ADF.ArcGISServer.RecordSet)), ESRI.ArcGIS.ADF.ArcGISServer.RecordSet) ' Convert the record set to a DataTable Dim summaryStatsDataTable As System.Data.DataTable = ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.Converter.ToDataTable(summaryStatsRecordSet) If summaryStatsDataTable.Rows.Count > 0 Then ' Bind the summary stats to the grid view summaryStatsGridView.DataSource = summaryStatsDataTable summaryStatsGridView.DataBind() ' Get the grid view's HTML Dim stringWriter As New System.IO.StringWriter() Dim htmlTextWriter As New System.Web.UI.HtmlTextWriter(stringWriter) summaryStatsGridView.RenderControl(htmlTextWriter) htmlTextWriter.Flush() Dim gridViewHtml As String = stringWriter.ToString() ' Create a callback result that will update the summary stats grid view Dim updateStatsTableCallbackResult As ESRI.ArcGIS.ADF.Web.UI.WebControls.CallbackResult = ESRI.ArcGIS.ADF.Web.UI.WebControls.CallbackResult.CreateSetInnerContent("summaryStatsDiv", gridViewHtml) adfMap.CallbackResults.Add(updateStatsTableCallbackResult) Else showSummaryStats = False End If End If ' Create a callback result that will update the visibility of the summary stats div and busy indicator via JavaScript Dim statsDivVisibility As String = If(showSummaryStats, "", "none") Dim setElementVisibilityScript As String = "" & ControlChars.CrLf & " var summaryStatsDiv = $get('summaryStatsDiv');" & ControlChars.CrLf & " summaryStatsDiv.style.display = '{0}';" & ControlChars.CrLf & ControlChars.CrLf & " var busyIndicator = $get('busyIndicator');" & ControlChars.CrLf & " busyIndicator.style.display = 'none';" setElementVisibilityScript = String.Format(setElementVisibilityScript, statsDivVisibility) Dim setStatsDivVisibilityCallbackResult As ESRI.ArcGIS.ADF.Web.UI.WebControls.CallbackResult = ESRI.ArcGIS.ADF.Web.UI.WebControls.CallbackResult.CreateJavaScript(setElementVisibilityScript) adfMap.CallbackResults.Add(setStatsDivVisibilityCallbackResult) adfMap.RefreshResource(agsMapResourceLocal.Name) End Sub #End Region End Class