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);
        }
예제 #2
0
        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;
        }
예제 #3
0
        /// <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);
        }
예제 #4
0
        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);
        }
예제 #5
0
        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);
        }
예제 #6
0
        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;
        }
예제 #7
0
        /// <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();
            }
        }
예제 #8
0
        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
                {
                }
            }
        }
예제 #9
0
        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;
        }
예제 #10
0
        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);
        }
예제 #11
0
        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)
            {
            }
        }
예제 #12
0
        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);
        }
예제 #13
0
        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);
            }
        }
예제 #14
0
        /// <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);
        }
예제 #15
0
        //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);
            }
        }
예제 #16
0
        /// <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();
        }
예제 #17
0
        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();
        }
예제 #18
0
        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);
        }
예제 #19
0
        /// <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;
            }
        }
예제 #20
0
        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);
                }
            }
        }
예제 #21
0
 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);
     }
 }
예제 #22
0
        //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);
            }
        }
예제 #23
0
        /// <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();
                }
            }
        }
예제 #24
0
        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);
        }
예제 #26
0
        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);
            }
        }
예제 #27
0
        //创建所有要素的轮廓线
        private void CreateAllElementFrame()
        {
            IGraphicsContainer pGraphicsContainer = m_hookHelper.ActiveView.GraphicsContainer;

            IElement pElement = pGraphicsContainer.Next();

            //IEnumElement pp =

            IMapSurroundFrame pMapsurroundFrame = new MapSurroundFrameClass();

            pMapsurroundFrame.MapSurround = pGraphicsContainer as IMapSurround;

            IFrameProperties pFrameProperties = pMapsurroundFrame as IFrameProperties;

            //边框的间距和圆角
            if (SymbolBorder != null)
            {
                if (this.txtBorderGap.Text != null)
                {
                    SymbolBorder.Gap = double.Parse(this.txtBorderGap.Text);
                }
                if (this.txtBorderAngle.Text != null)
                {
                    SymbolBorder.CornerRounding = short.Parse(this.txtBorderAngle.Text);
                }
            }
            if (SymbolBackground != null)
            {
                if (txtBackgroundGap.Text != null)
                {
                    SymbolBackground.Gap = double.Parse(this.txtBackgroundGap.Text);
                }
                if (txtBackgroundAngle.Text != null)
                {
                    SymbolBackground.CornerRounding = short.Parse(this.txtBackgroundAngle.Text);
                }
            }
            if (SymbolShadow != null)
            {
                if (txtShadowX.Text != null)
                {
                    SymbolShadow.HorizontalSpacing = double.Parse(this.txtShadowX.Text);
                }
                if (txtShadowY.Text != null)
                {
                    SymbolShadow.VerticalSpacing = double.Parse(this.txtShadowY.Text);
                }
                if (txtShadowAngle.Text != null)
                {
                    SymbolShadow.CornerRounding = short.Parse(this.txtShadowAngle.Text);
                }
            }
            //边框
            pFrameProperties.Border = SymbolBorder;

            //背景
            pFrameProperties.Background = SymbolBackground;
            //阴影
            pFrameProperties.Shadow = SymbolShadow;
        }
예제 #28
0
        /// <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);
            }
        }
예제 #29
0
        private void ClearElement(IActiveView actiview, string elementType)
        {
            IGraphicsContainer graphicsContainer = actiview.GraphicsContainer;

            graphicsContainer.Reset();
            IElement element = graphicsContainer.Next();

            while (element != null)
            {
                if (((IElementProperties)element).Name == elementType)
                {
                    graphicsContainer.DeleteElement(element);
                }
                element = graphicsContainer.Next();
            }
            actiview.Refresh();
        }
예제 #30
0
        private bool method_8()
        {
            bool flag = false;

            try
            {
                IGraphicsContainer graphicsContainer = base.m_pActiveView.GraphicsContainer;
                graphicsContainer.Reset();
                IElement  element  = graphicsContainer.Next();
                IEnvelope envelope = null;
                while (element != null)
                {
                    IElementProperties properties = (IElementProperties)element;
                    if (properties.Name == "TK")
                    {
                        goto Label_005D;
                    }
                    if (element is IMapFrame)
                    {
                        goto Label_009D;
                    }
                    element = graphicsContainer.Next();
                }
                return(flag);

Label_005D:
                envelope      = element.Geometry.Envelope;
                base.LeftLow  = envelope.LowerLeft;
                base.LeftUp   = envelope.UpperLeft;
                base.RightLow = envelope.LowerRight;
                base.RightUp  = envelope.UpperRight;
                return(true);

Label_009D:
                envelope      = element.Geometry.Envelope;
                base.LeftLow  = envelope.LowerLeft;
                base.LeftUp   = envelope.UpperLeft;
                base.RightLow = envelope.LowerRight;
                base.RightUp  = envelope.UpperRight;
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
		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
        /// 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);
        }
        /// <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);
        }