ARCGISEngine中交互式画点线面,文字符号,及右键弹出“取消编辑,全图显示”内容框

 

目录

画点:

画线:

画面:

画文字符号:

右键弹出“取消编辑”内容框

运行结果:

完整项目下载:https://download.csdn.net/download/qq_40323256/10865950


画点:

                    IPoint pt = axMapControl1.ToMapPoint(e.x, e.y);
                    IMap pMap = axMapControl1.Map;
                    IGraphicsContainer pGraphicsContainer = pMap as IGraphicsContainer;
                    IActiveView pActiveView = axMapControl1.ActiveView;
                    IMarkerElement pMarkerElement = new MarkerElementClass();
                    IElement pElement = pMarkerElement as IElement;
                    pElement.Geometry = pt;

                    pGraphicsContainer.AddElement((IElement)pMarkerElement, 0);
                    pActiveView.Refresh();

画线:

                    IMap pMap = axMapControl1.Map;
                    IGraphicsContainer pGraphicsContainer = axMapControl1.ActiveView as IGraphicsContainer;
                    IActiveView pActiveView = pGraphicsContainer as IActiveView;
                    IGeometry polyline;
                    polyline = axMapControl1.TrackLine();
                    ILineElement pLineElement;
                    pLineElement = new LineElementClass();
                    IElement pElement;
                    pElement = pLineElement as IElement;
                    pElement.Geometry = polyline;
                    pGraphicsContainer = pMap as IGraphicsContainer;
                    pGraphicsContainer.AddElement((IElement)pLineElement, 0);
                    pActiveView.Refresh();

画面:

                    IMap pMap = axMapControl1.Map;
                    IGraphicsContainer pGraphicsContainer = pMap as IGraphicsContainer;
                    IActiveView pActiveView = axMapControl1.ActiveView;
                    IGeometry Polygon = axMapControl1.TrackPolygon();
                    IPolygonElement PolygonElement = new PolygonElementClass();
                    IElement pElement = PolygonElement as IElement;
                    pElement.Geometry = Polygon;
                    pGraphicsContainer.AddElement((IElement)PolygonElement, 0);
                    pActiveView.Refresh();

画文字符号:

  IActiveView activeView = axMapControl1.ActiveView;
                    ITextSymbol pTextSymbol;
                    pTextSymbol = new TextSymbolClass();

                    pTextSymbol.Size = 10;
                    stdole.IFontDisp pFont;
                    //pFont = new stdole.StdFontClass() as stdole.IFontDisp;
                    //pFont.Name = "黑体";
                    //pTextSymbol.Font = pFont;
                    pTextSymbol.Color.RGB = 255;

                    ITextElement pTextElement = new TextElementClass();
                    pTextElement.Text = "李疆";
                    pTextElement.Symbol = pTextSymbol;

                    IElement pEle;
                    pEle = pTextElement as IElement;

                    IPoint pt = new PointClass();
                    pt = activeView.ScreenDisplay.DisplayTransformation.ToMapPoint(e.x, e.y);
                    pEle.Geometry = pt;


                    IGraphicsContainer pGraphicsContainer = axMapControl1.Map as IGraphicsContainer;
                    pGraphicsContainer.AddElement(pEle, 0);
                    activeView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);

右键弹出“取消编辑”内容框

 public partial class Form1 : Form
    {
       private void axMapControl1_OnMouseDown(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnMouseDownEvent e)
        {
            if (e.button == 1)
            {
                switch (edit)
                {
                    case "point":
                        {

                            IGraphicsContainer pGraphicsContainer = axMapControl1.ActiveView as IGraphicsContainer;
                            IActiveView pActiveView = pGraphicsContainer as IActiveView;
                            IMap pMap = axMapControl1.Map;
                            IPoint pt;
                            pt = axMapControl1.ToMapPoint(e.x, e.y);

                            IMarkerElement pMarkerElement;
                            pMarkerElement = new MarkerElementClass();
                            IElement pElement;
                            pElement = pMarkerElement as IElement;

                            pElement.Geometry = pt;
                            pGraphicsContainer = pMap as IGraphicsContainer;
                            pGraphicsContainer.AddElement((IElement)pMarkerElement, 0);
                            pActiveView.Refresh();
                            break;
                        }
                    case "line":
                        {
                            IMap pMap = axMapControl1.Map;
                            IGraphicsContainer pGraphicsContainer = axMapControl1.ActiveView as IGraphicsContainer;
                            IActiveView pActiveView = pGraphicsContainer as IActiveView;
                            IGeometry polyline;
                            polyline = axMapControl1.TrackLine();
                            ILineElement pLineElement;
                            pLineElement = new LineElementClass();
                            IElement pElement;
                            pElement = pLineElement as IElement;
                            pElement.Geometry = polyline;
                            pGraphicsContainer = pMap as IGraphicsContainer;
                            pGraphicsContainer.AddElement((IElement)pLineElement, 0);
                            pActiveView.Refresh();
                            break;
                        }
                    case "polygon":
                        {
                            IMap pMap = axMapControl1.Map;
                            IGraphicsContainer pGraphicsContainer = axMapControl1.ActiveView as IGraphicsContainer;
                            IActiveView pActiveView = pGraphicsContainer as IActiveView;
                            IGeometry Polygon;
                            Polygon = axMapControl1.TrackPolygon();
                            IPolygonElement PolygonElement;
                            PolygonElement = new PolygonElementClass();
                            IElement pElement;
                            pElement = PolygonElement as IElement;
                            pElement.Geometry = Polygon;
                            pGraphicsContainer = pMap as IGraphicsContainer;
                            pGraphicsContainer.AddElement((IElement)PolygonElement, 0);
                            pActiveView.Refresh();
                            break;
                        }

                    default:
                        break;
                }
            }

            IToolbarMenu mapPopMenu = null;
            mapPopMenu = new ToolbarMenu();//这个很关键,主要应用SDK封装的工具类似于C#的OpenDialog
            if (e.button == 2)
            {

                mapPopMenu.AddItem(new StopEditlalala(), -1, 0, false, esriCommandStyles.esriCommandStyleIconAndText);
                mapPopMenu.AddItem(new ControlsMapFullExtentCommand(), -1, 1, false, esriCommandStyles.esriCommandStyleIconAndText);
                mapPopMenu.SetHook(axMapControl1); 得到地图视窗右键菜单
                mapPopMenu.PopupMenu(e.x, e.y, axMapControl1.hWnd);//弹出显示菜单

            }
        }
}

 public class StopEditlalala : BaseCommand
        {
            private IMapControl3 m_mapControl;
            public StopEditlalala()
            {
                base.m_caption = "停止编辑!!!";
            }
            public override void OnClick()
            {
                if (Form1.edit == "")
                {
                    MessageBox.Show("没有正在编辑的内容!");
                    return;
                }
                Form1.edit = "";
                MessageBox.Show("已结束编辑!");
            }
            public override void OnCreate(object hook)
            {

                m_mapControl = (IMapControl3)hook;

            }
        }

运行结果:

完整项目下载:https://download.csdn.net/download/qq_40323256/10865950

评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值