ADF Tutorials
ADFTutorials_CSharp\AccessArcGISServer\App_Code\PointBufferTool.cs
// 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.
// 

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using ESRI.ArcGIS.ADF.Web.UI.WebControls.Tools;
using ESRI.ArcGIS.ADF.Web.UI.WebControls;
using ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer;
using ESRI.ArcGIS.Server;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.Display;

/// <summary>
/// Summary description for PointBufferTool
/// </summary>
public class PointBufferTool : IMapServerToolAction
{
    public void ServerAction(ToolEventArgs args)
    {
        ESRI.ArcGIS.ADF.Web.UI.WebControls.Map mapctrl;
        mapctrl = (ESRI.ArcGIS.ADF.Web.UI.WebControls.Map)args.Control;

        MapPointEventArgs mpea = (MapPointEventArgs)args;
        
        ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapFunctionality mf;
        mf = (ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapFunctionality)mapctrl.GetFunctionality("MapResourceItem0");

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

        ESRI.ArcGIS.ADF.ArcGISServer.PointN ags_map_point;
        ags_map_point = ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.Converter.FromAdfPoint(mpea.MapPoint);

        ESRI.ArcGIS.ADF.ArcGISServer.RgbColor rgb;
        rgb = new ESRI.ArcGIS.ADF.ArcGISServer.RgbColor();
        rgb.Red = 0;
        rgb.Green = 255;
        rgb.Blue = 0;
        rgb.AlphaValue = 255;

        ESRI.ArcGIS.ADF.ArcGISServer.SimpleMarkerSymbol sms;
        sms = new ESRI.ArcGIS.ADF.ArcGISServer.SimpleMarkerSymbol();
        sms.Style = ESRI.ArcGIS.ADF.ArcGISServer.esriSimpleMarkerStyle.esriSMSDiamond;
        sms.Color = rgb;
        sms.Size = 20.0;

        ESRI.ArcGIS.ADF.ArcGISServer.MarkerElement marker;
        marker = new ESRI.ArcGIS.ADF.ArcGISServer.MarkerElement();
        marker.Symbol = sms;
        marker.Point = ags_map_point;

        ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapResourceLocal mrl;
        mrl = (ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapResourceLocal)mf.MapResource;
        ESRI.ArcGIS.Server.IServerContext serverContext = mrl.ServerContextInfo.ServerContext;

        ESRI.ArcGIS.Geometry.IPoint ipnt;
        ipnt = (ESRI.ArcGIS.Geometry.IPoint)ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.Converter.ValueObjectToComObject(ags_map_point,serverContext);
        ESRI.ArcGIS.Geometry.ITopologicalOperator topop = (ESRI.ArcGIS.Geometry.ITopologicalOperator)ipnt;
        double bufferdistance = mapctrl.Extent.Width / 6;
        ESRI.ArcGIS.Geometry.IPolygon bufferpolygon = (ESRI.ArcGIS.Geometry.IPolygon)topop.Buffer(bufferdistance);

        ESRI.ArcGIS.ADF.ArcGISServer.PolygonN buffer_polyn;
        buffer_polyn = (ESRI.ArcGIS.ADF.ArcGISServer.PolygonN)ESRI.ArcGIS.ADF.ArcGISServer.Converter.ComObjectToValueObject
           (bufferpolygon, serverContext, typeof(ESRI.ArcGIS.ADF.ArcGISServer.PolygonN));

        ESRI.ArcGIS.ADF.ArcGISServer.RgbColor rgb1;
        rgb1 = new ESRI.ArcGIS.ADF.ArcGISServer.RgbColor();
        rgb1.Red = 255;
        rgb1.Green = 0;
        rgb1.Blue = 0;
        rgb1.AlphaValue = 0;

        ESRI.ArcGIS.ADF.ArcGISServer.SimpleFillSymbol sfs1;
        sfs1 = new ESRI.ArcGIS.ADF.ArcGISServer.SimpleFillSymbol();
        sfs1.Style = ESRI.ArcGIS.ADF.ArcGISServer.esriSimpleFillStyle.esriSFSForwardDiagonal;
        sfs1.Color = rgb1;

        ESRI.ArcGIS.ADF.ArcGISServer.PolygonElement polyelement1;
        polyelement1 = new ESRI.ArcGIS.ADF.ArcGISServer.PolygonElement();
        polyelement1.Symbol = sfs1;
        polyelement1.Polygon = buffer_polyn;

        ESRI.ArcGIS.ADF.ArcGISServer.GraphicElement[] ges;
        ges = new ESRI.ArcGIS.ADF.ArcGISServer.GraphicElement[2];
        ges[0] = marker;
        ges[1] = polyelement1;
        mapDescription.CustomGraphics = ges;

        mapctrl.RefreshResource(mf.Resource.Name);
    }
}