GraphicsLayer layer = LayerExists(layerName); if (!layer.Graphics.Contains(g)) layer.Graphics.Add(g);
bool layerContainsGraphic = false; foreach (Graphic graphicInLayer in layer.Graphics) { if (graphicToAdd.Geometry == graphicInLayer.Geometry) layerContainsGraphic = true; } if (!layerContainsGraphic) layer.Graphics.Add(graphicToAdd);Solved! Go to Solution.
var id = g.Attributes["ObjectId"]; if (!layer.Graphics.Any(graphic => graphic.Attributes["ObjectId"] == id)) ......
The layers you pointed out do have an ObjectId but called 'FID'.
You could loop on the layer fields, look for a field of type OID and then use this field as Identifier.
It's not 100% guarantee but...
int uniqueId = Convert.ToInt32(graphicToAdd.Attributes[StaticVariables.ObjectIdFieldName]);
private static bool LayerContainsObject(GraphicsLayer layer, int uniqueId)
{
foreach (Graphic g in layer)
if (Convert.ToInt32(g.Attributes[StaticVariables.ObjectIdFieldName]) == uniqueId)
return true;
return false;
}