public override void OnMouseDown(int button, int shift, int x, int y, double mapX, double mapY) { IPolygon pPoly; IEnvelope env = m_pMapControl.TrackRectangle() as ESRI.ArcGIS.Geometry.IEnvelope; pPoly = new PolygonClass(); ESRI.ArcGIS.Geometry.IPointCollection pc = pPoly as ESRI.ArcGIS.Geometry.IPointCollection; object missing = Type.Missing; pc.AddPoint(env.UpperLeft, ref missing, ref missing); pc.AddPoint(env.UpperRight, ref missing, ref missing); pc.AddPoint(env.LowerRight, ref missing, ref missing); pc.AddPoint(env.LowerLeft, ref missing, ref missing); IFeatureLayer pFeaLayer; // IRubberBand pRubberPoly = new RubberPolygonClass(); // pPoly = (IPolygon)pRubberPoly.TrackNew(m_Display, null); //遍历图层,查找选择框内的点要素,并标注 for (int i = 0; i < m_arrPntLayer.Count; i++) { pFeaLayer = m_arrPntLayer[i] as IFeatureLayer; ArrayList features = PublicFunction.SearchFeature(pFeaLayer.FeatureClass, pPoly, esriSpatialRelEnum.esriSpatialRelContains, false); for (int j = 0; j < features.Count; j++) { LabelPointFeature(features[j] as IFeature); } } this.m_pMapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null); }
private void QueryBoundsFromGeom(int hDC, ref ESRI.ArcGIS.Display.IDisplayTransformation transform, ref ESRI.ArcGIS.Geometry.IPolygon boundary, ref ESRI.ArcGIS.Geometry.IPoint point) { // Calculate Size, XOffset and YOffset of the shape in Map units. double dMapXOffset = 0; double dMapSize = 0; double dMapYOffset = 0; dMapSize = PointsToMap(transform, m_dSize); if (m_dXOffset != 0) dMapXOffset = PointsToMap(transform, m_dXOffset); if (m_dYOffset != 0) dMapYOffset = PointsToMap(transform, m_dYOffset); point.PutCoords(point.X + dMapXOffset, point.Y + dMapYOffset); // Set up the device ratio. SetupDeviceRatio(hDC, transform); ESRI.ArcGIS.Geometry.IPointCollection ptColl = null; ESRI.ArcGIS.Geometry.ISegmentCollection segColl = null; double dVal = 0; // dVal is the measurement of the short side of a Triangles are based on. double dRad = 0; ptColl = (IPointCollection)boundary; segColl = (ISegmentCollection)boundary; dRad = dMapSize / 2; dVal = System.Math.Sqrt((dRad * dRad) / 2); object missing = System.Reflection.Missing.Value; ptColl.AddPoint(Utility.CreatePoint(point.X + dVal, point.Y - dVal), ref missing, ref missing); ptColl.AddPoint(Utility.CreatePoint(point.X - dVal, point.Y - dVal), ref missing, ref missing); ptColl.AddPoint(Utility.CreatePoint(point.X - dVal, point.Y + dVal), ref missing, ref missing); IPoint p = ptColl.get_Point(0); segColl.AddSegment((ISegment)Utility.CreateCircArc(point, ptColl.get_Point(2), ref p), ref missing, ref missing); // Account for rotation also. ESRI.ArcGIS.Geometry.ITransform2D trans2D = null; if ((m_dAngle + m_dMapRotation) != 0) { trans2D = boundary as ITransform2D; trans2D.Rotate(point, Utility.Radians(m_dAngle + m_dMapRotation)); } }
/// <summary> /// 获取点击地图上的点 /// </summary> /// <param name="Button"></param> /// <param name="Shift"></param> /// <param name="X"></param> /// <param name="Y"></param> public override void OnMouseDown(int Button, int Shift, int X, int Y) { try { ESRI.ArcGIS.Geometry.IPoint pMapPoint = new ESRI.ArcGIS.Geometry.PointClass();; ISceneGraph pSceneGraph = m_sceneHookHelper.SceneGraph; object pOwner; object pObject; object before = Type.Missing; object after = Type.Missing; object StepSize = Type.Missing; IDisplay3D pDisplay; pSceneGraph.Locate(pSceneGraph.ActiveViewer, X, Y, esriScenePickMode.esriScenePickGeography, true, out pMapPoint, out pOwner, out pObject); //获取鼠标点击的位置并转化为地理坐标 if (pMapPoint == null) { return; } pMapPoint.Z = pMapPoint.Z / m_sceneHookHelper.Scene.ExaggerationFactor; pMapPoint.Z = m_psurface.GetElevation(pMapPoint); pMapPoint.SpatialReference = pSceneGraph.Scene.SpatialReference; pDisplay = m_sceneHookHelper.SceneGraph as IDisplay3D; pDisplay.FlashLocation(pMapPoint);//闪烁显示被点击的位置 IGeometry pGeom = null; Cls3DMarkDraw.DeleteAllElementsWithName(m_sceneHookHelper.Scene, sPolyOutlineName); //根据绘制对象类型的不同定义不同的类型 switch (m_DrawType.ToString()) { case "esriGeometryPoint": m_Geometry = pMapPoint; break; case "esriGeometryLine": if (m_pPointColl == null) { m_pPointColl = new PolylineClass(); pGeom = new PolylineClass(); } m_pPointColl.AddPoint(pMapPoint, ref before, ref after); break; case "esriGeometryPolygon": if (m_pPointColl == null) { m_pPointColl = new PolygonClass(); pGeom = new PolygonClass(); } m_pPointColl.AddPoint(pMapPoint, ref before, ref after); break; } //BeginDrawed(true); IGroupElement pGroup = null; if (m_pPointColl.PointCount == 1) { //当为一个点时绘制点 Cls3DMarkDraw.AddSimpleGraphic(pMapPoint, Cls3DMarkDraw.getRGB(71, 61, 255), 4, sPolyOutlineName, m_sceneHookHelper.Scene, pGroup); } else if (m_DrawType.ToString() == "esriGeometryLine") { pGeom = m_pPointColl as IGeometry; pGeom.SpatialReference = pMapPoint.SpatialReference; m_psurface.InterpolateShape(pGeom, out pGeom, ref StepSize); Cls3DMarkDraw.AddSimpleGraphic(pGeom, Cls3DMarkDraw.getRGB(71, 61, 255), 4, sPolyOutlineName, m_sceneHookHelper.Scene, pGroup); m_pPointColl = pGeom as IPointCollection; } else { ITopologicalOperator pTopo = m_pPointColl as ITopologicalOperator; pGeom = pTopo.Boundary; pGeom.SpatialReference = pMapPoint.SpatialReference; m_psurface.InterpolateShape(pGeom, out pGeom, ref StepSize); Cls3DMarkDraw.AddSimpleGraphic(pGeom, Cls3DMarkDraw.getRGB(71, 61, 255), 4, sPolyOutlineName, m_sceneHookHelper.Scene, pGroup); } m_sceneHookHelper.SceneGraph.RefreshViewers(); } catch { return; } }
public override void OnMouseDown(int Button, int Shift, int X, int Y) { try { ESRI.ArcGIS.Geometry.IPoint pMapPoint = new ESRI.ArcGIS.Geometry.PointClass();; object before = Type.Missing; object after = Type.Missing; object StepSize = Type.Missing; m_hookHelper.FocusMap.SpatialReference = m_psurface.Domain.SpatialReference; pMapPoint = m_hookHelper.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y); if (pMapPoint == null) { return; } pMapPoint.Project(m_psurface.Domain.SpatialReference); pMapPoint.Z = m_psurface.GetElevation(pMapPoint); //pMapPoint.SpatialReference = m_hookHelper.FocusMap.SpatialReference; //pDisplay = m_sceneHookHelper.SceneGraph as IDisplay3D; //pDisplay.FlashLocation(pMapPoint);//闪烁显示被点击的位置 IGeometry pGeom = null; ClsMarkDraw.DeleteAllElementsWithName(m_hookHelper.FocusMap, sPolyOutlineName); //根据绘制对象类型的不同定义不同的类型 switch (m_DrawType.ToString()) { case "esriGeometryPoint": m_Geometry = pMapPoint; break; case "esriGeometryLine": if (m_pPointColl == null) { m_pPointColl = new PolylineClass(); pGeom = new PolylineClass(); } m_pPointColl.AddPoint(pMapPoint, ref before, ref after); break; case "esriGeometryPolygon": if (m_pPointColl == null) { m_pPointColl = new PolygonClass(); pGeom = new PolygonClass(); } m_pPointColl.AddPoint(pMapPoint, ref before, ref after); break; } //BeginDrawed(true); IGroupElement pGroup = null; if (m_pPointColl.PointCount == 1) { //当为一个点时绘制点 ClsMarkDraw.AddSimpleGraphic(pMapPoint, ClsMarkDraw.getRGB(71, 61, 255), 3, sPolyOutlineName, m_hookHelper.FocusMap, pGroup); } else if (m_DrawType.ToString() == "esriGeometryLine") { pGeom = m_pPointColl as IGeometry; pGeom.SpatialReference = pMapPoint.SpatialReference; m_psurface.InterpolateShape(pGeom, out pGeom, ref StepSize); ClsMarkDraw.AddSimpleGraphic(pGeom, ClsMarkDraw.getRGB(71, 61, 255), 2, sPolyOutlineName, m_hookHelper.FocusMap, pGroup); m_pPointColl = pGeom as IPointCollection; } else { ITopologicalOperator pTopo = m_pPointColl as ITopologicalOperator; pGeom = pTopo.Boundary; pGeom.SpatialReference = pMapPoint.SpatialReference; m_psurface.InterpolateShape(pGeom, out pGeom, ref StepSize); ClsMarkDraw.AddSimpleGraphic(pGeom, ClsMarkDraw.getRGB(71, 61, 255), 2, sPolyOutlineName, m_hookHelper.FocusMap, pGroup); } m_hookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); } catch { return; } }