ArcGIS_ClipShip_Geoprocessing_VBNet\App_Code\PolylineTool.vb
' Copyright 2010 ESRI ' ' All rights reserved under the copyright laws of the United States ' and applicable international laws, treaties, and conventions. ' ' You may freely redistribute and use this sample code, with or ' without modification, provided you include the original copyright ' notice and use restrictions. ' ' See the use restrictions. ' Imports Microsoft.VisualBasic Imports System Public Class PolylineTool Implements ESRI.ArcGIS.ADF.Web.UI.WebControls.Tools.IMapServerToolAction #Region "IMapServerToolAction Members" Private Sub ServerAction(ByVal toolEventArgs As ESRI.ArcGIS.ADF.Web.UI.WebControls.ToolEventArgs) Implements ESRI.ArcGIS.ADF.Web.UI.WebControls.Tools.IMapServerToolAction.ServerAction ' Get the map control on which the tool was executed Dim adfMap As ESRI.ArcGIS.ADF.Web.UI.WebControls.Map = CType(toolEventArgs.Control, ESRI.ArcGIS.ADF.Web.UI.WebControls.Map) Try ' Get the polyline drawn by the user Dim mapPolylineEventArgs As ESRI.ArcGIS.ADF.Web.UI.WebControls.MapPolylineEventArgs = TryCast(toolEventArgs, ESRI.ArcGIS.ADF.Web.UI.WebControls.MapPolylineEventArgs) Dim adfPolyline As ESRI.ArcGIS.ADF.Web.Geometry.Polyline = mapPolylineEventArgs.MapPolyline ' Get the name of the graphics resource from session that will contain the ' user-drawn polyline Dim graphicsResourceName As String = CStr(adfMap.Page.Session("graphicsResourceName")) ' Get the graphics map functionality for the resource Dim graphicsMapFunctionality As ESRI.ArcGIS.ADF.Web.DataSources.Graphics.MapFunctionality = TryCast(adfMap.GetFunctionality(graphicsResourceName), ESRI.ArcGIS.ADF.Web.DataSources.Graphics.MapFunctionality) ' Get the name of the graphics layer to which we will add the user-drawn polyline from ' from session, then use this name to retrieve the graphics layer from the graphics ' map functionality. Dim polylineGraphicsLayerName As String = CStr(adfMap.Page.Session("polylineGraphicsLayerName")) Dim elementGraphicsLayer As ESRI.ArcGIS.ADF.Web.Display.Graphics.ElementGraphicsLayer = TryCast(graphicsMapFunctionality.GraphicsDataSet.Tables(polylineGraphicsLayerName), ESRI.ArcGIS.ADF.Web.Display.Graphics.ElementGraphicsLayer) ' If the graphics layer was not found, create it If elementGraphicsLayer Is Nothing Then elementGraphicsLayer = New ESRI.ArcGIS.ADF.Web.Display.Graphics.ElementGraphicsLayer() elementGraphicsLayer.TableName = polylineGraphicsLayerName graphicsMapFunctionality.GraphicsDataSet.Tables.Add(elementGraphicsLayer) End If ' Uncomment to allow only one polyline to be drawn on the map at a time 'elementGraphicsLayer.Clear(); ' Create the symbology for the polyline Dim adfSimpleLineSymbol As ESRI.ArcGIS.ADF.Web.Display.Symbol.SimpleLineSymbol = New ESRI.ArcGIS.ADF.Web.Display.Symbol.SimpleLineSymbol() adfSimpleLineSymbol.Type = ESRI.ArcGIS.ADF.Web.Display.Symbol.LineType.Solid adfSimpleLineSymbol.Color = System.Drawing.Color.DarkGreen adfSimpleLineSymbol.Width = 1 ' Create a graphic element based on the polyline and the symbology Dim graphicElement As ESRI.ArcGIS.ADF.Web.Display.Graphics.GraphicElement = New ESRI.ArcGIS.ADF.Web.Display.Graphics.GraphicElement(adfPolyline, adfSimpleLineSymbol) ' Add the element to the graphics layer elementGraphicsLayer.Add(graphicElement) ' Refresh the graphics resource so the newly added graphic is displayed adfMap.RefreshResource(graphicsResourceName) Catch exception As System.Exception Dim errorCallbackResult As ESRI.ArcGIS.ADF.Web.UI.WebControls.CallbackResult = Utility.CreateErrorCallbackResult(exception) adfMap.CallbackResults.Add(errorCallbackResult) End Try End Sub #End Region End Class