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); }
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); }
public void RemoveLinesFromGraphics(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); DeleteGraphicsElement(graphic); if (graphic != null) { curList.Remove(graphic); } } activeView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); }
private void UpdateGraphicLine(GroupedLines groupedLines, int profileId, MilSpaceGraphicsTypeEnum graphicsType, bool selectionRemove = false) { RemoveLineFromSessionGraphicsByLineId(profileId, groupedLines.LineId, graphicsType); logger.InfoEx($"UpdateGraphicLine {profileId}"); 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); }
private static ILineSymbol DefineProfileDecorationLineSymbol(MilSpaceGraphicsTypeEnum graphicsType, IRgbColor color, int width = 2, LineType lineType = LineType.Arrow) { //TODO: Get symbol from ESRITools //Create cartographic line symbol ICartographicLineSymbol cartographicLineSymbol = new CartographicLineSymbolClass(); cartographicLineSymbol.Color = color; cartographicLineSymbol.Width = width; //Define line decoration ILineDecoration lineDecoration = new LineDecorationClass(); if (lineType == LineType.Arrow || lineType == LineType.DefaultLine) { //Define simple line decoration ISimpleLineDecorationElement simpleLineDecorationElement = new SimpleLineDecorationElementClass(); //Place the arrow at the end of the line(the "To" point in the geometry below) simpleLineDecorationElement.AddPosition(1); //Define an arrow marker IArrowMarkerSymbol arrowMarkerSymbol = new ArrowMarkerSymbolClass(); arrowMarkerSymbol.Color = color; arrowMarkerSymbol.Size = 5; arrowMarkerSymbol.Length = 8; arrowMarkerSymbol.Width = 5 + width; //Add an offset to make sure the square end of the line is hidden arrowMarkerSymbol.XOffset = 0.8; simpleLineDecorationElement.MarkerSymbol = arrowMarkerSymbol; lineDecoration.AddElement(simpleLineDecorationElement); } if (lineType == LineType.Point || lineType == LineType.DefaultLine) { //Define simple line decoration ISimpleLineDecorationElement simpleLineDecorationElement = new SimpleLineDecorationElementClass(); simpleLineDecorationElement.AddPosition(0); SimpleMarkerSymbol circleMarkerSymbol = new SimpleMarkerSymbol() { Color = color, Size = 5, Style = esriSimpleMarkerStyle.esriSMSCircle, }; //Add an offset to make sure the square end of the line is hidden circleMarkerSymbol.XOffset = 0.8; simpleLineDecorationElement.MarkerSymbol = circleMarkerSymbol; lineDecoration.AddElement(simpleLineDecorationElement); } //Set line properties ILineProperties lineProperties = (ILineProperties)cartographicLineSymbol; lineProperties.LineDecoration = lineDecoration; return(cartographicLineSymbol); }
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; 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) { 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; 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 (doRefresh) { logger.InfoEx($"Refreshing view.."); activeView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); logger.InfoEx($"Refreshed"); } }
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) { logger.InfoEx($"From Point - Graphics {line.FromPoint.X}: {line.FromPoint.Y}"); logger.InfoEx($"To Point - Graphics {line.ToPoint.X}: {line.ToPoint.Y}"); line.Project(activeView.FocusMap.SpatialReference); logger.InfoEx($"Projected From Point - Graphics {line.FromPoint.X}: {line.FromPoint.Y}"); logger.InfoEx($"Projected To Point - Graphics {line.ToPoint.X}: {line.ToPoint.Y}"); 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); }
private void RemoveLineFromSessionGraphicsByLineId(int profileId, int LineId, MilSpaceGraphicsTypeEnum graphicsType) { var graphicLine = milSpaceSessionGraphics.Where(g => g.ProfileId == profileId && g.LineId == LineId).ToList(); var curList = allGraphics[graphicsType]; if (graphicLine.Count() > 0) { foreach (var graphic in graphicLine) { DeleteGraphicsElement(graphic); curList.Remove(graphic); } } activeView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); }