Ejemplo n.º 1
0
        /// <summary>
        /// 这里的鼠标点击事件中包含了根据[当前工具条的命令]进行相应事件触发的逻辑
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void axMapControl_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e)
        {
            if (!ApplicationV.IsBanFormMainMapClick)
            {
                try
                {
                    //屏幕坐标点转化为地图坐标点
                    pPointPt = (axMapControl.Map as IActiveView).ScreenDisplay.DisplayTransformation.ToMapPoint(e.x, e.y);

                    if (e.button == 1)
                    {
                        IActiveView pActiveView = axMapControl.ActiveView;
                        IEnvelope   pEnvelope   = new EnvelopeClass();

                        switch (pMouseOperate)
                        {
                            #region 区域导出
                        case "ExportRegion":
                            //删除视图中数据
                            axMapControl.ActiveView.GraphicsContainer.DeleteAllElements();
                            axMapControl.ActiveView.Refresh();
                            IPolygon pPolygon = MapUtils.DrawPolygon(axMapControl);
                            if (pPolygon == null)
                            {
                                return;
                            }
                            MapUtils.AddElement(pPolygon, axMapControl.ActiveView);
                            presenter.CallOutFormExport(false, pPolygon);
                            break;
                            #endregion

                            #region 距离量算
                        case "MeasureLength":
                            //判断追踪线对象是否为空,若是则实例化并设置当前鼠标点为起始点
                            if (pNewLineFeedback == null)
                            {
                                //实例化追踪线对象
                                pNewLineFeedback         = new NewLineFeedbackClass();
                                pNewLineFeedback.Display = (axMapControl.Map as IActiveView).ScreenDisplay;
                                //设置起点,开始动态线绘制
                                pNewLineFeedback.Start(pPointPt);
                                dToltalLength = 0;
                            }
                            else     //如果追踪线对象不为空,则添加当前鼠标点
                            {
                                pNewLineFeedback.AddPoint(pPointPt);
                            }
                            //pGeometry = m_PointPt;
                            if (dSegmentLength != 0)
                            {
                                dToltalLength = dToltalLength + dSegmentLength;
                            }
                            break;
                            #endregion

                            #region 面积量算
                        case "MeasureArea":
                            if (pNewPolygonFeedback == null)
                            {
                                //实例化追踪面对象
                                pNewPolygonFeedback         = new NewPolygonFeedback();
                                pNewPolygonFeedback.Display = (axMapControl.Map as IActiveView).ScreenDisplay;
                                ;
                                pAreaPointCol.RemovePoints(0, pAreaPointCol.PointCount);
                                //开始绘制多边形
                                pNewPolygonFeedback.Start(pPointPt);

                                pAreaPointCol.AddPoint(pPointPt, ref missing, ref missing);
                            }

                            else
                            {
                                pNewPolygonFeedback.AddPoint(pPointPt);

                                pAreaPointCol.AddPoint(pPointPt, ref missing, ref missing);
                            }
                            break;
                            #endregion

                            #region 要素选择
                        case "SelectFeature":
                            IPoint    point     = new PointClass();
                            IGeometry pGeometry = point as IGeometry;
                            axMapControl.Map.SelectByShape(pGeometry, null, false);
                            axMapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, null);
                            break;
                            #endregion

                        default:
                            break;
                        }
                    }
                    else if (e.button == 2)
                    {
                        pMouseOperate             = "";
                        axMapControl.MousePointer = esriControlsMousePointer.esriPointerDefault;
                    }
                }
                catch (Exception exception)
                {
                    Console.WriteLine(exception);
                }
            }
            switch (e.button)
            {
            case (4):
            {
                Map.Pan();
                break;
            }
            }
        }