Esempio n. 1
0
        /// <summary>
        /// 文字比例尺
        /// </summary>
        /// <returns></returns>
        public bool AddTxtSacleBar()
        {
            IStyleSelector pStyleSelector = new ScaleTextSelectorClass();
            bool           m_bOK          = pStyleSelector.DoModal(0);

            if (m_bOK == true)
            {
                IScaleText pScaleText = pStyleSelector.GetStyle(0) as IScaleText;

                IEnvelope envelope = new EnvelopeClass();
                envelope.PutCoords(0.2, 0.2, 5, 1);
                ESRI.ArcGIS.esriSystem.IUID uid = new ESRI.ArcGIS.esriSystem.UIDClass();
                uid.Value = "esriCarto.Scaletext";
                IMap pMap = mainPage.ActiveView.FocusMap;
                IGraphicsContainer graphicsContainer = mainPage.ActiveView as IGraphicsContainer;
                IActiveView        activeView        = mainPage.ActiveView as IActiveView;
                IFrameElement      frameElement      = graphicsContainer.FindFrame(pMap);
                IMapFrame          mapFrame          = frameElement as IMapFrame;
                IMapSurroundFrame  mapSurroundFrame  = mapFrame.CreateSurroundFrame(uid as ESRI.ArcGIS.esriSystem.UID, null);
                IMapSurround       mapsurround       = pScaleText as IMapSurround;
                mapSurroundFrame.MapSurround = mapsurround;
                IElement element = mapSurroundFrame as IElement;
                element.Geometry = envelope;
                element.Activate(activeView.ScreenDisplay);
                graphicsContainer.AddElement(element, 0);
                IMapSurround mapSurround = mapSurroundFrame.MapSurround;
            }
            return(true);
        }
Esempio n. 2
0
        public static void AddNorthArrow(AxPageLayoutControl pageLayoutControl, IEnvelope envelope)
        {
            IUID uid = new UIDClass()
            {
                Value = "esriCarto.MarkerNorthArrow"
            };

            IFrameElement frameElement = (pageLayoutControl.PageLayout as IGraphicsContainer)
                                         .FindFrame(pageLayoutControl.ActiveView.FocusMap);
            IMapFrame         mapFrame         = frameElement as IMapFrame;
            IMapSurroundFrame mapSurroundFrame = mapFrame.CreateSurroundFrame(uid as UID, null); // Dynamic Cast
            IElement          element          = mapSurroundFrame as IElement;                   // Dynamic Cast

            element.Geometry = envelope;
            element.Activate(pageLayoutControl.ActiveView.ScreenDisplay);
            (pageLayoutControl.PageLayout as IGraphicsContainer).AddElement(element, 0);
            IMapSurround mapSurround = mapSurroundFrame.MapSurround;

            // Change out the default north arrow
            IMarkerNorthArrow      markerNorthArrow      = mapSurround as IMarkerNorthArrow;       // Dynamic Cast
            IMarkerSymbol          markerSymbol          = markerNorthArrow.MarkerSymbol;
            ICharacterMarkerSymbol characterMarkerSymbol = markerSymbol as ICharacterMarkerSymbol; // Dynamic Cast

            characterMarkerSymbol.CharacterIndex = 202;
            markerNorthArrow.MarkerSymbol        = characterMarkerSymbol;
        }
Esempio n. 3
0
        /// <summary>
        /// 添加图例或指北针——根据UID元素添加相应的元素
        /// </summary>
        /// <param name="uid"></param>
        private void AddElementInPageLayer(UID uid)
        {
            //提供对控制图形容器的成员的访问。
            IGraphicsContainer graphicsContainer = axPageLayoutControl1.PageLayout as IGraphicsContainer;
            //提供对成员的访问, 控制map元素的对象, IMapFrame是地图浏览栏对象的默认接口
            //通过FindFrame方法, 查找axPageLayoutControl1中屏幕包含指定对象的框架
            IMapFrame mapFrame = graphicsContainer.FindFrame(axPageLayoutControl1.ActiveView.FocusMap) as IMapFrame;
            //提供对成员的访问, 控制地图环绕元素映射的接口, 是附属物框架的对象的默认接口
            //通过CreateSurroundFrame方法创建基于当前地图框下的一个新地图环绕元素(如图例、指北针)
            IMapSurroundFrame mapSurroundFrame = mapFrame.CreateSurroundFrame(uid, null);
            //IElement是所有图形元素和框架元素类都要实现的接口
            //将mapSurroundFrame强转成IElement类型
            IElement element = mapSurroundFrame as IElement;
            //实例化一个包络线
            IEnvelope envelope = new EnvelopeClass();

            //设定坐标
            envelope.PutCoords(1, 1, 2, 2);
            //设置元素中的几何形状
            element.Geometry = envelope;
            try
            {
                //提供对控制图例的成员的访问。
                ILegend legend = (ILegend)mapSurroundFrame.MapSurround;
                legend.Title = "图例";
            }
            catch
            { }
            graphicsContainer.AddElement(element, 0);
            //设置元素将在axPageLayoutControl屏幕上显示图形
            element.Activate(axPageLayoutControl1.ActiveView.ScreenDisplay);
            //部分刷新
            axPageLayoutControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
        }
        private void AddGraphicToDisplay(IElement elem, IAGAnimationContainer animContainer)
        {
            IActiveView        view = animContainer.CurrentView as IActiveView;
            IGraphicsContainer graphicsContainer = view as IGraphicsContainer;

            graphicsContainer.AddElement(elem, 0);
            elem.Activate(view.ScreenDisplay);
        }
Esempio n. 5
0
        /// <summary>
        /// Adds a Call Out
        /// </summary>
        /// <param name="point"></param>
        /// <param name="LocatorDescription"></param>
        private void AddCallout(ESRI.ArcGIS.Geometry.Point point, String LocatorDescription)
        {
            try
            {
                IMxDocument mxDocument = ArcMap.Application.Document as IMxDocument;
                try
                {
                    //Register if not already registered
                    IActiveViewEvents_Event check = mxDocument.ActiveView as IActiveViewEvents_Event;
                    if (check != this.activeViewEvents)
                    {
                        this.activeViewEvents       = mxDocument.ActiveView as IActiveViewEvents_Event;
                        activeViewEvents.AfterDraw -= AfterDrawEventHandler;
                        activeViewEvents.AfterDraw += AfterDrawEventHandler;
                    }
                }
                catch (Exception)
                {
                }

                IMap        map        = mxDocument.FocusMap;
                IActiveView activeView = mxDocument.ActiveView;
                this.CurrentEnvelope = activeView.Extent;
                IFormattedTextSymbol formattedTextSymbol = new TextSymbolClass();
                ICallout             callout             = new BalloonCalloutClass();

                (callout as IBalloonCallout).Style = esriBalloonCalloutStyle.esriBCSRoundedRectangle;
                formattedTextSymbol.Background     = callout as ITextBackground;
                callout.AnchorPoint     = point;
                callout.LeaderTolerance = 0.0;

                ITextElement textElement = new TextElementClass();
                string       CalloutText = LocatorDescription.Replace("|LOCATOR_SEPARATOR|", System.Environment.NewLine);
                textElement.Text = CalloutText;
                IElement textElementAsElement = textElement as IElement;
                IPoint   textPoint            = (point as IClone).Clone() as IPoint;
                textPoint.PutCoords(point.X - (activeView.Extent.Width / 30), point.Y + (activeView.Extent.Width / 30));
                textElementAsElement.Geometry = textPoint;

                //Apply the properties
                textElement.Symbol = formattedTextSymbol;
                (textElement as IElementProperties).Name = LOCATOR_ELEMENT_NAME;

                //Add the Element to the view
                IGraphicsContainer graphicsContainer = map as IGraphicsContainer;
                graphicsContainer.AddElement(textElement as IElement, 0);
                textElementAsElement.Activate(activeView.ScreenDisplay);

                activeView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
                this.CalloutAdded = true;
            }
            catch (Exception ex)
            {
                ShowError(ex);
            }
        }
        private void AddCallout(IPoint CurrentPos, string p)
        {
            BetterMarker marker  = new BetterMarker(CurrentPos, p, mMap.MapScale);
            IElement     element = marker.MarkerElement;

            graphicsContainer.AddElement(element, 0);
            element.Activate(mDoc.ActiveView.ScreenDisplay);

            mMarkers.Add(marker);

            mDoc.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, element, null);

            mMap.ClearSelection();
        }
Esempio n. 7
0
        /// <summary>
        /// Adds a point
        /// </summary>
        /// <param name="x">The X Coordinate</param>
        /// <param name="y">The y Coordinate</param>
        /// <param name="coordinateSystem">The coordinate system.</param>
        /// <param name="description">The description.</param>
        /// <param name="minX">The extent min X.</param>
        /// <param name="minY">The extent min Y.</param>
        /// <param name="maxX">The extent max X.</param>
        /// <param name="maxY">The extent max Y.</param>
        private void AddPoint(Double x, Double y, int coordinateSystem, String description, Double minX, Double minY, Double maxX, Double maxY)
        {
            try
            {
                //get mapdocument
                IMxDocument mxDocument = ArcMap.Application.Document as IMxDocument;
                //get map
                IMap map = mxDocument.FocusMap;
                //get the active view
                IActiveView activeView = mxDocument.ActiveView;

                //get the point from the matched record
                ESRI.ArcGIS.Geometry.Point point = CreatePoint(x, y, coordinateSystem, map.SpatialReference);

                //create a simple marker and set attributes
                ISimpleMarkerSymbol simpleMarkerSymbol = new SimpleMarkerSymbolClass();
                simpleMarkerSymbol.Size  = 10;
                simpleMarkerSymbol.Style = esriSimpleMarkerStyle.esriSMSDiamond;
                IRgbColor color = new RgbColorClass();
                color.Red   = Color.Blue.R;
                color.Green = Color.Blue.G;
                color.Blue  = Color.Blue.B;
                simpleMarkerSymbol.Color = color;

                //Create the Grapthics Element
                IMarkerElement markerElement = new MarkerElementClass();
                markerElement.Symbol = simpleMarkerSymbol as IMarkerSymbol;
                IElement markerElementAsElement = markerElement as IElement;
                markerElementAsElement.Geometry = point;
                IElementProperties markerElementAsElementProperties = markerElement as IElementProperties;
                markerElementAsElementProperties.Name = LOCATOR_ELEMENT_NAME;

                //Add the Element to the view
                IGraphicsContainer graphicsContainer = map as IGraphicsContainer;
                graphicsContainer.AddElement(markerElementAsElement as IElement, 0);
                markerElementAsElement.Activate(activeView.ScreenDisplay);
                activeView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);

                //Add the callout box
                AddCallout(point, description);

                //move to location
                MoveToLocation(point, map, coordinateSystem, minX, minY, maxX, maxY);
            }
            catch (Exception ex)
            {
                ShowError(ex);
            }
        }
Esempio n. 8
0
 public void add(string value, double xmin, double ymin, double xmax, double ymax)
 {
     uid       = new UID();
     uid.Value = value;
     envelope  = new Envelope() as IEnvelope;
     envelope.PutCoords(xmin, ymin, xmax, ymax);
     graphicsContainer = pageLayoutControl.PageLayout as IGraphicsContainer;
     mapFrame          = graphicsContainer.FindFrame(pageLayoutControl.ActiveView.FocusMap) as IMapFrame;
     mapSurroundFrame  = mapFrame.CreateSurroundFrame(uid, null);
     element           = mapSurroundFrame as IElement;
     element.Geometry  = envelope;
     element.Activate(pageLayoutControl.ActiveView.ScreenDisplay);
     trackCancel = new CancelTracker();
     element.Draw(pageLayoutControl.ActiveView.ScreenDisplay, trackCancel);
     graphicsContainer.AddElement(element, 0);
 }
        void mActiveViewEvents_AfterDraw(IDisplay Display, esriViewDrawPhase phase)
        {
            if (phase != esriViewDrawPhase.esriViewGraphics)
            {
                graphicsContainer.DeleteAllElements();


                foreach (BetterMarker marker in mMarkers)
                {
                    marker.Update(this.mMap.MapScale);
                    IElement element = marker.MarkerElement;
                    graphicsContainer.AddElement(element, 0);
                    element.Activate(mDoc.ActiveView.ScreenDisplay);

                    mDoc.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, element, null);
                }
            }
        }
        private static IElement CreateFillElement(IGeometry pGeometry, ISimpleFillSymbol pFillSym)
        {
            IFillShapeElement pFillEle = new RectangleElementClass();

            pFillEle.Symbol = pFillSym;
            IElement pElement = pFillEle as IElement;

            pElement.Geometry = pGeometry;

            IScreenDisplay pScrDisp = ArcMap.Document.ActiveView.ScreenDisplay;

            pElement.Activate(pScrDisp);

            pScrDisp.StartDrawing(0, (System.Int16)esriScreenCache.esriNoScreenCache);
            pElement.Draw(pScrDisp, null);
            pScrDisp.FinishDrawing();

            return(pElement);
        }
        protected override void OnMouseUp(MouseEventArgs Args)
        {
            //when mouse comes up, end the new envelope and pass it to feedbackEnv.
            feedbackEnv = NewEnvelopeFeedback.Stop();

            //initialize a new RectangleElementClass
            feedbackElement = new RectangleElementClass();

            //pass the new rectangle element, the geometry defined by our feedback object
            feedbackElement.Geometry = feedbackEnv;

            //make sure the element is activated in the current view
            feedbackElement.Activate(feedbackScreenDisplay);

            //now add the newly created element to the ActiveView with default symbology.
            ArcMap.Document.ActiveView.GraphicsContainer.AddElement(feedbackElement, 0);

            //and refresh the view so we can see the changes.
            ArcMap.Document.ActiveView.Refresh();
        }
Esempio n. 12
0
        public void AddNorthArrow(IPageLayout pageLayout, IMap map, double posX, double posY, double division)
        {
            try
            {
                if (pageLayout == null || map == null)
                {
                    return;
                }

                IEnvelope envelope = new EnvelopeClass();
                envelope.PutCoords(posX - division, posY - division, posX, posY); //  Specify the location and size of the north arrow

                ESRI.ArcGIS.esriSystem.IUID uid = new ESRI.ArcGIS.esriSystem.UIDClass();
                uid.Value = "esriCarto.MarkerNorthArrow";

                // Create a Surround. Set the geometry of the MapSurroundFrame to give it a location
                // Activate it and add it to the PageLayout's graphics container
                IGraphicsContainer graphicsContainer = pageLayout as IGraphicsContainer;                                      // Dynamic Cast
                IActiveView        activeView        = pageLayout as IActiveView;                                             // Dynamic Cast
                IFrameElement      frameElement      = graphicsContainer.FindFrame(map);
                IMapFrame          mapFrame          = frameElement as IMapFrame;                                             // Dynamic Cast
                IMapSurroundFrame  mapSurroundFrame  = mapFrame.CreateSurroundFrame(uid as ESRI.ArcGIS.esriSystem.UID, null); // Dynamic Cast
                IElement           element           = mapSurroundFrame as IElement;                                          // Dynamic Cast
                element.Geometry = envelope;
                element.Activate(activeView.ScreenDisplay);
                graphicsContainer.AddElement(element, 0);
                IMapSurround mapSurround = mapSurroundFrame.MapSurround;

                // Change out the default north arrow
                IMarkerNorthArrow      markerNorthArrow      = mapSurround as IMarkerNorthArrow;       // Dynamic Cast
                IMarkerSymbol          markerSymbol          = markerNorthArrow.MarkerSymbol;
                ICharacterMarkerSymbol characterMarkerSymbol = markerSymbol as ICharacterMarkerSymbol; // Dynamic Cast
                characterMarkerSymbol.CharacterIndex = 174;                                            // change the symbol for the North Arrow
                markerNorthArrow.MarkerSymbol        = characterMarkerSymbol;
            }
            catch (Exception ex)
            {
                frmErrorLog pfrmErrorLog = new frmErrorLog(); pfrmErrorLog.ex = ex; pfrmErrorLog.ShowDialog();
                return;
            }
        }
Esempio n. 13
0
        public static void AddScalebar(AxPageLayoutControl pageLayoutControl, IEnvelope envelope)
        {
            IUID uid = new UIDClass()
            {
                Value = "esriCarto.AlternatingScaleBar"
            };

            IFrameElement frameElement = (pageLayoutControl.PageLayout as IGraphicsContainer)
                                         .FindFrame(pageLayoutControl.ActiveView.FocusMap);
            IMapFrame         mapFrame         = frameElement as IMapFrame;
            IMapSurroundFrame mapSurroundFrame = mapFrame.CreateSurroundFrame(uid as UID, null); // Dynamic Cast
            IElement          element          = mapSurroundFrame as IElement;                   // Dynamic Cast

            element.Geometry = envelope;
            element.Activate(pageLayoutControl.ActiveView.ScreenDisplay);
            (pageLayoutControl.PageLayout as IGraphicsContainer).AddElement(element, 0);
            IMapSurround mapSurround = mapSurroundFrame.MapSurround;

            IScaleBar markerScaleBar = (IScaleBar)(mapSurround);

            markerScaleBar.LabelPosition = esriVertPosEnum.esriBelow;
            markerScaleBar.UseMapSettings();
        }
Esempio n. 14
0
        public void AddScalebar(IPageLayout pageLayout, IMap map, double posX, double posY, double division, string strMapUnits, short srtDivisions)
        {
            try
            {
                if (pageLayout == null || map == null)
                {
                    return;
                }

                IEnvelope envelope = new EnvelopeClass();
                envelope.PutCoords(posX - (division * 2), posY, posX, posY + (division * 0.5)); // Specify the location and size of the scalebar
                ESRI.ArcGIS.esriSystem.IUID uid = new ESRI.ArcGIS.esriSystem.UIDClass();
                uid.Value = "esriCarto.AlternatingScaleBar";

                // Create a Surround. Set the geometry of the MapSurroundFrame to give it a location
                // Activate it and add it to the PageLayout's graphics container
                IGraphicsContainer graphicsContainer = pageLayout as IGraphicsContainer;                                      // Dynamic Cast
                IActiveView        activeView        = pageLayout as IActiveView;                                             // Dynamic Cast
                IFrameElement      frameElement      = graphicsContainer.FindFrame(map);
                IMapFrame          mapFrame          = frameElement as IMapFrame;                                             // Dynamic Cast
                IMapSurroundFrame  mapSurroundFrame  = mapFrame.CreateSurroundFrame(uid as ESRI.ArcGIS.esriSystem.UID, null); // Dynamic Cast
                IElement           element           = mapSurroundFrame as IElement;                                          // Dynamic Cast
                element.Geometry = envelope;
                element.Activate(activeView.ScreenDisplay);
                graphicsContainer.AddElement(element, 0);
                IMapSurround mapSurround = mapSurroundFrame.MapSurround;


                IScaleBar markerScaleBar = ((IScaleBar)(mapSurround));
                markerScaleBar.LabelPosition = esriVertPosEnum.esriBelow;
                markerScaleBar.UseMapSettings();
                markerScaleBar.Divisions           = srtDivisions;
                markerScaleBar.DivisionsBeforeZero = 0;
                markerScaleBar.Subdivisions        = 0;
                markerScaleBar.LabelFrequency      = esriScaleBarFrequency.esriScaleBarMajorDivisions;

                if (strMapUnits == "Feet")
                {
                    markerScaleBar.Units = ESRI.ArcGIS.esriSystem.esriUnits.esriFeet;
                }
                //Default Settings
                else if (strMapUnits == "Miles")
                {
                    markerScaleBar.Units = ESRI.ArcGIS.esriSystem.esriUnits.esriMiles;
                }
                else if (strMapUnits == "Meters")
                {
                    markerScaleBar.Units = ESRI.ArcGIS.esriSystem.esriUnits.esriMeters;
                }
                else if (strMapUnits == "Kilometers")
                {
                    markerScaleBar.Units = ESRI.ArcGIS.esriSystem.esriUnits.esriKilometers;
                }
                else
                {
                    return;
                }
            }
            catch (Exception ex)
            {
                frmErrorLog pfrmErrorLog = new frmErrorLog(); pfrmErrorLog.ex = ex; pfrmErrorLog.ShowDialog();
                return;
            }
        }
 private void AddGraphicToDisplay(IElement elem, IAGAnimationContainer animContainer)
 {
     IActiveView view = animContainer.CurrentView as IActiveView;
     IGraphicsContainer graphicsContainer = view as IGraphicsContainer;
     graphicsContainer.AddElement(elem, 0);            
     elem.Activate(view.ScreenDisplay);
 }
    protected override void OnMouseUp(MouseEventArgs Args)
    {
      //when mouse comes up, end the new envelope and pass it to feedbackEnv.
      feedbackEnv = NewEnvelopeFeedback.Stop();

      //initialize a new RectangleElementClass
      feedbackElement = new RectangleElementClass();

      //pass the new rectangle element, the geometry defined by our feedback object
      feedbackElement.Geometry = feedbackEnv;

      //make sure the element is activated in the current view
      feedbackElement.Activate(feedbackScreenDisplay);

      //now add the newly created element to the ActiveView with default symbology.
      ArcMap.Document.ActiveView.GraphicsContainer.AddElement(feedbackElement, 0);

      //and refresh the view so we can see the changes.
      ArcMap.Document.ActiveView.Refresh();
    }