protected override void OnActivate() { //Get the snap environment and initialize the feedback UID snapUID = new UID(); this.Cursor = Cursors.Cross; snapUID.Value = "{E07B4C52-C894-4558-B8D4-D4050018D1DA}"; if (ArcMap.Application != null) { m_SnappingEnv = ArcMap.Application.FindExtensionByCLSID(snapUID) as ISnappingEnvironment; } if (m_SnappingEnv != null) { m_Snapper = m_SnappingEnv.PointSnapper; } m_SnappingFeedback = new SnappingFeedbackClass(); m_SnappingFeedback.Initialize(ArcMap.Application, m_SnappingEnv, true); Mediator.NotifyColleagues(VisibilityLibrary.Constants.MAP_POINT_TOOL_ACTIVATED, true); // Also notify what the previous tool was so it can be set back Mediator.NotifyColleagues(VisibilityLibrary.Constants.MAP_TOOL_CHANGED, lastActiveToolGuid); }
protected override void OnActivate() { //Get the snap environment and initialize the feedback UID snapUID = new UID(); this.Cursor = Cursors.Cross; snapUID.Value = "{E07B4C52-C894-4558-B8D4-D4050018D1DA}"; m_SnappingEnv = ArcMap.Application.FindExtensionByCLSID(snapUID) as ISnappingEnvironment; m_Snapper = m_SnappingEnv.PointSnapper; m_SnappingFeedback = new SnappingFeedbackClass(); m_SnappingFeedback.Initialize(ArcMap.Application, m_SnappingEnv, true); }
//设置捕捉环境 public static void StartSnappingEnv() { if (m_bStartSnap) { m_SnappingEnv = DataEditCommon.GetSnapEnvironment(m_hookHelper, snappingType); if (m_SnappingEnv != null) { m_Snapper = m_SnappingEnv.PointSnapper; m_SnappingFeedback = new SnappingFeedbackClass(); m_SnappingFeedback.Initialize(m_hookHelper.Hook, m_SnappingEnv); } } }
public void Initialize(IEditor pEditor) { // Initialize the constructor m_editor = pEditor as IEditor; m_edSketch = pEditor as IEditSketch3; //Get the snap environment m_snappingEnv = m_editor.Parent.FindExtensionByName("ESRI Snapping") as ISnappingEnvironment; m_snapper = m_snappingEnv.PointSnapper; m_snappingFeedback = new SnappingFeedbackClass(); m_snappingFeedback.Initialize(m_editor.Parent, m_snappingEnv, true); m_firstPoint = new PointClass(); m_secondPoint = new PointClass(); m_activePoint = new PointClass(); // Set the phase to inactive so we start at the beginning m_etoolPhase = ToolPhase.Inactive; }
/// <summary> /// Occurs when this tool is created /// </summary> /// <param name="hook">Instance of the application</param> public override void OnCreate(object hook) { if (m_hookHelper == null) { m_hookHelper = new HookHelperClass(); } m_hookHelper.Hook = hook; // TODO: Add ToolNewDisplacement.OnCreate implementation IMapControl2 pMapCtr = (((IToolbarControl)m_hookHelper.Hook).Buddy) as IMapControl2; //m_NewLineFeedback.Display = pMapCtr.ActiveView.ScreenDisplay; //m_FrmVectorLinkTable.OriginPoints = OriginPoints; //m_FrmVectorLinkTable.TargetPoints = TargetPoints; m_FrmVectorLinkTable.IMUFeatureList = m_IMUFeatureList; m_FrmVectorLinkTable.CenterlinePointFeatureList = m_CenterlinePointFeatureList; m_FrmVectorLinkTable.MapCtr = pMapCtr; //m_FrmVectorLinkTable.refreshLayer += new RefreshEvent(RefreshLayer); if (m_FrmVectorLinkTable != null) { m_FrmVectorLinkTable.Owner = System.Windows.Forms.Form.FromChildHandle(User32API.GetCurrentWindowHandle()) as System.Windows.Forms.Form; } IExtensionManager extensionManager = ((IHookHelper2)m_hookHelper).ExtensionManager; UID guid = new UIDClass(); guid.Value = "{E07B4C52-C894-4558-B8D4-D4050018D1DA}"; //Snapping extension. IExtension extension = extensionManager.FindExtension(guid); m_SnappingEnvironment = extension as ISnappingEnvironment; m_snappingFeed = new SnappingFeedbackClass(); m_snappingFeed.Initialize(hook, m_SnappingEnvironment, true); }
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); } } }
//������ public static void StartSnappingEnv() { if (m_bStartSnap) { m_SnappingEnv = DataEditCommon.GetSnapEnvironment(m_hookHelper, snappingType); if (m_SnappingEnv != null) { m_Snapper = m_SnappingEnv.PointSnapper; m_SnappingFeedback = new SnappingFeedbackClass(); m_SnappingFeedback.Initialize(m_hookHelper.Hook, m_SnappingEnv); } } }