GraphicsOverlay - adding points of different color

693
1
05-31-2019 12:11 PM
JonShuler
New Contributor

We are doing some testing of the SDK Runtime using C# & WPF.  I started with the "Display point, line, and polygon graphics" tutorial and added the following code:

private void DisplayPoints(SqlGeography geometry, Color pointColor, bool displayOnMap = true)
{
var numGeometries = geometry.STNumGeometries();
for (int i = 0; i < geometry.STNumGeometries(); i++)
{
var polygonPoints = new Esri.ArcGISRuntime.Geometry.PointCollection(SpatialReferences.Wgs84);
var numSTPoints = geometry.STGeometryN(i + 1).STNumPoints();
for (int j = 1; j <= numSTPoints; j++)
{
var point = geometry.STPointN(j);
pointSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbolStyle.Circle, pointColor, 5);
pointSymbol.Outline = new SimpleLineSymbol(SimpleLineSymbolStyle.Null, pointColor, 1);

var pointGraphic = new Graphic(new MapPoint((double)point.Long, (double)point.Lat, SpatialReferences.Wgs84), pointSymbol);

MapGraphics.Graphics.Add(pointGraphic);
}
}
}
}

I am loading some geography data from a db and displaying on the map.  Everything works except the points are always the same color no matter what color is passed in.  I determined that whatever is the last color of the last point added wins.

If I want to add a bunch of points (or polygons) what is the proper way to set the colors if I need them to be different.

0 Kudos
1 Reply
KimberlyMcCarty
Esri Contributor

Hi Jon,

From your code provided it looks like you're adding all the points to the graphics overlay with whatever color is being passed to this DisplayPoints method. Were you concerned that they were all the same color or that the single color being passed isn't showing? If you're calling this method while passing the same geometry and iterating through a list of colors then a bunch of graphics are being added one on top of the other. You will only see the topmost graphic in this case which is the last color you pass through.

If you want certain features to be different colors you can either in your same function change the color after a set number of features. Or if you have a field you want to use containing unique values you can use a Unique Value Renderer.

https://developers.arcgis.com/net/latest/wpf/sample-code/renderuniquevalues.htm

Best,

Kim

0 Kudos