/// <summary> /// 插入线标记 并且将线标记移动到后面 /// </summary> /// <param name="mapControl"></param> /// <param name="pGeometry"></param> /// <returns></returns> public static IElement DrawLineSymbol(AxMapControl mapControl, IGeometry pGeometry) { IRgbColor pColor = GetColor(0, 255, 255); pColor.Transparency = 255; //产生一个线符号对象 ILineSymbol pOutline = new SimpleLineSymbolClass(); pOutline.Width = 4; pOutline.Color = pColor; ILineElement pLineElement = new LineElementClass(); pLineElement.Symbol = pOutline; IElement pElement = pLineElement as IElement; pElement.Geometry = pGeometry; //添加标注 InsertElement(mapControl, pElement, 0); IGraphicsContainerSelect tmpGSelect = (IGraphicsContainerSelect)mapControl.Map; //将元素移动到后面 tmpGSelect.SelectElement(pElement); IGraphicsContainer pGraphicsContainer = mapControl.Map as IGraphicsContainer; pGraphicsContainer.SendToBack(tmpGSelect.SelectedElements); tmpGSelect.UnselectAllElements(); return(pElement); }
public bool FocusOneElement(IPageLayout ipageLayout_0, IElement ielement_0) { bool result; try { IGraphicsContainerSelect graphicsContainerSelect = ipageLayout_0 as IGraphicsContainerSelect; if (graphicsContainerSelect == null) { result = false; return(result); } IActiveView activeView = ipageLayout_0 as IActiveView; activeView.PartialRefresh(esriViewDrawPhase.esriViewGraphicSelection, null, null); int elementSelectionCount = graphicsContainerSelect.ElementSelectionCount; if (elementSelectionCount >= 1) { graphicsContainerSelect.UnselectAllElements(); } graphicsContainerSelect.SelectElement(ielement_0); activeView.Refresh(); result = true; return(result); } catch { } result = false; return(result); }
public bool AddElement(IGraphicsContainer pGraphicsContainer, IElement pElement, bool bSelect, bool bPreserve) { try { if (pGraphicsContainer == null) { return(false); } if (pElement == null) { return(false); } pGraphicsContainer.AddElement(pElement, 0); if (bSelect && (pGraphicsContainer is IGraphicsContainerSelect)) { IGraphicsContainerSelect select = pGraphicsContainer as IGraphicsContainerSelect; if (!bPreserve) { select.UnselectAllElements(); } select.SelectElement(pElement); } return(true); } catch (Exception exception) { this.mErrOpt.ErrorOperate(this.mSubSysName, "FunFactory.ElementFun", "AddElement", exception.GetHashCode().ToString(), exception.Source, exception.Message, "", "", ""); return(false); } }
private void method_0() { IGraphicsContainer graphicsContainer = this.iactiveView_0.GraphicsContainer; IGraphicsContainerSelect graphicsContainerSelect = graphicsContainer as IGraphicsContainerSelect; graphicsContainerSelect.UnselectAllElements(); this.ienumElement_0.Reset(); IElement element = this.ienumElement_0.Next(); this.ilist_0.Clear(); while (element != null) { if ((!(element is IGraphicsComposite) ? false : !(element is IMapFrame))) { IEnumElement graphics = (element as IGraphicsComposite).Graphics[this.iactiveView_0.ScreenDisplay, null]; graphics.Reset(); for (IElement i = graphics.Next(); i != null; i = graphics.Next()) { graphicsContainer.AddElement(i, -1); graphicsContainerSelect.SelectElement(element); this.ilist_0.Add(i); } } element = this.ienumElement_0.Next(); } foreach (IElement list0 in this.list_0) { graphicsContainer.DeleteElement(list0); } }
private void method_0() { this.ienumElement_0.Reset(); IElement element = this.ienumElement_0.Next(); IGraphicsContainer graphicsContainer = this.iactiveView_0.GraphicsContainer; IGraphicsContainerSelect graphicsContainerSelect = graphicsContainer as IGraphicsContainerSelect; graphicsContainerSelect.UnselectAllElements(); graphicsContainer.DeleteElement(element); while (element != null) { if (element is IGroupElement) { IEnumElement elements = (element as IGroupElement).Elements; elements.Reset(); for (IElement i = elements.Next(); i != null; i = elements.Next()) { (element as IElementProperties2).AutoTransform = true; graphicsContainer.AddElement(i, -1); graphicsContainerSelect.SelectElement(i); } } element = this.ienumElement_0.Next(); } }
private void AddNormalTextElement(IPoint pPoint) { IGraphicsContainer pGraphicCtn = m_pAV.GraphicsContainer; try { frmEdit frmCallOut = new frmEdit(false); PublicClass.POINTAPI pos = new PublicClass.POINTAPI(); PublicClass.GetCursorPos(ref pos); int scrW = Screen.PrimaryScreen.Bounds.Width; //主显示宽度 int scrH = Screen.PrimaryScreen.Bounds.Height; //主显示高度 frmCallOut.Location = new System.Drawing.Point(pos.x, pos.y); // * pScreen.BitsPerPixel if (pos.x + frmCallOut.Width > scrW && pos.y + frmCallOut.Height > scrH) //超出显示器边界宽和高,则迂回 { frmCallOut.Location = new System.Drawing.Point(scrW - frmCallOut.Width, scrH - frmCallOut.Height); } if (pos.x + frmCallOut.Width > scrW && pos.y + frmCallOut.Height < scrH) //超出显示器边界宽,则迂回 { frmCallOut.Location = new System.Drawing.Point(scrW - frmCallOut.Width, pos.y); } if (pos.x + frmCallOut.Width < scrW && pos.y + frmCallOut.Height > scrH) //超出显示器边界高,则迂回 { frmCallOut.Location = new System.Drawing.Point(pos.x, scrH - frmCallOut.Height); } frmCallOut.ShowDialog(); if (frmCallOut.DialogResult == System.Windows.Forms.DialogResult.Cancel) { return; } ITextElement pTextElement = new TextElementClass(); pTextElement.ScaleText = true; pTextElement.Text = frmCallOut.AnnoText; IFormattedTextSymbol pTextSymbol = (IFormattedTextSymbol)frmCallOut.m_pTextSymbol; pTextElement.Symbol = pTextSymbol as ITextSymbol; IElement pElement = (IElement)pTextElement; pElement.Geometry = pPoint; //刷新显示 frmCallOut.Dispose(); IGraphicsContainerSelect pGraphicsSel = pGraphicCtn as IGraphicsContainerSelect; pGraphicsSel.UnselectAllElements(); pGraphicsSel.SelectElement(pElement); pGraphicCtn.AddElement(pElement, 0); m_pAV.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); } catch (Exception ex) { System.Windows.Forms.MessageBox.Show("添加文本注记失败:" + ex.Message, "提示"); return; } }
public void Undo() { IGraphicsContainer graphicsContainer = this.iactiveView_0.GraphicsContainer; IGraphicsContainerSelect graphicsContainerSelect = graphicsContainer as IGraphicsContainerSelect; graphicsContainerSelect.UnselectAllElements(); graphicsContainer.DeleteElement(this.igroupElement2_0 as IElement); this.ienumElement_0.Reset(); for (IElement i = this.ienumElement_0.Next(); i != null; i = this.ienumElement_0.Next()) { graphicsContainer.AddElement(i, -1); graphicsContainerSelect.SelectElement(i); } }
public void Undo() { IGraphicsContainer graphicsContainer = this.iactiveView_0.GraphicsContainer; IGraphicsContainerSelect graphicsContainerSelect = graphicsContainer as IGraphicsContainerSelect; graphicsContainerSelect.UnselectAllElements(); for (int i = 0; i < this.ilist_0.Count; i++) { graphicsContainer.DeleteElement(this.ilist_0[i] as IElement); } this.ienumElement_0.Reset(); for (IElement j = this.ienumElement_0.Next(); j != null; j = this.ienumElement_0.Next()) { if ((!(j is IGraphicsComposite) ? false : !(j is IMapFrame))) { graphicsContainer.AddElement(j, -1); graphicsContainerSelect.SelectElement(j); } } }
public static void FocusOneElement(IActiveView iactiveView_0, IElement ielement_0) { try { IGraphicsContainerSelect iactiveView0 = iactiveView_0 as IGraphicsContainerSelect; if (iactiveView0 != null) { iactiveView_0.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); if (iactiveView0.ElementSelectionCount >= 1) { iactiveView0.UnselectAllElements(); } iactiveView0.SelectElement(ielement_0); iactiveView_0.PartialRefresh(esriViewDrawPhase.esriViewGraphics, ielement_0, null); } } catch { } }
public void Undo() { this.ienumElement_0.Reset(); IElement element = this.ienumElement_0.Next(); IGraphicsContainer graphicsContainer = this.iactiveView_0.GraphicsContainer; IGraphicsContainerSelect graphicsContainerSelect = graphicsContainer as IGraphicsContainerSelect; graphicsContainerSelect.UnselectAllElements(); while (element != null) { if (element is IGroupElement) { IEnumElement elements = (element as IGroupElement).Elements; elements.Reset(); for (IElement i = elements.Next(); i != null; i = elements.Next()) { graphicsContainer.DeleteElement(i); } graphicsContainer.AddElement(element, -1); graphicsContainerSelect.SelectElement(element); } element = this.ienumElement_0.Next(); } }
internal static void GraphicsContainClearSelection() { IGraphicsContainerSelect graphicContainerSelect = g_axPageLayoutControl.PageLayout as IGraphicsContainerSelect; graphicContainerSelect.UnselectAllElements(); }
public override void OnMouseUp(int Button, int Shift, int X, int Y) { if (m_InUse == false) { return; } //Stop capturing mouse events if (GetCapture() == m_HookHelper.ActiveView.ScreenDisplay.hWnd) { ReleaseCapture(); } //If an envelope has not been tracked or its height/width is 0 if (m_Feedback == null) { m_Feedback = null; m_InUse = false; return; } IEnvelope envelope = m_Feedback.Stop(); if ((envelope.IsEmpty) || (envelope.Width == 0) || (envelope.Height == 0)) { m_Feedback = null; m_InUse = false; return; } frmSymbolSelector symbolForm = new frmSymbolSelector(); IStyleGalleryItem styleGalleryItem = symbolForm.GetItem(esriSymbologyStyleClass.esriStyleClassScaleTexts, null); //Release the form symbolForm.Dispose(); if (symbolForm.DialogResult != DialogResult.OK) { return; } if (styleGalleryItem == null) { return; } //Get the map frame of the focus map IMapFrame mapFrame = (IMapFrame)m_HookHelper.ActiveView.GraphicsContainer.FindFrame(m_HookHelper.ActiveView.FocusMap); //Create a map surround frame UID vUid = new UIDClass(); vUid.Value = "{7A3F91DC-B9E3-11d1-8756-0000F8751720}"; IMapSurroundFrame mapSurroundFrame = mapFrame.CreateSurroundFrame(vUid, (IMapSurround)styleGalleryItem.Item); IElement element = (IElement)mapSurroundFrame; element.Geometry = envelope; IElementProperties3 pep = element as IElementProperties3; pep.Name = "比例尺"; IGraphicsContainerSelect pGraphicsSel = m_HookHelper.ActiveView.GraphicsContainer as IGraphicsContainerSelect; pGraphicsSel.UnselectAllElements(); pGraphicsSel.SelectElement(element); m_HookHelper.ActiveView.GraphicsContainer.AddElement(element, 0); //Refresh m_HookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); m_Feedback = null; m_InUse = false; }
public override void OnMouseUp(int Button, int Shift, int X, int Y) { if (m_InUse == false) { return; } if (GetCapture() == m_HookHelper.ActiveView.ScreenDisplay.hWnd) { ReleaseCapture(); } if (m_Feedback == null) { m_Feedback = null; m_InUse = false; return; } IEnvelope envelope = m_Feedback.Stop(); if ((envelope.IsEmpty) || (envelope.Width == 0) || (envelope.Height == 0)) { m_Feedback = null; m_InUse = false; return; } frmSymbolSelector symbolForm = new frmSymbolSelector(); IStyleGalleryItem styleGalleryItem = symbolForm.GetItem(esriSymbologyStyleClass.esriStyleClassNorthArrows, null); symbolForm.Dispose(); if (symbolForm.DialogResult != DialogResult.OK) { return; } if (styleGalleryItem == null) { return; } IMapFrame mapFrame = (IMapFrame)m_HookHelper.ActiveView.GraphicsContainer.FindFrame(m_HookHelper.ActiveView.FocusMap); UID vUid = new UIDClass(); vUid.Value = "{7A3F91DD-B9E3-11d1-8756-0000F8751720}"; IMapSurroundFrame mapSurroundFrame = mapFrame.CreateSurroundFrame(vUid, (IMapSurround)styleGalleryItem.Item); IElement element = (IElement)mapSurroundFrame; element.Geometry = envelope; IElementProperties3 pep = element as IElementProperties3; pep.Name = "指北针"; IGraphicsContainerSelect pGraphicsSel = m_HookHelper.ActiveView.GraphicsContainer as IGraphicsContainerSelect; pGraphicsSel.UnselectAllElements(); pGraphicsSel.SelectElement(element); m_HookHelper.ActiveView.GraphicsContainer.AddElement(element, 0); m_HookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); if (m_HookHelper.Hook is IPageLayoutControl) { IPageLayoutControl pPLC = m_HookHelper.Hook as IPageLayoutControl; if (pPLC != null) { ////初始化控件工具为选择元素工具 //string progID = "esriControls.ControlsSelectTool"; //int index = axToolbarControl1.Find(progID); //if (index != -1) //{ // IToolbarItem toolItem = axToolbarControl1.GetItem(index); // ICommand _cmd = toolItem.Command; // ITool _tool = (ITool)_cmd; // pPLC.CurrentTool = _tool; //} } } m_Feedback = null; m_InUse = false; }
private void InsertPicture() { try { OpenFileDialog filedlg = new OpenFileDialog(); filedlg.Filter = "图像文件 (*.jpg;*.bmp;*.gif;*.tif;*.emf)|*.jpg;*.bmp;*.gif;*.tif;*.emf"; filedlg.Title = "选择图像文件"; if (filedlg.ShowDialog() == DialogResult.OK) { string sPath = filedlg.FileName; int pos = sPath.LastIndexOf('.'); string sExt = sPath.Substring(pos + 1); IPictureElement3 pPicElement = null; switch (sExt.ToLower()) { case "jpg": pPicElement = new JpgPictureElementClass(); break; case "bmp": pPicElement = new BmpPictureElementClass(); break; case "gif": pPicElement = new GifPictureElementClass(); break; case "tif": pPicElement = new TifPictureElementClass(); break; case "emf": pPicElement = new EmfPictureElementClass(); break; default: break; } if (pPicElement == null) { return; } pPicElement.ImportPictureFromFile(sPath); pPicElement.SavePictureInDocument = true; pPicElement.MaintainAspectRatio = true; IElementProperties pElementProp = (IElementProperties)pPicElement; pElementProp.Name = sPath; double picWidth = 0, picHeight = 0; pPicElement.QueryIntrinsicSize(ref picWidth, ref picHeight); //得到图片的象素点 //象素点转换成厘米 picWidth = picWidth / 37.79; picHeight = picHeight / 37.79; //将厘米转换为当前Page单位 ConvertUnit(m_pHookHelper.PageLayout.Page.Units, ref picWidth, ref picHeight); IPolygon pPoly = new PolygonClass(); IPointCollection pPntCln = (IPointCollection)pPoly; object obj = System.Type.Missing; IPoint pTmpPoint = new PointClass(); pTmpPoint.PutCoords(0, 0); pPntCln.AddPoint(pTmpPoint, ref obj, ref obj); pTmpPoint = new PointClass(); pTmpPoint.PutCoords(picWidth, 0); pPntCln.AddPoint(pTmpPoint, ref obj, ref obj); pTmpPoint = new PointClass(); pTmpPoint.PutCoords(picWidth, picHeight); pPntCln.AddPoint(pTmpPoint, ref obj, ref obj); pTmpPoint = new PointClass(); pTmpPoint.PutCoords(0, picHeight); pPntCln.AddPoint(pTmpPoint, ref obj, ref obj); pTmpPoint = new PointClass(); pTmpPoint.PutCoords(0, 0); pPntCln.AddPoint(pTmpPoint, ref obj, ref obj); double pageWidth, pageHeight; m_pHookHelper.PageLayout.Page.QuerySize(out pageWidth, out pageHeight); ITransform2D pTrans = (ITransform2D)pPoly; pTrans.Move(pageWidth / 2 - picWidth / 2, pageHeight / 2 - picHeight / 2); IElement pElement = null; pElement = (IElement)pPicElement; pElement.Geometry = pPoly; IGraphicsContainer pContainer = (IGraphicsContainer)m_pHookHelper.PageLayout; IGraphicsContainerSelect pGraphicsSel = pContainer as IGraphicsContainerSelect; pGraphicsSel.UnselectAllElements(); pGraphicsSel.SelectElement(pElement); pContainer.AddElement(pElement, 0); m_pHookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, pElement, null); } } catch (Exception ex) { MessageBox.Show("插入图片失败:" + ex.Message, "提示"); } }
private void axMapControl1_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e) { switch (toolAction) { case "Drag Zoom In": //判定当前的操作是否为拉框放大 IEnvelope pEnvelope = axMapControl1.TrackRectangle(); // 调用axMapControl1的矩形框跟踪功能进行拉框操作, //将拉框完成后的范围赋值给一个Envelope对象 //此处,你可以尝试axMapControl1.TrackPolygon(),axMapControl1.TrackCircle(),axMapControl1.TrackLine()等方法的调用,看有什么效果 if (pEnvelope == null || pEnvelope.IsEmpty || pEnvelope.Height == 0 || pEnvelope.Width == 0) //判定所获取的拉框范围是否无效 { return; // 拉框范围无效,就直接返回 } axMapControl1.Extent = pEnvelope; // 给地图窗口的空间范围赋值为刚才拉框的范围 axMapControl1.ActiveView.Refresh(); //地图刷新 return; case "Drag Zoom Out": //判定当前的操作是否为拉框缩小 IEnvelope pEnvelope1 = axMapControl1.TrackRectangle(); // 调用axMapControl1的矩形框跟踪功能进行拉框操作, //将拉框完成后的范围赋值给一个Envelope对象 //此处,你可以尝试axMapControl1.TrackPolygon(),axMapControl1.TrackCircle(),axMapControl1.TrackLine()等方法的调用,看有什么效果 if (pEnvelope1 == null || pEnvelope1.IsEmpty || pEnvelope1.Height == 0 || pEnvelope1.Width == 0) ////判定所获取的拉框范围是否无效 { return; //// 拉框范围无效,就直接返回 } IActiveView pActiveView = axMapControl1.ActiveView; // 获取地图视窗对象 double mHeight = pActiveView.Extent.Height * pActiveView.Extent.Height / pEnvelope1.Height; // 根据倍数计算新空间范围高度 double mWidth = pActiveView.Extent.Width * pActiveView.Extent.Width / pEnvelope1.Width; // 根据倍数计算新空间范围宽度 double mMinX = pActiveView.Extent.XMin - (pEnvelope1.XMin - pActiveView.Extent.XMin) * pActiveView.Extent.Width / pEnvelope1.Width; //计算新空间范围的x的最小值 double mMinY = pActiveView.Extent.YMin - (pEnvelope1.YMin - pActiveView.Extent.YMin) * pActiveView.Extent.Height / pEnvelope1.Height; //计算新空间范围的y的最小值 double mMaxX = mMinX + mWidth; //计算新空间范围的x的最大值 double mMaxY = mMinY + mHeight; // 计算新空间范围的y的最大值 pEnvelope1.PutCoords(mMinX, mMinY, mMaxX, mMaxY); // 给Envelope对象赋值新的空间范围 //(pActiveView.Extent.XMax-pActiveView.Extent.XMin)* axMapControl1.Extent = pEnvelope1; // 给地图范围赋值为新的空间范围 axMapControl1.ActiveView.Refresh(); //地图刷新 return; case "Pan": // 判定是否进行地图平移操作 axMapControl1.Pan(); //可执行地图平移 return; case "Select Feature Using Point": //点选要素 axMapControl1.ActiveView.FocusMap.ClearSelection(); // 清空当前地图的选择集; axMapControl1.ActiveView.Refresh(); tagRECT r; // 定义一个tagRECT结构变量,用于存放以当前鼠标为中心的长宽各为10个像素的小矩形 r.left = e.x - 5; // r.right = e.x + 5; // r.bottom = e.y - 5; // r.top = e.y + 5; // IEnvelope pEnv = new Envelope() as IEnvelope; // 创建一个Envelope对象,用于接受刚才创建的小矩形范围由屏幕坐标转换为地图坐标的值 axMapControl1.ActiveView.ScreenDisplay.DisplayTransformation.TransformRect(pEnv, ref r, 4); //把r的屏幕坐标转换为地图坐标,存入Envelope对象中 pEnv.SpatialReference = axMapControl1.ActiveView.FocusMap.SpatialReference; //设定Envelope对象的空间坐标参考与当前地图窗口的坐标一致 IGeometry pGeo = pEnv as IGeometry; //接口访问到IGeometry接口 axMapControl1.Map.SelectByShape(pGeo, null, false); //调用地图控件中map对象的SelectByShape方法,在地图中选择与pGeo相交或包含在其中的地图要素 //int selCount = axMapControl1.Map.SelectionCount; //IEnumFeature pEnumFeature = axMapControl1.Map.FeatureSelection as IEnumFeature; //IFeature pFeature = pEnumFeature.Next(); //while (pFeature != null) //{ // int index = pFeature.Fields.FindField("GB"); // str1 = Convert.ToString(pFeature.get_Value(index)); // MessageBox.Show(str1); // //string str2 = pFeature.get_Value(2).ToString(); // pFeature = pEnumFeature.Next(); //} ISelection selection = axMapControl1.Map.FeatureSelection; IEnumFeatureSetup iEnumFeatureSetup = (IEnumFeatureSetup)selection; iEnumFeatureSetup.AllFields = true; IEnumFeature pEnumFeature = (IEnumFeature)iEnumFeatureSetup; pEnumFeature.Reset(); IFeature pFeature = pEnumFeature.Next(); if (pFeature != null) { int index = pFeature.Fields.FindField("RNAME"); //string str1 = pFeature.OID.ToString(); if (index != -1) { str1 = pFeature.get_Value(index).ToString(); } //MessageBox.Show(str1); //pFeature = pEnumFeature.Next(); } axMapControl1.Refresh(esriViewDrawPhase.esriViewGeoSelection, null, null); // toolAction = ""; return; case "Select Feature Using Rectangle": //矩形选择要素 IEnvelope pEnvlope2 = axMapControl1.TrackRectangle(); // 进行矩形框的绘制追踪, if (pEnvlope2.IsEmpty == true) // 若矩形框为空 { tagRECT r1; r1.left = e.x - 5; r1.right = e.x + 5; r1.bottom = e.y - 5; r1.top = e.y + 5; axMapControl1.ActiveView.ScreenDisplay.DisplayTransformation.TransformRect(pEnvlope2, ref r1, 4); pEnvlope2.SpatialReference = axMapControl1.ActiveView.FocusMap.SpatialReference; } IGeometry pGeo1 = pEnvlope2 as IGeometry; axMapControl1.Map.SelectByShape(pGeo1, null, false); axMapControl1.Refresh(esriViewDrawPhase.esriViewGeoSelection, null, null); toolAction = ""; return; case "Select Feature Using Circle": // 圆形选择要素 IGeometry pCircl = axMapControl1.TrackCircle(); //圆形绘制 if (pCircl.IsEmpty == true) { return; } // IGeometry pGeo1 = pEnvlope2 as IGeometry; axMapControl1.Map.SelectByShape(pCircl, null, false); axMapControl1.Refresh(esriViewDrawPhase.esriViewGeoSelection, null, null); toolAction = ""; return; case "Select Feature Using Polygon": //多边形选择要素 IGeometry pPolygon = axMapControl1.TrackPolygon(); // 绘制多边形 if (pPolygon.IsEmpty == true) { return; } // IGeometry pGeo1 = pEnvlope2 as IGeometry; axMapControl1.Map.SelectByShape(pPolygon, null, false); axMapControl1.Refresh(esriViewDrawPhase.esriViewGeoSelection, null, null); toolAction = ""; return; case "Select Feature Using Polyline": // 线性选择要素 IGeometry pLine = axMapControl1.TrackLine(); //绘制线 if (pLine.IsEmpty == true) { return; } // IGeometry pGeo1 = pEnvlope2 as IGeometry; axMapControl1.Map.SelectByShape(pLine, null, false); axMapControl1.Refresh(esriViewDrawPhase.esriViewGeoSelection, null, null); toolAction = ""; return; case "Draw Polygon": IGeometry pPolygon1 = axMapControl1.TrackPolygon(); // 绘制多边形 if (pPolygon1 == null) { return; } IElement pElement = new PolygonElement(); pElement.Geometry = pPolygon1; IFillShapeElement pPolygonEle = pElement as IFillShapeElement; if (pSelectedFillSymbol != null) { pPolygonEle.Symbol = pSelectedFillSymbol; } IGraphicsContainer pGc = axMapControl1.ActiveView.GraphicsContainer; pGc.AddElement(pElement, 0); IGraphicsContainerSelect pGSelection = pGc as IGraphicsContainerSelect; pGSelection.UnselectAllElements(); pGSelection.SelectElement(pElement); toolAction = ""; axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); return; case "Draw Point": IPoint pPointMark = new ESRI.ArcGIS.Geometry.Point(); // 创建一个点 pPointMark.PutCoords(e.mapX, e.mapY); //给点赋值为当前鼠标所在位置的地图坐标 IGeometry pPointGeo = pPointMark as IGeometry; IElement pMElement = new MarkerElement(); pMElement.Geometry = pPointGeo; IMarkerElement pMarkElement = pMElement as IMarkerElement; if (pSelectedMarkSymbol != null) { pMarkElement.Symbol = pSelectedMarkSymbol; } IGraphicsContainer pGraphiscont = axMapControl1.ActiveView.GraphicsContainer; pGraphiscont.AddElement(pMElement, 0); IGraphicsContainerSelect pGS = pGraphiscont as IGraphicsContainerSelect; pGS.UnselectAllElements(); pGS.SelectElement(pMElement); toolAction = ""; axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); return; case "Draw Line": IGeometry pLineGeo = axMapControl1.TrackLine(); // 绘制Line if (pLineGeo == null) { return; } IElement pElement4 = new LineElement(); ILineElement pLineEle = pElement4 as ILineElement; if (pSelectedLineSymbol != null) { pLineEle.Symbol = pSelectedLineSymbol; } pElement4.Geometry = pLineGeo; IGraphicsContainer pGc4 = axMapControl1.ActiveView.GraphicsContainer; pGc4.AddElement(pElement4, 0); IGraphicsContainerSelect pGSelection4 = pGc4 as IGraphicsContainerSelect; pGSelection4.UnselectAllElements(); pGSelection4.SelectElement(pElement4); toolAction = ""; axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); return; case "Draw Text": IRgbColor pColor = new RgbColor(); pColor.Red = 150; pColor.Green = 150; pColor.Blue = 0; ITextSymbol pTextSymbol = new TextSymbol(); stdole.StdFont font = new stdole.StdFont(); font.Name = "宋体"; font.Size = 20; pTextSymbol.Font = font as stdole.IFontDisp; pTextSymbol.Color = pColor; pTextSymbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHALeft; pTextSymbol.VerticalAlignment = esriTextVerticalAlignment.esriTVABaseline; pTextSymbol.Text = "This is my First Text"; IPoint pTextPoint = new ESRI.ArcGIS.Geometry.Point(); // 创建一个点 pTextPoint.PutCoords(e.mapX, e.mapY); //给点赋值为当前鼠标所在位置的地图坐标 IGeometry pTextGeo = pTextPoint as IGeometry; IElement pTElement = new TextElement(); pTElement.Geometry = pTextGeo; ITextElement pTextEle = pTElement as ITextElement; pTextEle.Symbol = pTextSymbol; pTextEle.Text = pTextSymbol.Text; IGraphicsContainer pGraphisCon = axMapControl1.ActiveView.GraphicsContainer; pGraphisCon.AddElement(pTElement, 0); IGraphicsContainerSelect pGrhSelection = pGraphisCon as IGraphicsContainerSelect; pGrhSelection.UnselectAllElements(); pGrhSelection.SelectElement(pTElement); axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); toolAction = ""; break; case "Select Graphics by using Point": //通过点击获得GraphicsContainor中的element IPoint pPoint = new ESRI.ArcGIS.Geometry.Point(); // 创建一个点 pPoint.PutCoords(e.mapX, e.mapY); //给点赋值为当前鼠标所在位置的地图坐标 double dist = axMapControl1.ActiveView.Extent.Width / 15; //设置以点为圆心的查询的半径 IGraphicsContainer pGc1 = axMapControl1.ActiveView.GraphicsContainer; //获得地图的GraphicsContainor容器 IEnumElement pEnumElement = pGc1.LocateElements(pPoint, dist); //以点为中心点,按照指定半径选择element IGraphicsContainerSelect pGSelection1 = pGc1 as IGraphicsContainerSelect; //获得地图的容器中的图形要素选择集 if (pEnumElement != null) // { pEnumElement.Reset(); //回到-1位置 pGSelection1.UnselectAllElements(); //清空原来选择到的图形要素 pGSelection1.SelectElements(pEnumElement); //将新查询到的图形要素添加到GraphicsContainor容器中的图形要素选择集中 } axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); //图形要素刷新 return; } if (e.button == 2) //若单击鼠标右键 { contextMenuStrip2.Show(axMapControl1, e.x, e.y); //在TOC控件的当前鼠标位置弹出右键菜单 } }
public override void OnMouseUp(int Button, int Shift, int X, int Y) { if (m_InUse == false) { return; } if (GetCapture() == m_HookHelper.ActiveView.ScreenDisplay.hWnd) { ReleaseCapture(); } if (m_Feedback == null) { m_Feedback = null; m_InUse = false; return; } IEnvelope envelope = m_Feedback.Stop(); if ((envelope.IsEmpty) || (envelope.Width == 0) || (envelope.Height == 0)) { m_Feedback = null; m_InUse = false; return; } frmSymbolSelector symbolForm = new frmSymbolSelector(); IStyleGalleryItem styleGalleryItem = symbolForm.GetItem(esriSymbologyStyleClass.esriStyleClassScaleBars, null); symbolForm.Dispose(); if (symbolForm.DialogResult != DialogResult.OK) { return; } if (styleGalleryItem == null) { return; } IMapFrame mapFrame = (IMapFrame)m_HookHelper.ActiveView.GraphicsContainer.FindFrame(m_HookHelper.ActiveView.FocusMap); UID vUid = new UIDClass(); vUid.Value = "{6589F143-F7F7-11d2-B872-00600802E603}"; IMapSurroundFrame mapSurroundFrame = mapFrame.CreateSurroundFrame(vUid, (IMapSurround)styleGalleryItem.Item); if (mapSurroundFrame.MapSurround is IScaleBar) { IScaleBar pScalbeBar = (IScaleBar)mapSurroundFrame.MapSurround; pScalbeBar.Units = mapFrame.Map.MapUnits; switch (pScalbeBar.Units) { case esriUnits.esriMeters: pScalbeBar.UnitLabel = "米"; break; case esriUnits.esriKilometers: pScalbeBar.UnitLabel = "公里"; break; case esriUnits.esriMiles: pScalbeBar.UnitLabel = "英里"; break; case esriUnits.esriDecimalDegrees: pScalbeBar.UnitLabel = "度"; break; } } IElement element = (IElement)mapSurroundFrame; element.Geometry = envelope; IElementProperties3 pep = element as IElementProperties3; pep.Name = "比例尺"; IGraphicsContainerSelect pGraphicsSel = m_HookHelper.ActiveView.GraphicsContainer as IGraphicsContainerSelect; pGraphicsSel.UnselectAllElements(); pGraphicsSel.SelectElement(element); m_HookHelper.ActiveView.GraphicsContainer.AddElement(element, 0); m_HookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); m_Feedback = null; m_InUse = false; }