public void ClearMapFromOldGraphics() { var actualGraphics = new List <GraphicElement>(milSpaceSessionGraphics); actualGraphics.AddRange(milSpaceCalculatingGraphics); graphics.Reset(); IElement ge = graphics.Next(); while (ge != null) { var graphic = actualGraphics.FirstOrDefault(graph => graph.Element.Equals(ge)); if (graphic != null) { actualGraphics.Remove(graphic); } else { graphics.DeleteElement(ge); } ge = graphics.Next(); } graphics.Reset(); activeView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); }
/// <summary> /// 清除布局所有要素,除了框架 /// </summary> /// <param name="pageLayoutControl">布局控件</param> public static void ClearAllLayoutData(AxPageLayoutControl pageLayoutControl) { if (pageLayoutControl == null) { return; } IGraphicsContainer curGraph = pageLayoutControl.ActiveView as IGraphicsContainer; if (curGraph == null) { return; } curGraph.Reset(); IElement pElement = curGraph.Next(); while (pElement != null) { //不是MapFrame框架对象,则删除 if (!(pElement is IMapFrame)) { curGraph.DeleteElement(pElement); //必须重置,不然会叠加之前的元素 curGraph.Reset(); } pElement = curGraph.Next(); } pageLayoutControl.Refresh(); }
private void ClearElements(IActiveView pActiveView) { IGraphicsContainer graphicsContainer = pActiveView.GraphicsContainer; IMapFrame mapFrame = graphicsContainer.FindFrame(pActiveView.FocusMap) as IMapFrame; (mapFrame as IMapGrids).ClearMapGrids(); graphicsContainer.Reset(); IElement element = graphicsContainer.Next(); List <IElement> list = new List <IElement>(); while (element != null) { if (element != mapFrame) { list.Add(element); } element = graphicsContainer.Next(); } try { graphicsContainer.DeleteAllElements(); graphicsContainer.Reset(); element = graphicsContainer.Next(); if (element != null) { graphicsContainer.DeleteElement(element); } graphicsContainer.AddElement(mapFrame as IElement, -1); pActiveView.FocusMap = mapFrame.Map; } catch (Exception) { } }
private void timer1_Tick(object sender, System.EventArgs e) { //Distance used in calculating the new point location double dMaxDistance = m_MapControl.Extent.Width / 20; //Loop through the elements in the GraphicContainer and get the IElement interface m_GraphicsContainer.Reset(); IElement element = m_GraphicsContainer.Next(); Random r = new Random(); while (element != null) { //QI for IElementProperties interface from IElement interface IElementProperties elementProperties = (IElementProperties)element; //If agent has not been located if (elementProperties.Name == false.ToString()) { //Get hold of the IPoint interface from the elements geometry IPoint point = (IPoint)element.Geometry; //Create new random point coordinates based upon current location point.X = point.X - (dMaxDistance * (r.NextDouble() - 0.5)); point.Y = point.Y - (dMaxDistance * (r.NextDouble() - 0.5)); //Set the point onto the GeographicCoordinateSystem - WHERE the point came FROM point.Project(m_GeographicCoordinateSystem); if (point.IsEmpty == false) { //Ensure that the point is within the horizon of the coordinate system. Mollweide //has a generic rectangular horizon with the following limits: //-179.999988540844, -90.000000000000, 179.999988540844, 90.000000000000 if (point.X > 179.999988540844) { point.X = point.X - 359.999977081688; } else if (point.X < -179.999988540844) { point.X = point.X + 359.999977081688; } if (point.Y > 89.891975) //fudge value to clip near poles { point.Y = point.Y - 179.78395; } else if (point.Y < -89.891975) //fudge value to clip near poles { point.Y = point.Y + 179.78395; } //Project the point onto the displays current spatial reference //WHERE the point is going TO point.Project(m_ProjectedCoordinateSystem); element.Geometry = point; } } element = m_GraphicsContainer.Next(); } //Refresh the graphics m_MapControl.Refresh(esriViewDrawPhase.esriViewGraphics, Type.Missing, Type.Missing); }
private void method_9() { try { IGraphicsContainer graphicsContainer = base.m_pActiveView.GraphicsContainer; graphicsContainer.Reset(); IElement element = graphicsContainer.Next(); while (element != null) { IElementProperties properties = (IElementProperties)element; if (properties.Name == "TK") { goto Label_004A; } element = graphicsContainer.Next(); } return; Label_004A: graphicsContainer.DeleteElement(element); } catch (Exception exception) { MessageBox.Show(exception.Message); } }
public static IGeometry GetSearchGeometryFromGraphics(IGraphicsContainer graphics) { IGeometryCollection geometryBag = new GeometryBagClass(); IElement element; IGeometry geometry; graphics.Reset(); element = graphics.Next(); object before = Type.Missing; object after = Type.Missing; while (element != null) { geometry = element.Geometry; if (geometry is IPolygon) { geometryBag.AddGeometry(geometry, ref before, ref after); } element = graphics.Next(); } IGeometry searchGeometry = geometryBag as IGeometry; return(searchGeometry); }
//Checks the element names of the page layout //returns boolean true if duplicates exist public static Boolean checkLayoutTextElementsForDuplicates(IMxDocument pMxDoc, string pFrameName) { //create list to store name of text elements List <string> lst = new List <string>(); Boolean duplicates; //check if the frame passed exists in the map document if (PageLayoutProperties.detectMapFrame(pMxDoc, pFrameName)) { //Declare variables IPageLayout pLayout = pMxDoc.PageLayout; IGraphicsContainer pGraphics = pLayout as IGraphicsContainer; pGraphics.Reset(); IElement element = new TextElementClass(); IElementProperties2 pElementProp; ITextElement pTextElement; //loop through the text elements in the frame try { element = (IElement)pGraphics.Next(); while (element != null) { if (element is ITextElement) { pTextElement = element as ITextElement; pElementProp = element as IElementProperties2; //where the name is not blank //System.Diagnostics.Debug.WriteLine(pElementProp.Name); if (pElementProp.Name != "") { //store the name of the elements and the values in the dictionary as pairs lst.Add(pElementProp.Name); } } element = pGraphics.Next() as IElement; } } catch (Exception e) { System.Diagnostics.Debug.WriteLine("Error detecting duplicate elements from the map frame"); System.Diagnostics.Debug.WriteLine(e); } } //Find if duplicates exist int duplicateCount = lst.Count() - lst.Distinct().Count(); if (duplicateCount != 0) { duplicates = true; return(duplicates); } else { duplicates = false; return(duplicates); } }
private void simpleButton5_Click(object sender, EventArgs e) { bEditOrNot = true; int i = listView1.SelectedItems.Count; if (i == 0) { MessageBox.Show("请选择需要删除的记录", "用户提示"); return; } pGraphic.Reset(); string name = listView1.SelectedItems[0].SubItems[0].Text; IElement pElement = pGraphic.Next(); while (pElement != null) { IElementProperties pd = pElement as IElementProperties; if (pd.Name == name) { pGraphic.DeleteElement(pElement); } pElement = pGraphic.Next(); } axMapControl1.Refresh(); this.listView1.Items.Remove(this.listView1.SelectedItems[0]); for (int j = 0; j < listView1.Items.Count; j++) { listView1.Items[j].SubItems[0].Text = (j + 1).ToString(); } MessageBox.Show("删除成功,请保存更改!", "用户提示", MessageBoxButtons.OK , MessageBoxIcon.Asterisk); }
/// <summary> /// 替换原地图容器中的元素为模板的元素 /// </summary> /// <param name="tempGraph">模板</param> /// <param name="oldMapFrame">原地图容器</param> /// <returns></returns> private static IArray ReplaceOldIntoTempElement(IGraphicsContainer tempGraph, IMapFrame oldMapFrame) { tempGraph.Reset(); IElement tempElement = tempGraph.Next(); IArray pArray = new ArrayClass(); while (tempElement != null) { if (tempElement is IMapFrame) { //改变布局边框几何形状 IElement pMapFrameElement = oldMapFrame as IElement; if (pMapFrameElement != null) { pMapFrameElement.Geometry = tempElement.Geometry; } } else { IMapSurroundFrame pTempMapSurroundFrame = tempElement as IMapSurroundFrame; if (pTempMapSurroundFrame != null) { //设置地图框架 pTempMapSurroundFrame.MapFrame = oldMapFrame; } //获取图例指北针等元素 pArray.Add(tempElement); } tempElement = tempGraph.Next(); } return(pArray); }
private void ToolStripMenuItemQueryByGraphics_Click(object sender, EventArgs e) { try { //首先清空地图选择集,以进行后续的选择操作 axMapControl.Map.FeatureSelection.Clear(); //使用IGraphicsContainer接口获取地图中的各个图形(Graphics) IGraphicsContainer graphicsContainer = axMapControl.Map as IGraphicsContainer; //重置访问图形的游标,使IGraphicsContainer接口的Next()方法定位于地图中的第一个图形 graphicsContainer.Reset(); //使用IElement接口操作所获取第一个图形 IElement element = graphicsContainer.Next(); //获取图形的几何信息 IGeometry geometry = element.Geometry; //使用第一个图形的几何形状来选择地图中的要素。 axMapControl.Map.SelectByShape(geometry, null, false); //进行部分刷新以显示最新的选择集 axMapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, axMapControl.ActiveView.Extent); } catch (Exception ex) { //MessageBox.Show(ex.Message); } }
protected override void OnClick() { // // TODO: Sample code showing how to access button host // ArcMap.Application.CurrentTool = null; ElementListForm frm = new ElementListForm(); frm.AlignHandler = new AlignElementDelegate(AlignElementMethod); IGraphicsContainer cont = ArcMap.Document.ActiveView as IGraphicsContainer; cont.Reset(); IElement ele = cont.Next(); while (ele != null) { IElementProperties3 pros = ele as IElementProperties3; if (pros.Name != "") { frm.AddItem(pros.Name); } ele = cont.Next(); } frm.ShowDialog(); }
private void method_5(IActiveView iactiveView_0) { IGraphicsContainer graphicsContainer = iactiveView_0.GraphicsContainer; IMapFrame frame = graphicsContainer.FindFrame(iactiveView_0.FocusMap) as IMapFrame; graphicsContainer.Reset(); IElement item = graphicsContainer.Next(); List <IElement> list = new List <IElement>(); while (item != null) { if (item != frame) { list.Add(item); } item = graphicsContainer.Next(); } for (int i = 0; i < list.Count; i++) { try { graphicsContainer.DeleteElement(list[i]); } catch { } } }
public static IMapFrame FindFocusMapFrame(IPageLayout ipageLayout_0) { IActiveView view = ipageLayout_0 as IActiveView; IMap focusMap = view.FocusMap; IGraphicsContainer container = ipageLayout_0 as IGraphicsContainer; container.Reset(); for (IElement element = container.Next(); element != null; element = container.Next()) { if (element is IMapFrame) { if (focusMap == (element as IMapFrame).Map) { return(element as IMapFrame); } } else if (element is IGroupElement) { IMapFrame frame2 = FindFocusMapFrame(element as IGroupElement, focusMap); if (frame2 != null) { return(frame2); } } } return(null); }
internal IMapFrame GetFocusMapFrame(IPageLayout ipageLayout_0) { IMapFrame mapFrame; IGraphicsContainer ipageLayout0 = ipageLayout_0 as IGraphicsContainer; ipageLayout0.Reset(); IElement element = ipageLayout0.Next(); while (true) { if (element == null) { mapFrame = null; break; } else if (element is IMapFrame) { mapFrame = element as IMapFrame; break; } else { element = ipageLayout0.Next(); } } return(mapFrame); }
/// <summary> /// Method used to remove graphics from the graphics container /// Elements are tagged with a GUID on the IElementProperties.Name property /// </summary> /// <param name="gc">map graphics container</param> /// <param name="list">list of GUIDs to remove</param> internal void RemoveGraphics(IGraphicsContainer gc, List <string> list) { if (gc == null || !list.Any()) { return; } var elementList = new List <IElement>(); gc.Reset(); var element = gc.Next(); while (element != null) { var eleProps = element as IElementProperties; if (list.Contains(eleProps.Name)) { elementList.Add(element); } element = gc.Next(); } foreach (var ele in elementList) { gc.DeleteElement(ele); } list.Clear(); elementList.Clear(); RaisePropertyChanged(() => HasMapGraphics); }
private void method_4(IActiveView iactiveView_1, long long_0) { IOutputRasterSettings displayTransformation; if (iactiveView_1 is IMap) { displayTransformation = iactiveView_1.ScreenDisplay.DisplayTransformation as IOutputRasterSettings; displayTransformation.ResampleRatio = (int)long_0; } else if (iactiveView_1 is IPageLayout) { IMapFrame frame; IActiveView map; displayTransformation = iactiveView_1.ScreenDisplay.DisplayTransformation as IOutputRasterSettings; displayTransformation.ResampleRatio = (int)long_0; IGraphicsContainer container = iactiveView_1 as IGraphicsContainer; container.Reset(); for (IElement element = container.Next(); element != null; element = container.Next()) { if (element is IMapFrame) { frame = element as IMapFrame; map = frame.Map as IActiveView; displayTransformation = map.ScreenDisplay.DisplayTransformation as IOutputRasterSettings; displayTransformation.ResampleRatio = (int)long_0; } } frame = null; container = null; map = null; } displayTransformation = null; }
private void CopyMap(IMap fromCopyMap, IMap toCopyMap) { int num; toCopyMap.ClearLayers(); toCopyMap.DistanceUnits = fromCopyMap.DistanceUnits; toCopyMap.MapUnits = fromCopyMap.MapUnits; toCopyMap.SpatialReferenceLocked = false; toCopyMap.SpatialReference = fromCopyMap.SpatialReference; toCopyMap.Name = fromCopyMap.Name; for (num = fromCopyMap.LayerCount - 1; num >= 0; num--) { ILayer layer = fromCopyMap.get_Layer(num); toCopyMap.AddLayer(layer); } IGraphicsContainer container = fromCopyMap as IGraphicsContainer; container.Reset(); IElement element = container.Next(); int zorder = 0; while (element != null) { (toCopyMap as IGraphicsContainer).AddElement(element, zorder); zorder++; element = container.Next(); } ITableCollection tables = fromCopyMap as ITableCollection; for (num = 0; num < tables.TableCount; num++) { (toCopyMap as ITableCollection).AddTable(tables.get_Table(num)); } (toCopyMap as IActiveView).Extent = (fromCopyMap as IActiveView).Extent; }
private void method_1(IMap imap_0, IMap imap_1) { int num; imap_1.ClearLayers(); imap_1.DistanceUnits = imap_0.DistanceUnits; imap_1.MapUnits = imap_0.MapUnits; imap_1.SpatialReferenceLocked = false; imap_1.SpatialReference = imap_0.SpatialReference; imap_1.Name = imap_0.Name; for (num = imap_0.LayerCount - 1; num >= 0; num--) { ILayer layer = imap_0.get_Layer(num); imap_1.AddLayer(layer); } IGraphicsContainer container = imap_0 as IGraphicsContainer; container.Reset(); IElement element = container.Next(); int zorder = 0; while (element != null) { (imap_1 as IGraphicsContainer).AddElement(element, zorder); zorder++; element = container.Next(); } ITableCollection tables = imap_0 as ITableCollection; for (num = 0; num < tables.TableCount; num++) { (imap_1 as ITableCollection).AddTable(tables.get_Table(num)); } (imap_1 as IActiveView).Extent = (imap_0 as IActiveView).Extent; }
/// <summary> /// 获得图饰位置 /// </summary> void GetSurroundPose() { m_mapSurroundList = new List <MapSurroundEntity>(); IGraphicsContainer graphicsContainer = axPageLayoutControl1.PageLayout as IGraphicsContainer; IEnvelope mapEnvelop = (graphicsContainer.FindFrame(axPageLayoutControl1.ActiveView.FocusMap) as IElement).Geometry.Envelope; graphicsContainer.Reset(); IElement element = graphicsContainer.Next(); while (element != null) { if (element is IMapFrame) { element = graphicsContainer.Next(); continue; } else { IEnvelope envelop = element.Geometry.Envelope as IEnvelope; MapSurroundEntity mapSurroundEntity = new MapSurroundEntity(); mapSurroundEntity.left = envelop.XMin - mapEnvelop.XMin; mapSurroundEntity.right = mapEnvelop.XMax - envelop.XMax; mapSurroundEntity.top = mapEnvelop.YMax - envelop.YMax; mapSurroundEntity.bottom = envelop.YMin - mapEnvelop.YMin; mapSurroundEntity.width = envelop.Width; mapSurroundEntity.height = envelop.Height; mapSurroundEntity.element = element; m_mapSurroundList.Add(mapSurroundEntity); } element = graphicsContainer.Next(); } }
/// <summary> /// Clear Graphics /// </summary> internal void ClearGraphics() { try { IMxDocument mxDocument = ArcMap.Application.Document as IMxDocument; IActiveView activeView = mxDocument.ActiveView; IGraphicsContainer graphicsContainer = activeView.GraphicsContainer; //Pre fresh the Graphics Container activeView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); //Loop thro the Elements Clearing the Locator Graphics graphicsContainer.Reset(); for (IElement element = graphicsContainer.Next(); element != null; element = graphicsContainer.Next()) { IElementProperties elementProperties = element as IElementProperties; if (elementProperties.Name == LOCATOR_ELEMENT_NAME) { graphicsContainer.DeleteElement(element); } } this.CalloutAdded = false; } catch (Exception ex) { ShowError(ex); } }
/// <summary> /// Add the mapscale text to the Graphic Container. Places this text under the scale bar. /// </summary> /// <param name="sMapScale"></param> public override void addMapScaleText(string sMapScale) { CSpatialSubs oSpatialSubs = new CSpatialSubs(); IMxDocument pMxDoc = (IMxDocument)this.App.Document; IGraphicsContainer pGC = (IGraphicsContainer)pMxDoc.PageLayout; IMapSurroundFrame pMSFrame = null; IEnvelope pEnv = null; ITextSymbol pTextSym = null; ITextElement pTextElem = null; try { //Locate the scalebar in the graphics container because we //want to put the mapscale right under it. //A scalebar is contained within a MapSurroundFrame. pGC.Reset(); IElement pElem = pGC.Next(); while (pElem != null) { if (pElem is IMapSurroundFrame) { pMSFrame = (IMapSurroundFrame)pElem; if (pMSFrame.Object is IScaleBar) { break; // we got the scalebar } } pElem = pGC.Next(); } pEnv = new EnvelopeClass(); //get the envelope of the scalebar pElem.QueryBounds(pMxDoc.ActiveView.ScreenDisplay, pEnv); double xMin = SPrintConst.MapscaleText_XMin * base.XFactor; double xMax = SPrintConst.MapscaleText_XMax * base.XFactor; double yMax = pEnv.YMin - 0.02; //this is the min y value of the scalebar envelope - .02 double yMin = SPrintConst.MapscaleText_YMin * base.YFactor; //Set pMapscaleText symbol to the textsymbol pTextSym = oSpatialSubs.createTextSymbol(0, 0, 0, 7 * this.YFactor, esriTextHorizontalAlignment.esriTHALeft, esriTextVerticalAlignment.esriTVATop, "Arial"); pTextElem = oSpatialSubs.addTextToGraphicsContainer(pGC, pTextSym, xMin, xMax, yMin, yMax, sMapScale); } catch (Exception ex) { System.Windows.Forms.MessageBox.Show("Errors: CPortraitLayout:addMapScaleText()\r\n" + ex.Message, "Errors occurred", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error); } finally { oSpatialSubs.Dispose(); pMxDoc = null; pGC = null; pMSFrame = null; pEnv = null; pTextSym = null; pTextElem = null; } }
/// <summary> /// 删除地图容器中除了地图框架外的所有元素 /// </summary> /// <param name="curGraph">地图容器</param> private static void DeleteElement(IGraphicsContainer curGraph) { curGraph.Reset(); IElement pElement = curGraph.Next(); while (pElement != null) { //不是MapFrame对象,则删除 if (!(pElement is IMapFrame)) { curGraph.DeleteElement(pElement); //必须重置,不然会叠加之前的元素 curGraph.Reset(); } pElement = curGraph.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); } } }
public Collection GetMapFrameCollection(IPageLayout pPageLayout, string sMapClassifyName) { try { if (pPageLayout == null) { return(null); } IActiveView view = null; view = pPageLayout as IActiveView; if (view == null) { return(null); } IGraphicsContainer graphicsContainer = null; graphicsContainer = view.GraphicsContainer; if (graphicsContainer == null) { return(null); } graphicsContainer.Reset(); Collection pMapColl = null; pMapColl = new Collection(); IElement item = null; for (item = graphicsContainer.Next(); item != null; item = graphicsContainer.Next()) { if (item is IMapFrame) { IElementProperties properties = null; properties = item as IElementProperties; if (string.IsNullOrEmpty(sMapClassifyName)) { pMapColl.Add(item, "", null, null); } else if (Strings.LCase(Strings.Mid(Convert.ToString(properties.CustomProperty), 4)) == Strings.LCase(sMapClassifyName)) { pMapColl.Add(item, "", null, null); } } else if (item is IGroupElement) { this.GetMapFrameCollGroupRecursion(item as IGroupElement, sMapClassifyName, pMapColl); } } if (pMapColl.Count <= 0) { return(null); } return(pMapColl); } catch (Exception exception) { this.mErrOpt.ErrorOperate(this.mSubSysName, "FunFactory.ElementFun", "GetMapFrameCollection", exception.GetHashCode().ToString(), exception.Source, exception.Message, "", "", ""); return(null); } }
public IMapFrame GetMapFrameOverview(IPageLayout pPageLayout, string sMapName) { try { if (pPageLayout != null) { IActiveView view = null; view = pPageLayout as IActiveView; if (view == null) { return(null); } IGraphicsContainer graphicsContainer = null; graphicsContainer = view.GraphicsContainer; if (graphicsContainer == null) { return(null); } graphicsContainer.Reset(); IMapFrame frame = null; IElement element = null; for (element = graphicsContainer.Next(); element != null; element = graphicsContainer.Next()) { if (element is IMapFrame) { IElementProperties properties = null; properties = element as IElementProperties; if (Strings.LCase(Strings.Mid(Convert.ToString(properties.CustomProperty), 4)) == Strings.LCase("OverviewMap")) { frame = element as IMapFrame; if (string.IsNullOrEmpty(sMapName) | (frame.Map.Name == sMapName)) { return(frame); } } } else if (element is IGroupElement) { frame = this.GetMapFrameGroupRecursion(element as IGroupElement, "OverviewMap", sMapName); if (frame != null) { return(frame); } } } } return(null); } catch (Exception exception) { this.mErrOpt.ErrorOperate(this.mSubSysName, "FunFactory.ElementFun", "GetMapFrameOverview", exception.GetHashCode().ToString(), exception.Source, exception.Message, "", "", ""); return(null); } }
/// <summary> /// 删除指定名称的 Element 张琪 20110628 /// </summary> /// <param name="pScene"></param> /// <param name="sName"></param> public static void DeleteAllElementsWithName(IMap pMap, string sName) { try { IElement pElement; IGraphicsContainer pGCon = pMap.BasicGraphicsLayer as IGraphicsContainer; pGCon.Reset(); pElement = pGCon.Next() as IElement; while (pElement != null) { IElementProperties pElemProps = pElement as IElementProperties; if (pElemProps.Name == sName) { pGCon.DeleteElement(pElement); pGCon.Reset(); } pElement = pGCon.Next() as IElement; } } catch { } }
//Gets all the text elements and their values from a map frame. //returns a dictionary with key value pairs of these element / values public static Dictionary <string, string> getLayoutTextElements(IMxDocument pMxDoc, string pFrameName) { //create dictionary to story element values Dictionary <string, string> dict = new Dictionary <string, string>(); //check if the frame passed exists in the map document if (PageLayoutProperties.detectMapFrame(pMxDoc, pFrameName)) { //Declare variables IPageLayout pLayout = pMxDoc.PageLayout; IGraphicsContainer pGraphics = pLayout as IGraphicsContainer; pGraphics.Reset(); IElement element = new TextElementClass(); IElementProperties2 pElementProp; ITextElement pTextElement; //loop through the text elements in the frame try { element = (IElement)pGraphics.Next(); while (element != null) { if (element is ITextElement) { pTextElement = element as ITextElement; pElementProp = element as IElementProperties2; //where the name is not blank //System.Diagnostics.Debug.WriteLine(pElementProp.Name); if (pElementProp.Name != "") { //store the name of the elements and the values in the dictionary as pairs dict.Add(pElementProp.Name, pTextElement.Text); } } element = pGraphics.Next() as IElement; } //return the dictionary return(dict); } catch (Exception e) { System.Diagnostics.Debug.WriteLine("Error getting elements from the map frame"); System.Diagnostics.Debug.WriteLine(e); return(null); } } else { return(null); } }
/// <summary> /// Creates an <see cref="IEnumerable{T}" /> from an <see cref="IElement" /> /// </summary> /// <param name="source">An <see cref="IGraphicsContainer" /> to create an <see cref="IEnumerable{T}" /> from.</param> /// <returns>An <see cref="IEnumerable{T}" /> that contains the layers from the input source.</returns> public static IEnumerable <IElement> AsEnumerable(this IGraphicsContainer source) { if (source != null) { source.Reset(); IElement element = source.Next(); while (element != null) { yield return(element); element = source.Next(); } } }
internal static IMapFrame GetFocusMapFrame(IPageLayout pPageLayout) { IGraphicsContainer container = pPageLayout as IGraphicsContainer; container.Reset(); for (IElement element = container.Next(); element != null; element = container.Next()) { if (element is IMapFrame) { return(element as IMapFrame); } } return(null); }
/// <summary> /// Method used to remove graphics from the graphics container /// Elements are tagged with a GUID on the IElementProperties.Name property /// Removes graphics from all tabs, not just the tab that is currently active /// </summary> private void RemoveGraphics(IGraphicsContainer gc, bool removeOnlyTemporary) { if (gc == null || !GraphicsList.Any()) { return; } // keep track of the graphics that we need to remove from the GraphicsList List <Graphic> removedGraphics = new List <Graphic>(); var elementList = new List <IElement>(); gc.Reset(); var element = gc.Next(); while (element != null) { var eleProps = element as IElementProperties; foreach (Graphic graphic in GraphicsList) { if (graphic.UniqueId.Equals(eleProps.Name)) { if (graphic.IsTemp == removeOnlyTemporary) { elementList.Add(element); removedGraphics.Add(graphic); } break; } } element = gc.Next(); } foreach (var ele in elementList) { gc.DeleteElement(ele); } // clean up the GraphicsList and remove the necessary graphics from it foreach (Graphic graphic in removedGraphics) { GraphicsList.Remove(graphic); } elementList.Clear(); RaisePropertyChanged(() => HasMapGraphics); }
public static IGeometry GetSearchGeometryFromGraphics(IGraphicsContainer graphics) { IGeometryCollection geometryBag = new GeometryBagClass(); IElement element; IGeometry geometry; graphics.Reset(); element = graphics.Next(); object before = Type.Missing; object after = Type.Missing; while (element != null) { geometry = element.Geometry; if (geometry is IPolygon) geometryBag.AddGeometry(geometry, ref before, ref after); element = graphics.Next(); } IGeometry searchGeometry = geometryBag as IGeometry; return searchGeometry; }
/// <summary> /// Method used to remove graphics from the graphics container /// Elements are tagged with a GUID on the IElementProperties.Name property /// </summary> /// <param name="gc">map graphics container</param> /// <param name="list">list of GUIDs to remove</param> internal void RemoveGraphics(IGraphicsContainer gc, List<string> list) { if (gc == null || !list.Any()) return; var elementList = new List<IElement>(); gc.Reset(); var element = gc.Next(); while (element != null) { var eleProps = element as IElementProperties; if (list.Contains(eleProps.Name)) { elementList.Add(element); } element = gc.Next(); } foreach (var ele in elementList) { gc.DeleteElement(ele); } list.Clear(); elementList.Clear(); RaisePropertyChanged(() => HasMapGraphics); }
/// <summary> /// Method used to remove graphics from the graphics container /// Elements are tagged with a GUID on the IElementProperties.Name property /// Removes graphics from all tabs, not just the tab that is currently active /// </summary> private void RemoveGraphics(IGraphicsContainer gc, bool removeOnlyTemporary) { if (gc == null || !GraphicsList.Any()) return; // keep track of the graphics that we need to remove from the GraphicsList List<Graphic> removedGraphics = new List<Graphic>(); var elementList = new List<IElement>(); gc.Reset(); var element = gc.Next(); while (element != null) { var eleProps = element as IElementProperties; foreach (Graphic graphic in GraphicsList) { if (graphic.UniqueId.Equals(eleProps.Name)) { if (graphic.IsTemp == removeOnlyTemporary) { elementList.Add(element); removedGraphics.Add(graphic); } break; } } element = gc.Next(); } foreach (var ele in elementList) { gc.DeleteElement(ele); } // clean up the GraphicsList and remove the necessary graphics from it foreach (Graphic graphic in removedGraphics) { GraphicsList.Remove(graphic); } elementList.Clear(); RaisePropertyChanged(() => HasMapGraphics); }