Example #1
0
        private void AddPolyline(GraphicElement graphicElement, MilSpaceGraphicsTypeEnum graphicsType, bool doRefresh = false, bool persist = false)
        {
            IPolyline    profileLine = graphicElement.Source;
            ILineElement lineElement = new LineElementClass();

            var curList = allGraphics[graphicsType];

            bool exists = curList.Any(ge => ge.ProfileId == graphicElement.ProfileId && ge.ElementId == graphicElement.ElementId);

            if (!persist && exists)
            {
                return;
            }

            lineElement.Symbol = DefineProfileLineSymbol(graphicsType);
            IElement elem = (IElement)lineElement;

            elem.Geometry          = profileLine;
            graphicElement.Element = elem;

            DeleteGraphicsElement(graphicElement);

            graphics.AddElement(elem, 0);


            if (!exists)
            {
                curList.Add(graphicElement);
            }

            if (doRefresh)
            {
                activeView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
            }
        }
Example #2
0
        private bool CheckElementOnGraphics(GraphicElement milSpaceElement)
        {
            if (milSpaceElement == null)
            {
                return(false);
            }

            graphics.Reset();
            IElement ge     = graphics.Next();
            bool     result = false;

            while (ge != null)
            {
                //if (ge is ILineElement line)
                //{
                //    var smbl = line.Symbol;
                //}
                if (ge.Equals(milSpaceElement.Element))
                {
                    result = true;
                    break;
                }
                ge = graphics.Next();
            }
            graphics.Reset();

            return(result);
        }
Example #3
0
        private void UpdateGraphicLine(GroupedLines groupedLines, int profileId,
                                       MilSpaceGraphicsTypeEnum graphicsType, bool selectionRemove = false)
        {
            RemoveLineFromSessionGraphicsByLineId(profileId, groupedLines.LineId, graphicsType);

            int elementId  = 0;
            int lineNumber = 0;
            int width;

            if (selectionRemove)
            {
                width = 2;
            }
            else
            {
                width = (groupedLines.IsSelected) ? 4 : 2;
            }

            foreach (var line in groupedLines.Polylines)
            {
                var ge = new GraphicElement()
                {
                    Source    = line,
                    ElementId = ++elementId,
                    ProfileId = profileId,
                    LineId    = groupedLines.LineId
                };

                var color = (groupedLines.Lines[lineNumber].Visible) ? groupedLines.VisibleColor
                                                                     : groupedLines.InvisibleColor;

                var pointFrom = groupedLines.Lines[lineNumber].PointFrom;
                var isVertex  = groupedLines.IsPrimitive && groupedLines.Vertices.Exists(point => point.X == pointFrom.X && point.Y == pointFrom.Y);

                LineType lineType;

                if (groupedLines.Lines.Count() == 1)
                {
                    lineType = LineType.DefaultLine;
                }
                else if (groupedLines.Lines.First() == groupedLines.Lines[lineNumber])
                {
                    lineType = LineType.Point;
                }
                else if (groupedLines.Lines.Last() == groupedLines.Lines[lineNumber])
                {
                    lineType = (!isVertex) ? LineType.Arrow : LineType.DefaultLine;
                }
                else
                {
                    lineType = (!isVertex) ? LineType.Line : LineType.Point;
                }

                AddPolyline(ge, graphicsType, color, lineType, false, false, width);

                lineNumber++;
            }

            activeView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
        }
Example #4
0
        public void AddObservPointsGraphicsToMap(IPolygon coverageArea, string areaName)
        {
            if ((coverageArea == null) || (coverageArea.SpatialReference == null))
            {
                return;
            }

            ISimpleFillSymbol simplePolygonSymbol = new SimpleFillSymbolClass();
            var color = (IRgbColor) new RgbColorClass()
            {
                Red = 255, Green = 253, Blue = 3
            };

            simplePolygonSymbol.Color = color;
            simplePolygonSymbol.Style = esriSimpleFillStyle.esriSFSHollow;

            ILineSymbol polygonOutline = new SimpleLineSymbol
            {
                Color = color,
                Width = 2
            };

            simplePolygonSymbol.Outline = polygonOutline;

            IFillShapeElement markerElement = new PolygonElementClass
            {
                Symbol = simplePolygonSymbol
            };

            IElement element = null;

            element = (IElement)markerElement;

            if (element == null)
            {
                return;
            }
            element.Geometry = coverageArea;
            element.Geometry.SpatialReference = activeView.FocusMap.SpatialReference;

            var eprop = (IElementProperties)element;

            eprop.Name = areaName;

            var ge = new GraphicElement()
            {
                Source = coverageArea, Name = eprop.Name, Element = element
            };

            if (allGraphics[MilSpaceGraphicsTypeEnum.Visibility].Exists(el => el.Name == eprop.Name))
            {
                DeleteGraphicsElement(ge, true, true);
            }

            graphics.AddElement(element, 0);
            allGraphics[MilSpaceGraphicsTypeEnum.Visibility].Add(ge);

            activeView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
        }
Example #5
0
        public void DrawText(IPoint point, string text, string textName, MilSpaceGraphicsTypeEnum graphicsType, IColor textColor = null, int size = 12, int distance = 5)
        {
            var units     = GetLengthInMapUnits(activeView, distance);
            var textPoint = new Point()
            {
                X = point.X + units, Y = point.Y + units, SpatialReference = point.SpatialReference
            };

            if (textColor == null)
            {
                textColor = new RgbColorClass()
                {
                    Red = 255
                };
            }

            ITextElement textElement = new TextElementClass
            {
                Text = text
            };

            var textSymbol = new TextSymbol
            {
                Color = textColor,
                Size  = size
            };

            textElement.Symbol = textSymbol;
            IElement textElementEl = (IElement)textElement;

            textElementEl.Geometry = textPoint;

            var textPropr = (IElementProperties)textElementEl;

            textPropr.Name = textName;

            if (graphicsType == MilSpaceGraphicsTypeEnum.GeoCalculator)
            {
                textPropr.Name += geoCalcPointsSuffix;
            }

            var ge = new GraphicElement()
            {
                Source = textPoint, Name = textPropr.Name, Element = textElementEl
            };

            if (allGraphics[graphicsType].Exists(el => el.Name == textPropr.Name))
            {
                DeleteGraphicsElement(ge, true, true);
            }

            allGraphics[graphicsType].Add(ge);

            graphics.AddElement(textElementEl, 0);

            activeView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
        }
Example #6
0
        public void AddObservPointsRelationLineToMap(IPolyline polyline, IRgbColor color, string name, string title)
        {
            var ge = new GraphicElement()
            {
                Source = polyline, Name = name
            };

            AddPolyline(ge, MilSpaceGraphicsTypeEnum.Visibility, color, LineType.DefaultLine, true, true);

            DrawText(polyline.ToPoint.Clone(), title, $"text_{name}", MilSpaceGraphicsTypeEnum.Visibility, color);
        }
Example #7
0
 private void DeleteGraphicsElement(GraphicElement milSpaceElement, bool doRefresh = false)
 {
     if (CheckElementOnGraphics(milSpaceElement))
     {
         graphics.DeleteElement(milSpaceElement.Element);
         if (doRefresh)
         {
             activeView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
         }
     }
 }
Example #8
0
        private void AddPolyline(GraphicElement graphicElement, MilSpaceGraphicsTypeEnum graphicsType,
                                 IRgbColor color = null, LineType lineType = LineType.DefaultLine, bool doRefresh = false,
                                 bool persist    = false, int width        = 2)
        {
            IPolyline    profileLine = graphicElement.Source;
            ILineElement lineElement = new LineElementClass();

            var curList = allGraphics[graphicsType];

            bool exists = curList.Any(ge => ge.ProfileId == graphicElement.ProfileId &&
                                      ge.ElementId == graphicElement.ElementId &&
                                      ge.LineId == graphicElement.LineId);

            if (!persist && exists)
            {
                return;
            }

            if (color == null)
            {
                color = grapchucsTypeColors[graphicsType]();
            }

            if (lineType == LineType.Line)
            {
                lineElement.Symbol = DefineProfileLineSymbol(graphicsType, color, width);
            }
            else
            {
                lineElement.Symbol = DefineProfileDecorationLineSymbol(graphicsType, color, width, lineType);
            }

            IElement elem = (IElement)lineElement;

            elem.Geometry          = profileLine;
            graphicElement.Element = elem;

            DeleteGraphicsElement(graphicElement);

            graphics.AddElement(elem, 0);


            if (!exists)
            {
                curList.Add(graphicElement);
            }

            if (doRefresh)
            {
                activeView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
            }
        }
Example #9
0
        public void AddLineSegmentToMap(IPoint pointFrom, IPoint pointTo, string name, string fromPointGuid)
        {
            var color = (IRgbColor) new RgbColorClass()
            {
                Green = 255
            };
            var polyline    = EsriTools.CreatePolylineFromPoints(pointFrom, pointTo);
            var segmentName = name + "_" + fromPointGuid + geoCalcPointsSuffix;
            var ge          = new GraphicElement()
            {
                Source = polyline, Name = segmentName
            };

            AddPolyline(ge, MilSpaceGraphicsTypeEnum.GeoCalculator, color, LineType.Line, true, true);
        }
Example #10
0
        private void DeleteGraphicsElement(GraphicElement milSpaceElement, bool doRefresh = false, bool removeFromList = false)
        {
            if (CheckElementOnGraphics(milSpaceElement))
            {
                graphics.DeleteElement(milSpaceElement.Element);
                if (doRefresh)
                {
                    activeView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
                }

                if (removeFromList)
                {
                    allGraphics[MilSpaceGraphicsTypeEnum.GeoCalculator].Remove(milSpaceElement);
                }
            }
        }
Example #11
0
        private void UpdateGraphic(IEnumerable <IPolyline> profileLines, int profileId, int profileTypeId, MilSpaceGraphicsTypeEnum graphicsType)
        {
            EmptyProfileGraphics(graphicsType);

            int elementId = profileTypeId;

            foreach (var line in profileLines)
            {
                var ge = new GraphicElement()
                {
                    Source = line, ElementId = ++elementId, ProfileId = profileId
                };
                AddPolyline(ge, graphicsType);
            }

            activeView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
        }
Example #12
0
        private void AddLinesToGraphics(IEnumerable <IPolyline> profileLines, int profileId, MilSpaceGraphicsTypeEnum graphicsType)
        {
            var curList = allGraphics[graphicsType];

            int elementId = 0;

            foreach (var line in profileLines)
            {
                elementId++;
                var graphic = curList.FirstOrDefault(g => g.ProfileId == profileId && g.ElementId == elementId);
                if (graphic != null)
                {
                    DeleteGraphicsElement(graphic);
                    curList.Remove(graphic);
                }

                var ge = new GraphicElement()
                {
                    Source = line, ElementId = elementId, ProfileId = profileId
                };
                AddPolyline(ge, graphicsType);
            }
            activeView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
        }
Example #13
0
        private bool CheckElementOnGraphics(GraphicElement milSpaceElement)
        {
            if (milSpaceElement == null)
            {
                return(false);
            }

            graphics.Reset();
            IElement ge     = graphics.Next();
            bool     result = false;

            while (ge != null)
            {
                if (ge.Equals(milSpaceElement.Element))
                {
                    result = true;
                    break;
                }
                ge = graphics.Next();
            }
            graphics.Reset();

            return(result);
        }
Example #14
0
        private void AddLinesToGraphics(IEnumerable <IPolyline> profileLines, int profileId,
                                        MilSpaceGraphicsTypeEnum graphicsType, GroupedLines profileColorLines = null)
        {
            var curList    = allGraphics[graphicsType];
            int elementId  = 0;
            var lineNumber = 0;
            int width      = 2;

            if (profileColorLines != null)
            {
                RemoveLineFromSessionGraphicsByLineId(profileId, profileColorLines.LineId, graphicsType);
                width = (profileColorLines.IsSelected) ? 4 : 2;
            }

            foreach (var line in profileLines)
            {
                elementId++;

                if (profileColorLines != null)
                {
                    var ge = new GraphicElement()
                    {
                        Source = line, ElementId = elementId, ProfileId = profileId, LineId = profileColorLines.LineId
                    };
                    var color = (profileColorLines.Lines[lineNumber].Visible) ? profileColorLines.VisibleColor
                                                                              : profileColorLines.InvisibleColor;
                    var pointFrom = profileColorLines.Lines[lineNumber].PointFrom;
                    var isVertex  = profileColorLines.IsPrimitive && profileColorLines.Vertices.Exists(point => point.X == pointFrom.X && point.Y == pointFrom.Y);

                    LineType lineType;

                    if (profileColorLines.Lines.Count() == 1)
                    {
                        lineType = LineType.DefaultLine;
                    }
                    else if (profileColorLines.Lines.First() == profileColorLines.Lines[lineNumber])
                    {
                        lineType = LineType.Point;
                    }
                    else if (profileColorLines.Lines.Last() == profileColorLines.Lines[lineNumber])
                    {
                        lineType = (!isVertex) ? LineType.Arrow: LineType.DefaultLine;
                    }
                    else
                    {
                        lineType = (!isVertex) ? LineType.Line : LineType.Point;
                    }


                    AddPolyline(ge, graphicsType, color, lineType, false, false, width);

                    lineNumber++;
                }
                else
                {
                    var graphic = curList.FirstOrDefault(g => g.ProfileId == profileId && g.ElementId == elementId);
                    if (graphic != null)
                    {
                        DeleteGraphicsElement(graphic);
                        curList.Remove(graphic);
                    }

                    var ge = new GraphicElement()
                    {
                        Source = line, ElementId = elementId, ProfileId = profileId, LineId = elementId
                    };
                    AddPolyline(ge, graphicsType);
                }
            }
            activeView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
        }
Example #15
0
 public void AddCalculationPolyline(GraphicElement graphicElement, bool doRefresh = false)
 {
     AddPolyline(graphicElement, MilSpaceGraphicsTypeEnum.Calculating, null);
 }
Example #16
0
        public void AddCrossPointerToPoint(IPoint point, int length, string name)
        {
            int segmentLength;
            int segmentCount = 5;
            var color        = grapchucsTypeColors[MilSpaceGraphicsTypeEnum.Visibility]();

            var delta = EsriTools.GetNorthDirrection(point) - 90;

            var angels = new double[]
            {
                delta,
                90 + delta,
                180 + delta,
                270 + delta
            };

            var fromPoints = new IPoint[]
            {
                point,
                point,
                point,
                point,
            };

            decimal segments;

            if (length % 5 != 0)
            {
                segments = length / 4;
            }
            else
            {
                segments = length / 5;
            }

            segmentLength = Convert.ToInt32(Math.Round(segments, 0));

            if (segmentLength >= 100)
            {
                segmentLength = segmentLength / 100 * 100;
            }
            else if (segmentLength >= 10)
            {
                segmentLength = segmentLength / 10 * 10;
            }

            for (int i = 1; i <= segmentCount; i++)
            {
                double segEndPointDistance = segmentLength * i;
                int    j = 0;
                foreach (var angel in angels)
                {
                    double radian      = (90 + angel) * (Math.PI / 180);
                    var    toPoint     = EsriTools.GetPointFromAngelAndDistance(point, radian, segEndPointDistance);
                    var    line        = EsriTools.CreatePolylineFromPoints(fromPoints[j], toPoint);
                    var    segmentName = name + "_" + j + "_" + i;
                    var    ge          = new GraphicElement()
                    {
                        Source = line, Name = segmentName
                    };

                    if (j == 0 && i == segmentCount)
                    {
                        AddPolyline(ge, MilSpaceGraphicsTypeEnum.Visibility, color, LineType.Arrow, true, true, 1);
                    }
                    else
                    {
                        AddPolyline(ge, MilSpaceGraphicsTypeEnum.Visibility, color, LineType.Cross, true, true, 1);
                    }
                    fromPoints[j++] = toPoint.Clone();
                }
            }

            var markPoint = EsriTools.GetPointFromAngelAndDistance(point, 0, segmentLength);

            DrawText(markPoint, segmentLength.ToString(), $"text_{name}", MilSpaceGraphicsTypeEnum.Visibility, color, 9, 1);
        }
Example #17
0
        public KeyValuePair <Guid, IPoint> AddGraphicToMap(
            IGeometry geom,
            IColor color,
            int number,
            bool showNums,
            string textName,
            string guid = null,
            esriSimpleMarkerStyle markerStyle = esriSimpleMarkerStyle.esriSMSCircle,
            int size = 5)
        {
            var emptyResult = new KeyValuePair <Guid, IPoint>();

            if ((geom == null) ||
                (geom.GeometryType != esriGeometryType.esriGeometryPoint) ||
                (geom.SpatialReference == null)
                )
            {
                return(emptyResult);
            }

            var simpleMarkerSymbol = (ISimpleMarkerSymbol) new SimpleMarkerSymbol();

            simpleMarkerSymbol.Color        = color;
            simpleMarkerSymbol.Outline      = false;
            simpleMarkerSymbol.OutlineColor = color;
            simpleMarkerSymbol.Size         = size;
            simpleMarkerSymbol.Style        = markerStyle;

            var markerElement = (IMarkerElement) new MarkerElement();

            markerElement.Symbol = simpleMarkerSymbol;

            IElement element = null;

            element = (IElement)markerElement;
            if (element == null)
            {
                return(emptyResult);
            }
            element.Geometry = geom;
            element.Geometry.SpatialReference = activeView.FocusMap.SpatialReference;

            var eprop     = (IElementProperties)element;
            var newGuid   = Guid.NewGuid().ToString();
            var pointGuid = (String.IsNullOrEmpty(guid)) ? newGuid : guid;

            eprop.Name = pointGuid + geoCalcPointsSuffix;

            var ge = new GraphicElement()
            {
                Source = geom, Name = eprop.Name, Element = element
            };

            if (allGraphics[MilSpaceGraphicsTypeEnum.GeoCalculator].Exists(el => el.Name == eprop.Name))
            {
                DeleteGraphicsElement(ge, true, true);
            }

            graphics.AddElement(element, 0);
            allGraphics[MilSpaceGraphicsTypeEnum.GeoCalculator].Add(ge);

            activeView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);

            if (showNums)
            {
                var point = geom as IPoint;
                DrawText(point, number.ToString(), $"{textName}{pointGuid}", MilSpaceGraphicsTypeEnum.GeoCalculator, color);
            }

            return(new KeyValuePair <Guid, IPoint>(Guid.Parse(pointGuid), element.Geometry as IPoint));
        }
Example #18
0
        private void AddPolyline(GraphicElement graphicElement, MilSpaceGraphicsTypeEnum graphicsType,
                                 IRgbColor color = null, LineType lineType = LineType.DefaultLine, bool doRefresh = false,
                                 bool persist    = false, int width        = 2)
        {
            logger.InfoEx($"AddPolyline {graphicElement.ProfileId} Element {graphicElement.ElementId}");

            IPolyline    profileLine = graphicElement.Source as IPolyline;
            ILineElement lineElement = new LineElementClass();

            var curList = allGraphics[graphicsType];

            bool exists = curList.Any(ge => ge.ProfileId == graphicElement.ProfileId &&
                                      ge.ElementId == graphicElement.ElementId &&
                                      ge.LineId == graphicElement.LineId &&
                                      ge.Name == graphicElement.Name);



            if (!persist && exists)
            {
                logger.InfoEx($"! Persists & Exists");
                return;
            }

            if (color == null)
            {
                color = grapchucsTypeColors[graphicsType]();
            }

            if (lineType == LineType.Line)
            {
                lineElement.Symbol = DefineProfileLineSymbol(graphicsType, color, width);
            }
            else
            {
                lineElement.Symbol = DefineProfileDecorationLineSymbol(graphicsType, color, width, lineType);
            }

            IElement elem = (IElement)lineElement;

            elem.Geometry = profileLine;

            var elementProp = lineElement as IElementProperties;

            elementProp.Name = graphicElement.Name;

            graphicElement.Element = elem;

            DeleteGraphicsElement(graphicElement);


            //    ////////////////
            //    //Create a new text element.
            //ITextElement textElement = new TextElementClass();
            ////Create a text symbol.
            //ITextSymbol textSymbol = new TextSymbolClass();
            //textSymbol.Size = 25;

            ////Set the text element properties.
            //textElement.Symbol = textSymbol;
            //textElement.Text = DateTime.Now.ToShortDateString();

            ////Query interface (QI) for IElement.
            //IElement element = (IElement)textElement;
            ////Create a point.
            //IPoint point = new PointClass();
            //point = profileLine.FromPoint;
            ////Set the element's geometry.
            //element.Geometry = point;

            ////Add the element to the graphics container.
            //activeView.GraphicsContainer.AddElement(element, 0);
            //    ///


            logger.InfoEx($"Adding element to Graphic container..");
            graphics.AddElement(elem, 0);
            logger.InfoEx($"Element addied to Graphic container.");

            if (!exists)
            {
                logger.InfoEx($"Adding element to cache..");
                curList.Add(graphicElement);
                logger.InfoEx($"Element added to cache.");
            }

            if (exists && persist)
            {
                curList.Remove(graphicElement);

                logger.InfoEx($"Adding element to cache..");
                curList.Add(graphicElement);
                logger.InfoEx($"Element added to cache.");
            }

            if (doRefresh)
            {
                logger.InfoEx($"Refreshing view..");
                activeView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
                logger.InfoEx($"Refreshed");
            }
        }
Example #19
0
        public void TestObjects(IGeometry geometry)
        {
            var color = new RgbColor {
                Red = 80, Blue = 150, Green = 150
            };
            ISymbol  symbol;
            IElement element = null;

            if (geometry.GeometryType == esriGeometryType.esriGeometryPolygon)
            {
                ISimpleFillSymbol simplePolygonSymbol = new SimpleFillSymbolClass
                {
                    Color = color,
                    Style = esriSimpleFillStyle.esriSFSSolid
                };

                IFillShapeElement markerElement = new PolygonElementClass
                {
                    Symbol = simplePolygonSymbol
                };

                symbol  = simplePolygonSymbol as ISymbol;
                element = markerElement as IElement;
            }

            if (geometry.GeometryType == esriGeometryType.esriGeometryPolyline)
            {
                ISimpleLineSymbol simplePolylineSymbol = new SimpleLineSymbolClass
                {
                    Color = color,
                    Width = 4
                };

                symbol = simplePolylineSymbol as ISymbol;

                ILineElement lineElement = new LineElementClass
                {
                    Symbol = simplePolylineSymbol
                };

                element = lineElement as IElement;
            }

            if (geometry.GeometryType == esriGeometryType.esriGeometryPoint)
            {
                Type   factoryType   = Type.GetTypeFromProgID("esriDisplay.SimpleMarkerSymbol");
                string typeFactoryID = factoryType.GUID.ToString("B");

                ISimpleMarkerSymbol pointMarkerSymbol = new SimpleMarkerSymbolClass
                {
                    Color = color,
                    Style = esriSimpleMarkerStyle.esriSMSCircle,
                    Size  = 10
                };

                IMarkerElement markerElement = new MarkerElementClass
                {
                    Symbol = pointMarkerSymbol
                };

                element = markerElement as IElement;
                symbol  = pointMarkerSymbol as ISymbol;
            }

            if (element == null)
            {
                return;
            }
            element.Geometry = geometry;
            element.Geometry.SpatialReference = activeView.FocusMap.SpatialReference;

            var eprop = (IElementProperties)element;

            eprop.Name = "test";

            var ge = new GraphicElement()
            {
                Source = geometry, Name = eprop.Name, Element = element
            };

            if (allGraphics[MilSpaceGraphicsTypeEnum.Visibility].Exists(el => el.Name == eprop.Name))
            {
                DeleteGraphicsElement(ge, true, true);
            }

            graphics.AddElement(element, 0);
            allGraphics[MilSpaceGraphicsTypeEnum.Visibility].Add(ge);

            activeView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
        }