How can I draw a multipoint with a graphic?
I am working on C#.NET ArcObjects add in for ArcGIS desktop 10.0/10.1. The bellow code works fine for adding a one of the points when I set the element.Geometry = points[0] in line 32. But I do not know the right pattern when add a group of points to a graphic container. I have looked around but could not find an example.
Thanks for any help!
RgbColor color = new RgbColorClass();
color.Blue = 255;
color.Red = 0;
color.Green = 0;
RgbColor colorOutline = new RgbColorClass();
ISimpleMarkerSymbol simpleMarkerSymbol = new SimpleMarkerSymbolClass();
simpleMarkerSymbol.Color = color;
simpleMarkerSymbol.Outline = true;
simpleMarkerSymbol.OutlineColor = colorOutline;
simpleMarkerSymbol.Size = 9;
simpleMarkerSymbol.Style = esriSimpleMarkerStyle.esriSMSDiamond;
IMarkerElement markerElement = new MarkerElementClass();
markerElement.Symbol = simpleMarkerSymbol;
List<IPoint> points = new List<IPoint>();
int numberOfPoints = pipeOids.Count;
for (int i = 0; i < numberOfPoints; i++)
{
IPoint point = new PointClass();
point = MeasureToPoint(pipeOids, measures);
points.Add(point);
}
Multipoint multipoint = new MultipointClass();
foreach (IPoint point in points)
{
multipoint.AddPoint(point);
}
IElement element = null;
element = (IElement) markerElement;
element.Geometry = (IGeometry) multipoint;
graphicsContainer.AddElement(element, 0);
Solved! Go to Solution.
OK, so first off I have discovered that I should not be using a mulitpoint object, but just point objects. Which in my defense is what I was trying to do at first. When it did not work I thought maybe if I try some other object. So, I now think that the problem is coming from repeated calls to graphicsContainer.DeleteAllElements(); I am getting extra calls because the ShowResultPoints method is called by the selection changed event from a data grid three times when loading the data grid. By placing some boolean flags in the form class I have prevented it from running extra times on loading.
The below code is working for adding the points.
internal static void ShowResultPoints(List<Int64> pipeOids, List<double> measures)
{
IGraphicsContainer graphicsContainer = null;
IMap map = null;
map = (IMap)ArcMap.Document.FocusMap;
graphicsContainer = (IGraphicsContainer)map;
RgbColor color = new RgbColorClass();
color.Blue = 255;
color.Red = 0;
color.Green = 0;
RgbColor colorOutline = new RgbColorClass();
colorOutline.Red = 255;
ISimpleMarkerSymbol simpleMarkerSymbol = new SimpleMarkerSymbolClass();
simpleMarkerSymbol.Color = color;
simpleMarkerSymbol.Outline = true;
simpleMarkerSymbol.OutlineColor = colorOutline;
simpleMarkerSymbol.Size = 9;
simpleMarkerSymbol.Style = esriSimpleMarkerStyle.esriSMSDiamond;
IMarkerElement markerElement = new MarkerElementClass();
markerElement.Symbol = simpleMarkerSymbol;
List<IPoint> points = new List<IPoint>();
int numberOfPoints = pipeOids.Count;
for (int i = 0; i < numberOfPoints; i++)
{
IPoint point = new PointClass();
point = MeasureToPoint(pipeOids, measures);
points.Add(point);
IElement element = new MarkerElementClass();
element = (IElement)markerElement;
element.Geometry = point;
graphicsContainer.AddElement(element, 0);
}
ArcMap.Document.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
}
Is part of your post missing? I just see the code?
Well there is a little bit of text at the start:
"How can I draw a multipoint with a graphic?"
The above code works fine for adding a one of the points when I set the element.Geometry = points[0] in line 32. But I do not know the right pattern when add a group of points to a graphic container. I have looked around but could not find an example. Sorry, I should have given a little more info upfront.
OK, so first off I have discovered that I should not be using a mulitpoint object, but just point objects. Which in my defense is what I was trying to do at first. When it did not work I thought maybe if I try some other object. So, I now think that the problem is coming from repeated calls to graphicsContainer.DeleteAllElements(); I am getting extra calls because the ShowResultPoints method is called by the selection changed event from a data grid three times when loading the data grid. By placing some boolean flags in the form class I have prevented it from running extra times on loading.
The below code is working for adding the points.
internal static void ShowResultPoints(List<Int64> pipeOids, List<double> measures)
{
IGraphicsContainer graphicsContainer = null;
IMap map = null;
map = (IMap)ArcMap.Document.FocusMap;
graphicsContainer = (IGraphicsContainer)map;
RgbColor color = new RgbColorClass();
color.Blue = 255;
color.Red = 0;
color.Green = 0;
RgbColor colorOutline = new RgbColorClass();
colorOutline.Red = 255;
ISimpleMarkerSymbol simpleMarkerSymbol = new SimpleMarkerSymbolClass();
simpleMarkerSymbol.Color = color;
simpleMarkerSymbol.Outline = true;
simpleMarkerSymbol.OutlineColor = colorOutline;
simpleMarkerSymbol.Size = 9;
simpleMarkerSymbol.Style = esriSimpleMarkerStyle.esriSMSDiamond;
IMarkerElement markerElement = new MarkerElementClass();
markerElement.Symbol = simpleMarkerSymbol;
List<IPoint> points = new List<IPoint>();
int numberOfPoints = pipeOids.Count;
for (int i = 0; i < numberOfPoints; i++)
{
IPoint point = new PointClass();
point = MeasureToPoint(pipeOids, measures);
points.Add(point);
IElement element = new MarkerElementClass();
element = (IElement)markerElement;
element.Geometry = point;
graphicsContainer.AddElement(element, 0);
}
ArcMap.Document.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
}