Beispiel #1
0
        public override void OnMouseDown(int Button, int Shift, int X, int Y)
        {
            // TODO:  Add ToolNewDisplacement.OnMouseDown implementation
            if (!DataReady())
            {
                MessageBox.Show("内检测、中线图层设置不正确");
                return;
            }

            object       Miss         = Type.Missing;
            IMapControl2 pMapCtr      = (((IToolbarControl)m_hookHelper.Hook).Buddy) as IMapControl2;
            IMapControl3 m_MapControl = pMapCtr as IMapControl3;

            if (pMapCtr != null)
            {
                //IGeoReference pGR = pRasterLayer as IGeoReference;
                IPoint mapPoint = pMapCtr.ToMapPoint(X, Y);
                m_NewLineFeedback.Display = pMapCtr.ActiveView.ScreenDisplay;
                if (bFlag == true)//起始点
                {
                    IPoint          point      = TransformToMapPoint(X, Y);
                    IPointSnapper   ptSnapper  = m_SnappingEnvironment.PointSnapper;
                    ISnappingResult snapresult = ptSnapper.Snap(point);
                    if (snapresult != null)
                    {
                        m_snappingFeed.UnInitialize();
                        m_snappingFeed.Initialize(m_MapControl.Object, m_SnappingEnvironment, true);
                        m_snappingFeed.Refresh(m_MapControl.ActiveView.ScreenDisplay.hDC);
                        m_SnappingEnvironment.SnappingType = esriSnappingType.esriSnappingTypePoint;
                        ISpatialFilter pSF    = new SpatialFilterClass();
                        IPoint         ProjPt = snapresult.Location;
                        ProjPt.Project(((IGeoDataset)(pIMULayer.FeatureClass)).SpatialReference);
                        pSF.Geometry      = ProjPt;
                        pSF.GeometryField = pIMULayer.FeatureClass.ShapeFieldName;
                        pSF.SpatialRel    = esriSpatialRelEnum.esriSpatialRelIntersects;
                        IFeatureCursor pCursor  = pIMULayer.FeatureClass.Search(pSF, false);
                        IFeature       pFeature = pCursor.NextFeature();
                        if (pFeature != null)
                        {
                            IMUFeature = pFeature;
                            m_NewLineFeedback.Start(mapPoint);

                            bFlag = false;
                        }
                        System.Runtime.InteropServices.Marshal.ReleaseComObject(pCursor);
                        System.Runtime.InteropServices.Marshal.ReleaseComObject(pSF);
                    }
                }
                else//目标点
                {
                    IPoint          point      = TransformToMapPoint(X, Y);
                    IPointSnapper   ptSnapper  = m_SnappingEnvironment.PointSnapper;
                    ISnappingResult snapresult = ptSnapper.Snap(point);
                    if (snapresult != null)
                    {
                        //m_snappingFeed.Refresh(m_MapControl.ActiveView.ScreenDisplay.hDC);
                        //m_snappingFeed.UnInitialize();
                        //m_snappingFeed.Refresh(m_MapControl.ActiveView.ScreenDisplay.hDC);
                        //m_snappingFeed.Initialize(m_MapControl.Object, m_SnappingEnvironment, true);

                        m_SnappingEnvironment.SnappingType = esriSnappingType.esriSnappingTypePoint;
                        ISpatialFilter pSF    = new SpatialFilterClass();
                        IPoint         ProjPt = snapresult.Location;
                        ProjPt.Project(((IGeoDataset)(pCenterlinePointLayer.FeatureClass)).SpatialReference);
                        pSF.Geometry      = ProjPt;
                        pSF.GeometryField = pCenterlinePointLayer.FeatureClass.ShapeFieldName;
                        pSF.SpatialRel    = esriSpatialRelEnum.esriSpatialRelIntersects;
                        IFeatureCursor pCursor  = pCenterlinePointLayer.FeatureClass.Search(pSF, false);
                        IFeature       pFeature = pCursor.NextFeature();
                        if (pFeature != null)
                        {
                            CenterlinePointFeature = pFeature;



                            if (m_CenterlinePointFeatureList.Count > 0)
                            {
                                double newIMUM        = Convert.ToDouble(IMUFeature.Value[m_IMUFeatureList[0].Fields.FindField("记录距离")]);
                                double newCenterlineM = Convert.ToDouble(CenterlinePointFeature.Value[m_CenterlinePointFeatureList[0].Fields.FindField("里程")]);
                                for (int i = 0; i < m_CenterlinePointFeatureList.Count; i++)
                                {
                                    double previewIMUM      = Convert.ToDouble(m_IMUFeatureList[i].Value[m_IMUFeatureList[0].Fields.FindField("记录距离")]);
                                    double previewCentlineM = Convert.ToDouble(m_CenterlinePointFeatureList[i].Value[m_CenterlinePointFeatureList[0].Fields.FindField("里程")]);

                                    if ((newIMUM - previewIMUM) * (newCenterlineM - previewCentlineM) <= 0)
                                    {
                                        MessageBox.Show("特征点不能交叉匹配.");
                                        return;
                                    }
                                }
                            }

                            m_IMUFeatureList.Add(IMUFeature);
                            m_CenterlinePointFeatureList.Add(CenterlinePointFeature);
                            bFlag = true;
                            IPolyline pPline = m_NewLineFeedback.Stop();
                            m_FrmVectorLinkTable.RefreshDataTable();
                        }
                    }
                    m_MapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewAll, null, null);
                    //m_snappingFeed.UnInitialize();

                    //m_snappingFeed.Initialize(m_MapControl.Object, m_SnappingEnvironment, true);
                    // m_snappingFeed.Refresh(m_MapControl.ActiveView.ScreenDisplay.hDC);
                }
            }
        }
Beispiel #2
0
 public void Refresh(int hdc)
 {
     m_snappingFeedback.Refresh(hdc);
 }