protected override async void OnClick()
{
var activeMap = MapView.Active?.Map;
if (activeMap == null) return;
var location = @"C:/Data/FeatureTest/FeatureTest.gdb";
var name = @"TestLinesAnno";
await QueuedTask.Run(() =>
{
List<Layer> layersToRemove = new List<Layer>();
foreach (AnnotationLayer annotationLayer in activeMap.GetLayersAsFlattenedList().OfType<AnnotationLayer>())
{
using (AnnotationFeatureClass featureClass = annotationLayer.GetFeatureClass() as AnnotationFeatureClass)
{
if (featureClass != null)
{
using (var dataStore = featureClass.GetDatastore())
{
if (dataStore.GetPath().AbsolutePath == location &&
featureClass.GetName() == name)
{
layersToRemove.Add(annotationLayer);
}
}
}
}
}
activeMap.RemoveLayers(layersToRemove);
});
}