ArcGIS Select and Delete USNG Graphics Tool

SelectDeleteGraphicsTool

/// Updated Aug 15,2009. ArcGIS 9.3.1 Web ADF

using ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer;

using ESRI.ArcGIS.ADF.Web.UI.WebControls;

using ESRI.ArcGIS.ADF.Web.UI.WebControls.Tools;

 

/// <summary>

/// Summary description for SelectDeleteGraphicsTool

/// This Select and Delete graphics tool provides the ability to delete all graphic elements added using the USNG Coordinate Tool from the Graphic Element Array by drawing a rectangle on the map.

/// </summary>

 

public class SelectDeleteGraphicsTool : IMapServerToolAction

{

public void ServerAction(ToolEventArgs args)

{

Map map = (Map)args.Control;

RectangleEventArgs rect = (RectangleEventArgs)args;

System.Drawing.Rectangle screenRectangle = rect.ScreenExtent;

ESRI.ArcGIS.ADF.Web.Geometry.Point minimumAdfPoint = ESRI.ArcGIS.ADF.Web.Geometry.Point.ToMapPoint(screenRectangle.Left, screenRectangle.Bottom, map.GetTransformationParams(ESRI.ArcGIS.ADF.Web.Geometry.TransformationDirection.ToMap));

ESRI.ArcGIS.ADF.Web.Geometry.Point maximumAdfPoint = ESRI.ArcGIS.ADF.Web.Geometry.Point.ToMapPoint(screenRectangle.Right, screenRectangle.Top, map.GetTransformationParams(ESRI.ArcGIS.ADF.Web.Geometry.TransformationDirection.ToMap));

 

MapFunctionality mf = (MapFunctionality)map.GetFunctionality(0);

ESRI.ArcGIS.ADF.ArcGISServer.MapDescription mapDescription = mf.MapDescription;

if (mapDescription.CustomGraphics != null)

{

ESRI.ArcGIS.ADF.ArcGISServer.GraphicElement[] oldges = mapDescription.CustomGraphics;

int cnt = oldges.Length;

ESRI.ArcGIS.ADF.ArcGISServer.GraphicElement[] newges = new ESRI.ArcGIS.ADF.ArcGISServer.GraphicElement[cnt];

oldges.CopyTo(newges, 0);

do

{

ESRI.ArcGIS.ADF.ArcGISServer.TextElement ges = (ESRI.ArcGIS.ADF.ArcGISServer.TextElement)oldges[cnt - 2];

if (ges != null)

{

ESRI.ArcGIS.ADF.ArcGISServer.PointN pText = (ESRI.ArcGIS.ADF.ArcGISServer.PointN)ges.TextGeometry;

if ((pText.X >= minimumAdfPoint.X) && (pText.X <= maximumAdfPoint.X) && (pText.Y >= minimumAdfPoint.Y) && (pText.Y <= maximumAdfPoint.Y))

{

newges[cnt - 1] = null;

newges[cnt - 2] = null;

mapDescription.CustomGraphics = newges;

} // if loop

} // if loop

cnt = cnt – 2;

} while (cnt != 0); //do while loop ends

} // if loop ends

map.Refresh();

}

}