⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 polygontool.cs

📁 arcgis server9.2 (graphicElement)图形元素操作
💻 CS
字号:
// Copyright 2006 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 use restrictions at /arcgis/developerkit/userestrictions.

using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
using ESRI.ArcGIS.ADF.Web.UI.WebControls;
using ESRI.ArcGIS.ADF.Web.UI.WebControls.Tools;
using ESRI.ArcGIS.ADF.ArcGISServer;
using ESRI.ArcGIS.ADF.Web.DataSources;
using ESRI.ArcGIS.Server;
using System.Collections;


public class PolygonTool: IMapServerToolAction
{

    #region IMapServerToolAction Members

    public void ServerAction(ToolEventArgs args)
    {
        ESRI.ArcGIS.ADF.Web.UI.WebControls.Map mapctrl;
        mapctrl = (ESRI.ArcGIS.ADF.Web.UI.WebControls.Map)args.Control;

        PolygonEventArgs peag = (PolygonEventArgs)args;
        System.Drawing.Point[] screen_points = peag.Vectors;

        ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapFunctionality ags_mf = (ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapFunctionality)mapctrl.GetFunctionality(0);
        //ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapResourceLocal ags_mr = (ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapResourceLocal)ags_mf.Resource;
        //ESRI.ArcGIS.Server.IServerContext sc = ags_mr.ServerContextInfo.ServerContext;
        ESRI.ArcGIS.ADF.ArcGISServer.MapDescription mapDescription;
        mapDescription = ags_mf.MapDescription;

        RgbColor rgb = new RgbColor();
        rgb.Red = 0;
        rgb.Green = 255;
        rgb.Blue = 0;
        rgb.AlphaValue = 255;

        PointN[] pnts1 = new PointN[screen_points.Length];

        for (int i = 0; i < screen_points.Length; i++)
        {
            PointN pnt = new PointN();
            ESRI.ArcGIS.ADF.Web.Geometry.Point mappnt = ESRI.ArcGIS.ADF.Web.Geometry.Point.ToMapPoint(screen_points[i], mapctrl.Extent, (int)mapctrl.Width.Value, (int)mapctrl.Height.Value);
            pnt.X = mappnt.X;
            pnt.Y = mappnt.Y;
            pnts1[i] = pnt;
        }

        Ring[] rings1 = new Ring[1];
        Ring ring1 = new Ring();
        ring1.PointArray = pnts1;
        PolygonN polygon = new PolygonN();
        rings1[0] = ring1;
        polygon.RingArray = rings1;
        polygon.Extent = new EnvelopeN();
        polygon.HasID = false;
        polygon.HasM = false;
        polygon.HasZ = false;
        polygon.SpatialReference = mapDescription.SpatialReference;

        SimpleFillSymbol sfs = new SimpleFillSymbol();
        sfs.Style = ESRI.ArcGIS.ADF.ArcGISServer.esriSimpleFillStyle.esriSFSSolid;
        sfs.Color = rgb;

        PolygonElement pe = new PolygonElement();
        pe.Symbol = sfs;
        pe.Polygon = polygon;

        if (mapDescription.CustomGraphics != null)
        {
            GraphicElement[] oldges = mapDescription.CustomGraphics;
            int cnt = oldges.Length;
            GraphicElement[] newges = new GraphicElement[cnt + 1];
            oldges.CopyTo(newges, 0);
            newges[cnt] = pe;
            mapDescription.CustomGraphics = newges;
        }
        else
        {
            GraphicElement[] ges = new GraphicElement[1];
            ges[0] = pe;
            mapDescription.CustomGraphics = ges;
        }

        mapctrl.Refresh();

    }

    #endregion
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -