画线、圆、矩形、面、文字

    int flag = 0;
    private void axMapControl1_OnMouseDown(object sender,ESRI.ArcGIS.Controls.IMapControlEvents2_OnMouseDownEvent e)
    {
        axMapControl1.MousePointer = esriControlsMousePointer.esriPointerCrosshair;
        IGeometry geometry = null;
        if (flag == 1)
        {
            geometry = axMapControl1.TrackLine();
        }
        else if (flag == 2)
        {
            geometry = axMapControl1.TrackCircle();
        }
        else if (flag == 3)
        {
            geometry = axMapControl1.TrackRectangle();
        }
        else if (flag == 4)
        {
            geometry = axMapControl1.TrackPolygon();
        }
        else if (flag == 5)
        {
            IPoint point = new PointClass();
            point.X = e.x;
            point.Y = e.y;
            geometry = point as IGeometry;
        }
        if (flag >= 1 && flag <= 4)
        {
            drawMapShape(geometry);
        }
        else if (flag == 5)
        {
            drawMapText(geometry);
        }
        axMapControl1.Refresh(esriViewDrawPhase.esriViewGeography, null, null);
    }

    private void btnLine_Click(object sender, EventArgs e)
    {
        flag = 1;
    }

    private void btnCircle_Click(object sender, EventArgs e)
    {
        flag = 2;
    }

    private void btnRectangle_Click(object sender, EventArgs e)
    {
        flag = 3;
    }

    private void btnFace_Click(object sender, EventArgs e)
    {
        flag = 4;
    }

    private void btnText_Click(object sender, EventArgs e)
    {
        flag = 5;
    }

    private void drawMapShape(IGeometry pGeom)
    {
        IRgbColor pColor;
        pColor = new RgbColorClass();
        pColor.Red = 255;
        pColor.Green = 255;
        pColor.Blue = 0;
        object symbol = null;
        if (pGeom.GeometryType == esriGeometryType.esriGeometryPolyline)
        {
            ISimpleLineSymbol simpleLineSymbol;
            simpleLineSymbol = new SimpleLineSymbolClass();
            simpleLineSymbol.Color = pColor;
            simpleLineSymbol.Width = 5;
            symbol = simpleLineSymbol;
        }
        else
        {
            ISimpleFillSymbol simpleFillSymbol;
            simpleFillSymbol = new SimpleFillSymbolClass();
            simpleFillSymbol.Color = pColor;
            symbol = simpleFillSymbol;
        }
        axMapControl1.DrawShape(pGeom, ref symbol);            
    }

    private void drawMapText(IGeometry geometry)
    {
        IRgbColor color = new RgbColorClass();
        color.Red = 255;
        color.Blue = 0;
        color.Green = 0;
        ITextSymbol txtSystem = new TextSymbolClass();
        txtSystem.Color = color;
        object symbol = txtSystem;
        axMapControl1.DrawText(geometry, “Test DrawText”, ref symbol);
    }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值