internal void AddGraphicToMap(IGeometry geom, IColor color, bool IsTempGraphic = false, esriSimpleMarkerStyle markerStyle = esriSimpleMarkerStyle.esriSMSCircle, esriRasterOpCode rasterOpCode = esriRasterOpCode.esriROPNOP)
{
if (geom == null || ArcMap.Document == null || ArcMap.Document.FocusMap == null)
return;
IElement element = null;
double width = 2.0;
geom.Project(ArcMap.Document.FocusMap.SpatialReference);
if(geom.GeometryType == esriGeometryType.esriGeometryPoint)
{
// Marker symbols
var simpleMarkerSymbol = new SimpleMarkerSymbol() as ISimpleMarkerSymbol;
simpleMarkerSymbol.Color = color;
simpleMarkerSymbol.Outline = true;
simpleMarkerSymbol.OutlineColor = color;
simpleMarkerSymbol.Size = 5;
simpleMarkerSymbol.Style = markerStyle;
var markerElement = new MarkerElement() as IMarkerElement;
markerElement.Symbol = simpleMarkerSymbol;
element = markerElement as IElement;
}
else if(geom.GeometryType == esriGeometryType.esriGeometryPolyline)
{
// create graphic then add to map
var lineSymbol = new SimpleLineSymbolClass();
lineSymbol.Color = color;
lineSymbol.Width = width;
if (IsTempGraphic && rasterOpCode != esriRasterOpCode.esriROPNOP)
{
lineSymbol.Width = 1;
lineSymbol.ROP2 = rasterOpCode;
}
var le = new LineElementClass() as ILineElement;
element = le as IElement;
le.Symbol = lineSymbol;
}
if (element == null)
return;
IClone clone = geom as IClone;
element.Geometry = clone as IGeometry;
var mxdoc = ArcMap.Application.Document as IMxDocument;
var av = mxdoc.FocusMap as IActiveView;
var gc = av as IGraphicsContainer;
// store guid
var eprop = element as IElementProperties;
eprop.Name = Guid.NewGuid().ToString();
if (this is LinesViewModel)
GraphicsList.Add(new Graphic(GraphicTypes.Line, eprop.Name, geom, IsTempGraphic));
else if (this is CircleViewModel)
GraphicsList.Add(new Graphic(GraphicTypes.Circle, eprop.Name, geom, IsTempGraphic));
else if (this is EllipseViewModel)
GraphicsList.Add(new Graphic(GraphicTypes.Ellipse, eprop.Name, geom, IsTempGraphic));
else if (this is RangeViewModel)
GraphicsList.Add(new Graphic(GraphicTypes.RangeRing, eprop.Name, geom, IsTempGraphic));
gc.AddElement(element, 0);
//refresh map
av.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
if (!IsTempGraphic)
RaisePropertyChanged(() => HasMapGraphics);
}
/// <summary>