All,
I'm trying to remove the graphics layer on map. Codes did go through
graphicsLayer.RemoveElements(graphicsLayer.GetSelectedElements());
but nothing happened. My graphics layer is still there. Am I missing something?
protected async override void OnClick()
{
//Get the graphics layer
var graphicsLayer = MapView.Active.Map.GetLayersAsFlattenedList().OfType<GraphicsLayer>().FirstOrDefault();
await QueuedTask.Run(() =>
{
//Remove existing graphicsLayer
if (graphicsLayer != null)
{
graphicsLayer.RemoveElements(graphicsLayer.GetSelectedElements());
}
});
Thanks!
Solved! Go to Solution.
Hi,
Your code removes selected elements of graphics layer. To remove graphics layer you need to remove map layer using QueuedTask.Run like this :
MapView.Active.Map.RemoveLayer(graphicsLayer);
Thank you very much @GKmieliauskas . I actually wanted to remove all elements. I should use
graphicsLayer.RemoveElements(graphicsLayer.GetElements()); instead of
graphicsLayer.RemoveElements(graphicsLayer.GetSelectedElements());
Hi,
Your code removes selected elements of graphics layer. To remove graphics layer you need to remove map layer using QueuedTask.Run like this :
MapView.Active.Map.RemoveLayer(graphicsLayer);
Thank you very much @GKmieliauskas . I actually wanted to remove all elements. I should use
graphicsLayer.RemoveElements(graphicsLayer.GetElements()); instead of
graphicsLayer.RemoveElements(graphicsLayer.GetSelectedElements());