/// <summary>
 /// 全域导出
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void btnExportMap_Click(object sender, EventArgs e)
 {
     if (FrmExpMap == null || FrmExpMap.IsDisposed)
     {
         FrmExpMap = new FormExportMap(MainMapControl);
     }
     FrmExpMap.IsRegion   = false;
     FrmExpMap.GetGometry = MainMapControl.ActiveView.Extent;
     FrmExpMap.Show();
     FrmExpMap.Activate();
 }
Beispiel #2
0
        /// <summary>
        /// 地图中鼠标按下事件监听
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MainMapControl_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e)
        {
            //屏幕坐标点转化为地图坐标点
            pPointPt = (MainMapControl.Map as IActiveView).ScreenDisplay.DisplayTransformation.ToMapPoint(e.x, e.y);
            if (e.button == 1)
            {
                IActiveView pActiveView = MainMapControl.ActiveView;
                IEnvelope   pEnvelope   = new EnvelopeClass();

                switch (pMouseOperate)
                {
                case "ZoomIn":
                    pEnvelope = MainMapControl.TrackRectangle();
                    //  如果拉框范围为空则返回
                    if (pEnvelope == null || pEnvelope.IsEmpty || pEnvelope.Height == 0 || pEnvelope.Width == 0)
                    {
                        return;
                    }
                    // 如果拉框有范围,则拉大到拉框范围
                    MainMapControl.ActiveView.Extent = pEnvelope;
                    MainMapControl.ActiveView.Refresh();
                    break;

                case "ZoomOut":
                    pEnvelope = MainMapControl.TrackRectangle();
                    //  如果拉框范围为空则返回
                    if (pEnvelope == null || pEnvelope.IsEmpty || pEnvelope.Height == 0 || pEnvelope.Width == 0)
                    {
                        return;
                    }
                    else
                    {
                        double dWidth  = pActiveView.Extent.Width * pActiveView.Extent.Width / pEnvelope.Width;
                        double dHeight = pActiveView.Extent.Height * pActiveView.Extent.Height / pEnvelope.Height;
                        double dXmin   = pActiveView.Extent.XMin -
                                         ((pEnvelope.XMin - pActiveView.Extent.XMin) * pActiveView.Extent.Width /
                                          pEnvelope.Width);
                        double dYmin = pActiveView.Extent.YMin -
                                       ((pEnvelope.YMin - pActiveView.Extent.YMin) * pActiveView.Extent.Height /
                                        pEnvelope.Height);
                        double dXmax = dXmin + dWidth;
                        double dYmax = dYmin + dHeight;
                        pEnvelope.PutCoords(dXmin, dYmin, dXmax, dYmax);
                    }
                    pActiveView.Extent = pEnvelope;
                    pActiveView.Refresh();
                    break;

                case "Pan":
                    MainMapControl.Pan();
                    break;

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

                case "MeasureArea":
                    if (pNewPolygonFeedback == null)
                    {
                        //实例化追踪面对象
                        pNewPolygonFeedback         = new NewPolygonFeedback();
                        pNewPolygonFeedback.Display = (MainMapControl.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;

                case "SelFeature":
                    IEnvelope pEnv = MainMapControl.TrackRectangle();
                    IGeometry pGeo = pEnv as IGeometry;
                    // 矩形框若为空,即为点选时,对点的范围进行扩展
                    if (pEnv.IsEmpty == true)
                    {
                        tagRECT r;
                        r.left   = e.x - 5;
                        r.top    = e.y - 5;
                        r.right  = e.x + 5;
                        r.bottom = e.y + 5;
                        pActiveView.ScreenDisplay.DisplayTransformation.TransformRect(pEnv, ref r, 4);
                        pEnv.SpatialReference = pActiveView.FocusMap.SpatialReference;
                    }
                    pGeo = pEnv as IGeometry;
                    MainMapControl.Map.SelectByShape(pGeo, null, false);
                    MainMapControl.Refresh(esriViewDrawPhase.esriViewGeoSelection, null, null);

                    //IEnvelope pEnv = MainMapControl.TrackRectangle();
                    //IGeometry pGeo = pEnv as IGeometry;
                    ////矩形框若为空,即为点选时,对点范围进行扩展
                    //if (pEnv.IsEmpty == true)
                    //{
                    //    tagRECT r;
                    //    r.left = e.x - 5;
                    //    r.top = e.y - 5;
                    //    r.right = e.x + 5;
                    //    r.bottom = e.y + 5;
                    //    pActiveView.ScreenDisplay.DisplayTransformation.TransformRect(pEnv, ref r, 4);
                    //    pEnv.SpatialReference = pActiveView.FocusMap.SpatialReference;
                    //}
                    //pGeo = pEnv as IGeometry;
                    //MainMapControl.Map.SelectByShape(pGeo, null, false);
                    //MainMapControl.Refresh(esriViewDrawPhase.esriViewGeoSelection, null, null);

                    break;

                case "ExportRegion":
                    // 删除视图中的数据
                    MainMapControl.ActiveView.GraphicsContainer.DeleteAllElements();
                    MainMapControl.ActiveView.Refresh();
                    IPolygon polygon = DrawPolygon(MainMapControl);
                    if (polygon == null)
                    {
                        return;
                    }
                    ExportMap.AddElement(polygon, MainMapControl.ActiveView);
                    if (FrmExpMap == null || FrmExpMap.IsDisposed)
                    {
                        FrmExpMap = new FormExportMap(MainMapControl);
                    }
                    FrmExpMap.IsRegion   = true;
                    FrmExpMap.GetGometry = polygon as IGeometry;
                    FrmExpMap.Show();
                    FrmExpMap.Activate();
                    break;

                case "TxtSymbol":
                    TxtSymbol(e);
                    break;

                default:
                    break;
                }
            }
            else if (e.button == 2)
            {
                pMouseOperate = "";
                MainMapControl.MousePointer = esriControlsMousePointer.esriPointerDefault;
            }
        }