public static void CopyAndOverwriteMap(AxMapControl axMapControl, AxPageLayoutControl axPageLayoutControl) { IObjectCopy objectCopy = new ObjectCopyClass(); object toCopyMap = axMapControl.Map; object copiedMap = objectCopy.Copy(toCopyMap); IPageLayout pagelayout = axPageLayoutControl.PageLayout; object overwriteMap = (pagelayout as IActiveView).FocusMap; objectCopy.Overwrite(toCopyMap, ref overwriteMap); IGraphicsContainer pGraphicsContainer = pagelayout as IGraphicsContainer; IMapFrame pMapFrame = (IMapFrame)pGraphicsContainer.FindFrame(overwriteMap); IElement pElement = pMapFrame as IElement; IEnumElement pEnumElement = pGraphicsContainer.LocateElementsByEnvelope(pElement.Geometry.Envelope); IElement pElementIcon = pEnumElement.Next(); while (pElementIcon != null) { if (pElementIcon is IMapSurroundFrame) { if ((pElementIcon as IMapSurroundFrame).MapSurround is IScaleBar) { (pElementIcon as IMapSurroundFrame).MapFrame = pMapFrame; } } pElementIcon = pEnumElement.Next(); } axPageLayoutControl.ActiveView.Refresh(); }
private void InsertMapFrameToTree(IElement pElement, TOCTreeNodeCollection pParantNodes) { if (pElement is IMapFrame) { IMapFrame frame = (IMapFrame)pElement; string name = frame.Map.Name; if (name == "") { name = "Scene"; } TOCTreeNode pNode = new TOCTreeNodeEx(name, false, true); Bitmap bitmap = new Bitmap( base.GetType() .Assembly.GetManifestResourceStream("Yutai.ArcGIS.Controls.Controls.TOCTreeview.layers.bmp")); pNode.Image = bitmap; pNode.Tag = frame; pParantNodes.Add(pNode); this.InsertMapToTree((IBasicMap)frame.Map, pNode); } else if (pElement is IGroupElement) { IGroupElement element = (IGroupElement)pElement; IEnumElement elements = element.Elements; elements.Reset(); for (IElement element3 = elements.Next(); element3 != null; element3 = elements.Next()) { this.InsertMapFrameToTree(element3, pParantNodes); } } }
private void axPageLayoutControl1_OnDoubleClick(object sender, ESRI.ArcGIS.Controls.IPageLayoutControlEvents_OnDoubleClickEvent e) { if (e.button == 1) { //标注的修改 if (axPageLayoutControl1.CurrentTool == null) { return; } if (((axPageLayoutControl1.CurrentTool) as ICommand).Name == "ControlToolsGraphicElement_SelectTool") { IPoint pPoint = new PointClass(); pPoint.PutCoords(e.pageX, e.pageY); IGraphicsContainer pGraphicsContainer = axPageLayoutControl1.PageLayout as IGraphicsContainer; IEnumElement pEnumElement = pGraphicsContainer.LocateElements(pPoint, 10); if (pEnumElement != null) { IElement pElement = pEnumElement.Next(); if (pElement is ITextElement) { ITextElement ptextElement = pElement as ITextElement; MapPrint.TextSetUp textSetUp = new MapPrint.TextSetUp(); textSetUp.UpdateTextElement(ptextElement); textSetUp.Show(); } } } } }
public override void OnClick() { IGraphicsContainer graphicsContainer = this._context.ActiveView.GraphicsContainer; IGraphicsContainerSelect graphicsContainerSelect = graphicsContainer as IGraphicsContainerSelect; IEnumElement selectedElements = graphicsContainerSelect.SelectedElements; MapTemplateGroupElement mapTemplateGroupElement = new MapTemplateGroupElement(MapTemplate.CurrentMapTemplate); mapTemplateGroupElement.Create(selectedElements); mapTemplateGroupElement.Save(); List <IElement> list = new List <IElement>(); selectedElements.Reset(); for (IElement element = selectedElements.Next(); element != null; element = selectedElements.Next()) { list.Add(element); } foreach (IElement current in list) { graphicsContainer.DeleteElement(current); } IGraphicsContainer graphicsContainer2 = this._context.ActiveView.GraphicsContainer; IElement element2 = mapTemplateGroupElement.GetElement(this._context.ActiveView as IPageLayout); graphicsContainer2.AddElement(element2, -1); this._context.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, element2, null); }
/// <summary> /// 查询地图上的标注Element /// </summary> /// <param name="point">地图上的点</param> /// <param name="tolerance">缓冲距离</param> /// <returns></returns> private IEnumElement queryElementOnMap(IPoint point, double tolerance) { IGraphicsContainer pGContainer = axMapControl1.Map as IGraphicsContainer; IEnumElement pEunmEle = pGContainer.LocateElements(point, tolerance); return(pEunmEle); }
private void SetMapSurroundFrameMapGroupRecursion(IGroupElement pGroupElement, IMap pMap) { try { if (((pGroupElement != null) && (pGroupElement.ElementCount > 0)) && (pMap != null)) { IEnumElement elements = null; elements = pGroupElement.Elements; elements.Reset(); IMapSurroundFrame frame = null; IElement element2 = null; for (element2 = elements.Next(); element2 != null; element2 = elements.Next()) { if (element2 is IMapSurroundFrame) { frame = element2 as IMapSurroundFrame; frame.MapSurround.Map = pMap; } else if (element2 is IGroupElement) { this.SetMapSurroundFrameMapGroupRecursion(element2 as IGroupElement, pMap); } } } } catch (Exception exception) { this.mErrOpt.ErrorOperate(this.mSubSysName, "FunFactory.ElementFun", "SetMapSurroundFrameMapGroupRecursion", exception.GetHashCode().ToString(), exception.Source, exception.Message, "", "", ""); } }
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 static IMapFrame FindFocusMapFrame(IGroupElement igroupElement_0, IMap imap_0) { IEnumElement elements = igroupElement_0.Elements; elements.Reset(); for (IElement element2 = elements.Next(); element2 != null; element2 = elements.Next()) { if (element2 is IMapFrame) { if (imap_0 == (element2 as IMapFrame).Map) { return(element2 as IMapFrame); } } else if (element2 is IGroupElement) { IMapFrame frame2 = FindFocusMapFrame(element2 as IGroupElement, imap_0); if (frame2 != null) { return(frame2); } } } return(null); }
private void method_4(IGraphicsContainer igraphicsContainer_0, IEnvelope ienvelope_0) { IGroupElement2 element = null; IGraphicsContainerSelect select = igraphicsContainer_0 as IGraphicsContainerSelect; IEnumElement selectedElements = select.SelectedElements; selectedElements.Reset(); IElement element3 = selectedElements.Next(); element = new GroupElementClass(); (element as IElement).Geometry = ienvelope_0; while (element3 != null) { element.AddElement(element3); element.Refresh(); element3 = selectedElements.Next(); } igraphicsContainer_0.AddElement(element as IElement, -1); (element as IElement).QueryBounds((igraphicsContainer_0 as IActiveView).ScreenDisplay, ienvelope_0); selectedElements.Reset(); for (element3 = selectedElements.Next(); element3 != null; element3 = selectedElements.Next()) { igraphicsContainer_0.DeleteElement(element3); } select.SelectElement(element as IElement); }
private IElement GetSelectedPointElement() { IMap activeFrame = m_hookHelper.FocusMap; IGraphicsContainerSelect graphicsSel = activeFrame as IGraphicsContainerSelect; IElement selectedElement = null; IAGAnimationType graphicAnimationType = new AnimationTypeMapGraphic(); if (graphicsSel.ElementSelectionCount > 0) { IEnumElement enumElem = graphicsSel.SelectedElements; selectedElement = enumElem.Next(); while (selectedElement != null) { if (graphicAnimationType.get_AppliesToObject(selectedElement)) { break; } selectedElement = enumElem.Next(); } } else { selectedElement = null; } return(selectedElement); }
public override void OnMouseDown(int Button, int Shift, int X, int Y) { if (Button == 1) { IGraphicsContainer pGraphicsContainer = m_hookHelper.ActiveView as IGraphicsContainer; m_point = m_hookHelper.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y); IEnumElement pEnumElement = pGraphicsContainer.LocateElements(m_point, 1); if (pEnumElement == null) { return; } m_element = pEnumElement.Next(); if (m_element is AnnotationElement) { ITextElement pTextElement = new TextElementClass { Text = ((ITextElement)m_element).Text, Symbol = ((ITextElement)m_element).Symbol, ScaleText = true }; m_viewElement = pTextElement as IElement; m_viewElement.Geometry = m_element.Geometry; m_hookHelper.ActiveView.GraphicsContainer.AddElement(m_viewElement, 0); m_hookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, m_viewElement, null); } // 移动状态信息 m_moving = true; } }
protected override void OnMouseDown(MouseEventArgs arg) { IMxDocument pmxdoc = ArcMap.Application.Document as IMxDocument; IPoint pPoint = pmxdoc.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(arg.X, arg.Y); IGraphicsContainer pgc = pmxdoc.ActiveView.GraphicsContainer; IEnumElement eElements = pgc.LocateElements(pPoint, 5); if (eElements == null) { return; } eElements.Reset(); IElement pElement = eElements.Next(); while (pElement != null) { IElementProperties pElementProps = pElement as IElementProperties; MessageBox.Show(pElementProps.Name); pElement = eElements.Next(); } }
private void GroupElement(IGraphicsContainer pGC, IEnvelope pEnvelop) { IGroupElement2 groupElementClass = null; IGraphicsContainerSelect graphicsContainerSelect = pGC as IGraphicsContainerSelect; IEnumElement selectedElements = graphicsContainerSelect.SelectedElements; selectedElements.Reset(); IElement i = selectedElements.Next(); if (groupElementClass == null) { groupElementClass = new GroupElement() as IGroupElement2; (groupElementClass as IElement).Geometry = pEnvelop; while (i != null) { groupElementClass.AddElement(i); groupElementClass.Refresh(); i = selectedElements.Next(); } } pGC.AddElement(groupElementClass as IElement, -1); (groupElementClass as IElement).QueryBounds((pGC as IActiveView).ScreenDisplay, pEnvelop); selectedElements.Reset(); for (i = selectedElements.Next(); i != null; i = selectedElements.Next()) { pGC.DeleteElement(i); } graphicsContainerSelect.SelectElement(groupElementClass as IElement); }
private IEnvelope method_3(IGraphicsContainerSelect igraphicsContainerSelect_0) { try { IEnumElement selectedElements = igraphicsContainerSelect_0.SelectedElements; selectedElements.Reset(); IEnvelope envelope = null; IEnvelope inEnvelope = null; for (IElement element2 = selectedElements.Next(); element2 != null; element2 = selectedElements.Next()) { if (envelope == null) { envelope = element2.Geometry.Envelope; } else { inEnvelope = element2.Geometry.Envelope; envelope.Union(inEnvelope); } } if ((envelope != null) && ((envelope.Width == 0.0) || (envelope.Height == 0.0))) { envelope.Expand(0.001, 0.001, false); return(envelope); } } catch (Exception) { } return(null); }
/// <summary> /// 从组合元素中查找元素,被查找的元素不是组合元素 /// </summary> /// <param name="groupElement"></param> /// <param name="elementName"></param> /// <returns></returns> public static IElement GetFirstElementByName(this IGroupElement groupElement, string elementName) { IElement resultElement = null; IEnumElement enumEle = groupElement.Elements; IElement tmpEle; while ((tmpEle = enumEle.Next()) != null) { if ((tmpEle as IGroupElement) != null) { resultElement = GetFirstElementByName(tmpEle as IGroupElement, elementName); if (resultElement != null) { break; } } else { if ((tmpEle as IElementProperties)?.Name == elementName) { resultElement = tmpEle; break; } } } return(resultElement); }
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 method_0() { IElement element2; IGraphicsContainerSelect select = this.ipageLayout_0 as IGraphicsContainerSelect; if (select.ElementSelectionCount > 0) { this.rdoPlaceSelectElement.Enabled = true; this.rdoPlaceSelectElement.Checked = true; this.rdoPlaceAllElement.Checked = false; this.rdoPlacePageMargine.Checked = false; IEnumElement selectedElements = select.SelectedElements; selectedElements.Reset(); element2 = selectedElements.Next(); if ((select.ElementSelectionCount == 1) && (element2 is IFrameElement)) { this.chkNewFrameElement.Checked = false; this.chkNewFrameElement.Enabled = true; this.chkGroup.Checked = false; this.chkGroup.Enabled = false; this.iframeElement_0 = element2 as IFrameElement; this.method_1(element2 as IFrameElement); } else { this.chkNewFrameElement.Checked = true; this.chkNewFrameElement.Enabled = false; this.chkGroup.Checked = false; this.chkGroup.Enabled = true; } } else { this.rdoPlaceSelectElement.Enabled = false; this.rdoPlaceSelectElement.Checked = false; this.rdoPlaceAllElement.Checked = true; this.rdoPlacePageMargine.Checked = false; IGraphicsContainer container = this.ipageLayout_0 as IGraphicsContainer; container.Reset(); element2 = container.Next(); if (!((container.Next() == null) && (element2 is IFrameElement))) { this.chkNewFrameElement.Checked = true; this.chkNewFrameElement.Enabled = false; this.chkGroup.Checked = false; this.chkGroup.Enabled = true; } else { this.chkNewFrameElement.Checked = false; this.chkNewFrameElement.Enabled = true; this.chkGroup.Checked = false; this.chkGroup.Enabled = false; this.iframeElement_0 = element2 as IFrameElement; this.method_1(element2 as IFrameElement); } } }
private void delete_ele_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { IGraphicsContainerSelect pGraphicsCSelect = this.axPageLayoutControl1.GraphicsContainer as IGraphicsContainerSelect; IEnumElement pEnumEle = pGraphicsCSelect.SelectedElements; IElement ele = pEnumEle.Next(); while (ele != null) { this.axPageLayoutControl1.GraphicsContainer.DeleteElement(ele); this.axPageLayoutControl1.Refresh(); ele = pEnumEle.Next(); } }
public override void OnClick() { IGraphicsContainer graphicsContainer = this._context.ActiveView.GraphicsContainer; IGraphicsContainerSelect graphicsContainerSelect = graphicsContainer as IGraphicsContainerSelect; IEnumElement selectedElements = graphicsContainerSelect.SelectedElements; IGroupElementOperation groupElementOperation = new GroupElementOperation(); groupElementOperation.ActiveView = this._context.ActiveView; groupElementOperation.Elements = selectedElements; this._context.OperationStack.Do(groupElementOperation); this._context.ActiveView.Refresh(); //DocumentManager.DocumentChanged(this._context.Hook); }
public static IElement getElement(AxPageLayoutControl axPageLayoutControl, IPoint pPoint) { IPageLayout pageLayout = axPageLayoutControl.PageLayout; IGraphicsContainer pGraphicsContainer = pageLayout as IGraphicsContainer; IEnumElement pEnumElement = pGraphicsContainer.LocateElements(pPoint, 0); pEnumElement.Reset(); var pElement = pEnumElement.Next(); while (pElement != null && (pElement is IMapFrame)) { pElement = pEnumElement.Next(); } return(pElement); }
/// <summary> /// 鼠标弹起结束绘制 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void mapControl_OnMouseUp(object sender, IMapControlEvents2_OnMouseUpEvent e) { IPoint point = new PointClass() { X = e.mapX, Y = e.mapY }; envelope = rectangleFeedback.Stop() as IEnvelope; int layerCount = mapControl.LayerCount; for (int i = 0; i < layerCount; i++) { ILayer layer = mapControl.get_Layer(i); CompositeGraphicsLayerClass comp = layer as CompositeGraphicsLayerClass; if (comp == null) { continue; } if (envelope.IsEmpty == true) { elementEnums = comp.LocateElements(point, 0); } else { elementEnums = comp.LocateElementsByEnvelope(envelope); } List <IElement> list = new List <IElement>(); if (elementEnums == null) { return; } IElement el = null; do { el = elementEnums.Next(); if (el != null) { var element = el as IMFElement; listElements.Add(element); } }while (el != null); } ReleaseCommond(); }
private IMapFrame GetMapFrameGroupRecursion(IGroupElement pGroupElement, string sMapClassifyName, string sMapName) { try { if (pGroupElement != null) { if (pGroupElement.ElementCount <= 0) { return(null); } IEnumElement elements = null; elements = pGroupElement.Elements; elements.Reset(); IMapFrame frame = null; IElement element2 = null; for (element2 = elements.Next(); element2 != null; element2 = elements.Next()) { if (element2 is IMapFrame) { frame = element2 as IMapFrame; IElementProperties properties = null; properties = frame as IElementProperties; if ((Strings.LCase(Strings.Mid(Convert.ToString(properties.CustomProperty), 4)) == Strings.LCase(sMapClassifyName)) && (string.IsNullOrEmpty(sMapName) | (frame.Map.Name == sMapName))) { return(frame); } } else if (element2 is IGroupElement) { frame = this.GetMapFrameGroupRecursion(element2 as IGroupElement, sMapClassifyName, sMapName); if (frame != null) { return(frame); } } } } return(null); } catch (Exception exception) { this.mErrOpt.ErrorOperate(this.mSubSysName, "FunFactory.ElementFun", "GetMapFrameGroupRecursion", exception.GetHashCode().ToString(), exception.Source, exception.Message, "", "", ""); return(null); } }
public void Create(IEnumElement ienumElement_0) { ienumElement_0.Reset(); IElement element = ienumElement_0.Next(); if (this.igroupElement_0 == null) { this.igroupElement_0 = new GroupElementClass(); } while (element != null) { this.igroupElement_0.AddElement((element as IClone).Clone() as IElement); element = ienumElement_0.Next(); } if ((this.igroupElement_0 as IElement).Geometry.Envelope.IsEmpty) { } }
public override void OnClick() { IEnumElement selectedElements = (this._context.ActiveView as IGraphicsContainerSelect).SelectedElements; IAlignElementsOperation alignElementsOperation = new AlignElementsOperation(); IElement dominantElement = (this._context.ActiveView as IGraphicsContainerSelect).DominantElement; if (dominantElement != null) { IEnvelope envelope = new Envelope() as IEnvelope; dominantElement.QueryBounds(this._context.ActiveView.ScreenDisplay, envelope); alignElementsOperation.Elements = selectedElements; alignElementsOperation.AlignEnvelope = envelope; alignElementsOperation.AlignType = (enumAlignType)this.AlignType; alignElementsOperation.ActiveView = this._context.ActiveView; this._context.OperationStack.Do(alignElementsOperation); //DocumentManager.DocumentChanged(this._context.Hook); } }
public bool HitTestElement(IActiveView pActiveView, long x, long y, bool bMapUnit) { try { if (pActiveView != null) { IPoint point = null; if (bMapUnit) { point = new PointClass { X = x, Y = y }; } else { point = pActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint((int)x, (int)y); } double dPixelUnits = 3.0; dPixelUnits = GISFunFactory.UnitFun.ConvertPixelsToMapUnits(pActiveView, dPixelUnits, true); IEnumElement element = null; element = (pActiveView as IGraphicsContainer).LocateElements(point, dPixelUnits); if (element == null) { return(false); } IElement element2 = null; element.Reset(); for (element2 = element.Next(); element2 != null; element2 = element.Next()) { if (!element2.Locked) { return(true); } } } return(false); } catch (Exception exception) { this.mErrOpt.ErrorOperate(this.mSubSysName, "FunFactory.ElementFun", "HitTestElement", exception.GetHashCode().ToString(), exception.Source, exception.Message, "", "", ""); return(false); } }
/// <summary> /// Occurs when this command is clicked /// </summary> public override void OnClick() { try { m_pAV = m_pHookHelper.ActiveView; IViewManager pViewManager = (IViewManager)m_pAV; IEnumElement pEnumElement = (IEnumElement)pViewManager.ElementSelection; pEnumElement.Reset(); IElement pElement = pEnumElement.Next(); if (pElement == null) { return; } int i = 0; while (pElement != null) { i++; pElement = pEnumElement.Next(); if (i > 1) { return; } } pEnumElement.Reset(); pElement = pEnumElement.Next(); if (pElement is IMapSurroundFrame) { IMapSurroundFrame pMapSFrame = (IMapSurroundFrame)pElement; if (pMapSFrame.MapSurround is ILegend) { frmAddLegend vFrmLegend = new frmAddLegend(false); vFrmLegend.SetMapSurroundFrame(pMapSFrame); return; } } frmElementProperty frm = new frmElementProperty(2); frm.StartEditElement(m_pAV, ref pElement); frm.ShowDialog(); frm.Dispose(); } catch { } }
/// <summary> /// 在屏幕中添加标记元素 /// </summary> /// <param name="n"></param> private void drawElement(ExceptionsInfo n) { IFeature pFeature; IQueryFilter pQFilter = new QueryFilter(); pQFilter.WhereClause = "\"projectName\"='" + n.ProjectID + "'"; IFeatureLayer pFlayer = LayerHelper.getFeatureLayerFromMap(axMapControl1.Map, "Cities"); //获取特定图层 IFeatureCursor pFtCursor = pFlayer.Search(pQFilter, true); //查找对应结果的要素 IRgbColor pColor1 = setRGBColor(255, 0, 0, 255); IRgbColor pColor2 = setRGBColor(0, 255, 0, 255); IElement ele = createElement(pColor1, pColor2); IElementProperties pEleProperties = (IElementProperties)ele; pEleProperties.Name = n.ProjectID; //设置element的Name属性方便查找 IGraphicsContainer pGContainer = axMapControl1.Map as IGraphicsContainer; IActiveView pView = pGContainer as IActiveView; while ((pFeature = pFtCursor.NextFeature()) != null) { IPoint pPoint = pFeature.Shape as IPoint; IElement pEleTemp; IEnumElement pEnumEle = queryElementOnMap(pPoint, 0); if (pEnumEle != null) //检查地图中是否已存在此元素 { while ((pEleTemp = pEnumEle.Next()) != null) { IElementProperties pEleProTemp = (IElementProperties)pEleTemp; if (pEleProTemp.Name == n.ProjectID) { return; } //if (!pEleProTemp.Name.Contains(n.ProjectID)) //{ // pEleProTemp.Name += "," + n.ProjectID; // pGContainer.UpdateElement((IElement)pEleProTemp); // return; //} } } ele.Geometry = pPoint; pGContainer.AddElement(ele, 0); } }
/// <summary> /// 从组合元素中获取所有子元素(包括所有层级的子元素,但不包括组合元素本身) /// </summary> /// <param name="groupElement">组合元素</param> /// <returns></returns> public static List <IElement> GetElements(this IGroupElement groupElement) { List <IElement> elementList = new List <IElement>(); IEnumElement enumEle = groupElement.Elements; IElement tmpEle; while ((tmpEle = enumEle.Next()) != null) { if ((tmpEle as IGroupElement) != null) { elementList.AddRange(GetElements(tmpEle as IGroupElement)); } else { elementList.Add(tmpEle); } } return(elementList); }
/// <summary> /// Occurs when this command is clicked /// </summary> public override void OnClick() { // TODO: Add CmdDelectSelElement.OnClick implementation IGraphicsContainer pGraphicsContainer = m_hookHelper.ActiveView.GraphicsContainer; IGraphicsContainerSelect pGraphicsContainerSelect = pGraphicsContainer as IGraphicsContainerSelect; int SelectElementCount = pGraphicsContainerSelect.ElementSelectionCount; IEnumElement pEnumElement = pGraphicsContainerSelect.SelectedElements; pEnumElement.Reset(); IElement pElement = pEnumElement.Next(); for (int i = 0; i < SelectElementCount; i++) { pGraphicsContainer.DeleteElement(pElement); pElement = pEnumElement.Next(); m_hookHelper.ActiveView.Refresh(); } }
/// <summary> /// 根据点击位置和需要的element类型,取得在该位置的给类型的element /// </summary> /// <param name="pPoint"></param> /// <param name="geometryType"></param> /// <returns></returns> private IElement getElement(IPoint pPoint, esriGeometryType geometryType) { IEnumElement pEnumElement = this.pGraphicContainer.LocateElements(pPoint, this.axMapControl1.ActiveView.Extent.Width / 100); if (pEnumElement != null) { pEnumElement.Reset(); IElement pElement; for (pElement = pEnumElement.Next(); pElement != null; pElement = pEnumElement.Next()) { if (pElement.Geometry.GeometryType == geometryType) { this.hitElement = pElement; return(pElement); } } return(null); } return(null); }
public static IGeometry get_GraphicShape(IEnumElement theElements, int a_Dimensionality, bool multipart) { IGeometry theReturn = null; IGeometryCollection theGeomColl = null; object missing = Type.Missing; if (theElements != null) { theElements.Reset(); IElement theElement = theElements.Next(); while (theElement != null) { if (theGeomColl == null) theGeomColl = new GeometryBagClass(); IGeometry theShape = null; if (theElement is IGroupElement) { theShape = get_GraphicShape(((IGroupElement)theElement).Elements, a_Dimensionality, multipart); } else if (theElement is ICircleElement || theElement is IPolygonElement || theElement is IRectangleElement || theElement is IEllipseElement || theElement is ILineElement || theElement is IMarkerElement) theShape = theElement.Geometry; if (theShape != null) theGeomColl.AddGeometry(theShape, ref missing, ref missing); theElement = theElements.Next(); } } if (theGeomColl != null && theGeomColl.GeometryCount > 0) { ITopologicalOperator theTopoOp = null; switch (a_Dimensionality) { case 0: if (multipart) { theTopoOp = new MultipointClass(); theTopoOp.ConstructUnion((IEnumGeometry)theGeomColl); } else theTopoOp = theGeomColl.get_Geometry(0) as ITopologicalOperator; break; case 1: theTopoOp = new PolylineClass(); theTopoOp.ConstructUnion((IEnumGeometry)theGeomColl); break; case 2: theTopoOp = new PolygonClass(); theTopoOp.ConstructUnion((IEnumGeometry)theGeomColl); break; } theReturn = theTopoOp as IGeometry; } return theReturn; }
public static int get_Dimensionality(IEnumElement theElements, out bool multipart) { int theReturn = -1; multipart = false; if (theElements != null) { theElements.Reset(); IElement theElement = theElements.Next(); while (theElement != null) { int theDim = -1; if (theElement is IGroupElement) { theDim = get_Dimensionality(((IGroupElement)theElement).Elements, out multipart); } else if (theElement is IFillShapeElement) { if (theElement is ICircleElement || theElement is IPolygonElement || theElement is IRectangleElement || theElement is IEllipseElement) theDim = 2; } else if (theElement is ILineElement) { theDim = 1; } else if (theElement is IMarkerElement) { theDim = 0; } if (theReturn == -1) theReturn = theDim; else if (theReturn != theDim) theReturn = -1; else multipart = true; if (theReturn == -1) break; theElement = theElements.Next(); } } return theReturn; }
/// <summary> /// 鼠标点击 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void axMapControl1_OnMouseDown(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnMouseDownEvent e) { try { if (e.button == 1)//按左键的话 { IPoint pPoint = new PointClass();//在鼠标点击的位置生成一个点 pPoint.PutCoords(e.mapX, e.mapY); if (this.btnNewPolyline.Checked)//画多义线 { if (this.pDisplayFeedback == null)//如果是第一次点击,就建立第一个节点 { this.pDisplayFeedback = new NewLineFeedbackClass(); this.pDisplayFeedback.Display = this.pScreenDisplay; ((INewLineFeedback)this.pDisplayFeedback).Start(pPoint); } else//如果不是第一次点击,就添加节点 { ((INewLineFeedback)this.pDisplayFeedback).AddPoint(pPoint); } } else if (this.btnLineMovePoint.Checked)//移动多义线节点 { IElement pElement = this.getElement(pPoint, esriGeometryType.esriGeometryPolyline); if (pElement != null) { IPolyline pPolyline = pElement.Geometry as IPolyline; IHitTest pHitTest = pPolyline as IHitTest; IPoint hitPoint = new PointClass(); double distance = 0; bool isOnRightSide = false; int hitPartIndex = 0; int hitSegmentIndex = 0; bool isHit = pHitTest.HitTest(pPoint, this.axMapControl1.ActiveView.Extent.Width / 100, esriGeometryHitPartType.esriGeometryPartVertex, hitPoint, ref distance, ref hitPartIndex, ref hitSegmentIndex, ref isOnRightSide); if (isHit) { this.pDisplayFeedback = new LineMovePointFeedbackClass(); this.pDisplayFeedback.Display = this.pScreenDisplay; ((ILineMovePointFeedback)this.pDisplayFeedback).Start(pPolyline, hitSegmentIndex, pPoint); } } } else if (this.btnNewCircle.Checked)//画圆 { this.pDisplayFeedback = new NewCircleFeedbackClass(); this.pDisplayFeedback.Display = this.pScreenDisplay; ((INewCircleFeedback)this.pDisplayFeedback).Start(pPoint); } else if (this.btnNewEnvelope.Checked)//画矩形 { this.pDisplayFeedback = new NewEnvelopeFeedbackClass(); this.pDisplayFeedback.Display = this.pScreenDisplay; ((INewEnvelopeFeedback)this.pDisplayFeedback).Constraint = esriEnvelopeConstraints.esriEnvelopeConstraintsNone; ((INewEnvelopeFeedback)this.pDisplayFeedback).Start(pPoint); } else if (this.btnNewPolygon.Checked)//画多边形 { if (this.pDisplayFeedback == null)//如果是第一次点击,就建立第一个节点 { this.pDisplayFeedback = new NewPolygonFeedbackClass(); this.pDisplayFeedback.Display = this.pScreenDisplay; ((INewPolygonFeedback)this.pDisplayFeedback).Start(pPoint); } else//如果不是第一次点击,就添加节点 { ((INewPolygonFeedback)this.pDisplayFeedback).AddPoint(pPoint); } } else if (this.btnPolygonMovePoint.Checked)//移动多边形节点 { IElement pElement = this.getElement(pPoint, esriGeometryType.esriGeometryPolygon); if (pElement != null) { IPolygon pPolygon = pElement.Geometry as IPolygon; IHitTest pHitTest = pPolygon as IHitTest; IPoint hitPoint = new PointClass(); double distance = 0; bool isOnRightSide = true; int hitPartIndex = 0; int hitSegmentIndex = 0; bool isHit = pHitTest.HitTest(pPoint, this.axMapControl1.ActiveView.Extent.Width / 100, esriGeometryHitPartType.esriGeometryPartVertex, hitPoint, ref distance, ref hitPartIndex, ref hitSegmentIndex, ref isOnRightSide); if (isHit) { this.pDisplayFeedback = new PolygonMovePointFeedbackClass(); this.pDisplayFeedback.Display = this.pScreenDisplay; ((IPolygonMovePointFeedback)this.pDisplayFeedback).Start(pPolygon, hitSegmentIndex, pPoint); } } } else if (this.btnNewBezierCurve.Checked)//新建Bezier曲线 { if (this.pDisplayFeedback == null)//如果是第一次点击 { this.pDisplayFeedback = new NewBezierCurveFeedbackClass(); this.pDisplayFeedback.Display = this.pScreenDisplay; ((INewBezierCurveFeedback)this.pDisplayFeedback).Start(pPoint); } else//如果不是第一次点击 { ((INewBezierCurveFeedback)this.pDisplayFeedback).AddPoint(pPoint); } } else if (this.btnMoveGeometry.Checked)//移动几何对象 { this.pEnumElement = this.pGraphicContainer.LocateElements(pPoint, this.pActiveView.Extent.Width / 100); if (this.pEnumElement != null) { this.pDisplayFeedback = new MoveGeometryFeedbackClass(); this.pDisplayFeedback.Display = this.pScreenDisplay; IElement pElement; this.pEnumElement.Reset(); //需要逐个逐个添加Geometry for (pElement = this.pEnumElement.Next(); pElement != null; pElement = this.pEnumElement.Next()) { ((IMoveGeometryFeedback)this.pDisplayFeedback).AddGeometry(pElement.Geometry); } ((IMoveGeometryFeedback)this.pDisplayFeedback).Start(pPoint); this.moveGeometryStartPoint = pPoint; } } else if (this.btnStretchLine.Checked)//拉伸多义线 { IElement pElement = this.getElement(pPoint, esriGeometryType.esriGeometryPolyline); if (pElement != null) { IPolyline pPolyline = pElement.Geometry as IPolyline; this.pDisplayFeedback = new StretchLineFeedbackClass(); this.pDisplayFeedback.Display = this.pScreenDisplay; ((IStretchLineFeedback)this.pDisplayFeedback).Anchor = pPolyline.FromPoint; ((IStretchLineFeedback)this.pDisplayFeedback).Start(pPolyline, pPoint); } } } else if (e.button == 2)//按右键的就把画面清空 { if (this.pDisplayFeedback == null) { this.pGraphicContainer.DeleteAllElements(); this.axMapControl1.Refresh(); } } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
/// <summary> /// 松开鼠标 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void axMapControl1_OnMouseUp(object sender, IMapControlEvents2_OnMouseUpEvent e) { if (this.pDisplayFeedback != null) { if (this.btnLineMovePoint.Checked)//移动多义线节点 { IGeometry pGeometry = ((ILineMovePointFeedback)this.pDisplayFeedback).Stop(); if (pGeometry != null) { this.hitElement.Geometry = pGeometry; this.pGraphicContainer.UpdateElement(this.hitElement); } this.hitElement = null; this.pDisplayFeedback = null; this.axMapControl1.Refresh(esriViewDrawPhase.esriViewGraphics, null, null); } else if (this.btnNewCircle.Checked)//画圆 { IGeometry pGeometry = ((INewCircleFeedback)this.pDisplayFeedback).Stop(); this.AddElement(pGeometry); this.pDisplayFeedback = null; } else if (this.btnNewEnvelope.Checked)//画矩形 { IGeometry pGeometry = ((INewEnvelopeFeedback)this.pDisplayFeedback).Stop(); this.AddElement(pGeometry); this.pDisplayFeedback = null; } else if (this.btnPolygonMovePoint.Checked)//移动多边形节点 { IGeometry pGeometry = ((IPolygonMovePointFeedback)this.pDisplayFeedback).Stop(); if (pGeometry != null) { this.hitElement.Geometry = pGeometry; this.pGraphicContainer.UpdateElement(this.hitElement); } this.hitElement = null; this.pDisplayFeedback = null; this.axMapControl1.Refresh(esriViewDrawPhase.esriViewGraphics, null, null); } else if (this.btnMoveGeometry.Checked)//移动几何对象 { if (this.pEnumElement != null) { this.pEnumElement.Reset(); IElement pElement; ITransform2D pTransform2D; //需要用ITransform2D接口逐个逐个的移动element for (pElement = this.pEnumElement.Next(); pElement != null; pElement = this.pEnumElement.Next()) { pTransform2D = pElement as ITransform2D; pTransform2D.Move(e.mapX - this.moveGeometryStartPoint.X, e.mapY - this.moveGeometryStartPoint.Y); this.pGraphicContainer.UpdateElement(pElement); } this.moveGeometryStartPoint = null; this.pEnumElement = null; this.pDisplayFeedback = null; this.axMapControl1.Refresh(esriViewDrawPhase.esriViewGraphics, null, null); } } else if (this.btnStretchLine.Checked)//拉伸多义线 { if (this.hitElement != null) { IGeometry pGeometry = ((IStretchLineFeedback)this.pDisplayFeedback).Stop(); this.hitElement.Geometry = pGeometry; this.pGraphicContainer.UpdateElement(this.hitElement); this.hitElement = null; this.pDisplayFeedback = null; this.axMapControl1.Refresh(esriViewDrawPhase.esriViewGraphics, null, null); } } } }
private static int get_Dimensionality(IEnumElement theElements, out bool multipart) { int theReturn = -1; multipart = false; try { if (theElements != null) { theElements.Reset(); IElement theElement = theElements.Next(); while (theElement != null) { int theDim = -1; if (theElement is IGroupElement) { theDim = get_Dimensionality(((IGroupElement)theElement).Elements, out multipart); } else if (theElement is IFillShapeElement) { if (theElement is ICircleElement || theElement is IPolygonElement || theElement is IRectangleElement || theElement is IEllipseElement) theDim = 2; } else if (theElement is ILineElement) { theDim = 1; } else if (theElement is IMarkerElement) { theDim = 0; } if (theReturn == -1) theReturn = theDim; else if (theReturn != theDim) theReturn = -1; else multipart = true; if (theReturn == -1) break; theElement = theElements.Next(); } } } catch(Exception ex) { util.Logger.Write(" Descrip : Determining the dimensionality of graphic elements. " + "\n Message : " + ex.Message + "\n StackTrc : " + ex.StackTrace,util.Logger.LogLevel.Debug); } return theReturn; }
private static IGeometry get_GraphicShape(IEnumElement theElements, int a_Dimensionality, bool multipart, ref IElementCollection elemCollection) { IGeometry theReturn = null; IGeometryCollection theGeomColl = null; object missing = Type.Missing; try { elemCollection.Clear(); if (theElements != null) { theElements.Reset(); IElement theElement = theElements.Next(); while (theElement != null) { if (theGeomColl == null) theGeomColl = new GeometryBagClass(); IGeometry theShape = null; if (theElement is IGroupElement) { theShape = get_GraphicShape(((IGroupElement)theElement).Elements, a_Dimensionality, multipart,ref elemCollection); } else if (theElement is ICircleElement || theElement is IPolygonElement || theElement is IRectangleElement || theElement is IEllipseElement || theElement is ILineElement || theElement is IMarkerElement) theShape = theElement.Geometry; if (theShape != null) theGeomColl.AddGeometry(theShape, ref missing, ref missing); elemCollection.Add(theElement,-1); theElement = theElements.Next(); } } if (theGeomColl != null && theGeomColl.GeometryCount > 0) { ITopologicalOperator theTopoOp = null; switch (a_Dimensionality) { case 0: if (multipart) { theTopoOp = new MultipointClass(); theTopoOp.ConstructUnion((IEnumGeometry)theGeomColl); } else theTopoOp = theGeomColl.get_Geometry(0) as ITopologicalOperator; break; case 1: theTopoOp = new PolylineClass(); theTopoOp.ConstructUnion((IEnumGeometry)theGeomColl); break; case 2: theTopoOp = new PolygonClass(); theTopoOp.ConstructUnion((IEnumGeometry)theGeomColl); break; } theReturn = theTopoOp as IGeometry; } } catch(Exception ex) { util.Logger.Write(" Descrip : Finding elements with a specific dimensionality. " + "\n Message : " + ex.Message + "\n StackTrc : " + ex.StackTrace,util.Logger.LogLevel.Debug); } return theReturn; }