Hi, I am adding a layer to a map and want to read all the values from a particular field,
await QueuedTask.Run(() =>
{
Layer RefLayer = LayerFactory.CreateLayer(new Uri(LyrFile), myMap);
MapView.Active.ZoomToAsync(RefLayer);
if (RefLayer == null)
{
ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("Failed to create layer for url:" + LyrFile);
return;
}
else
{
//find layer
var disLayer = MapView.Active.Map.FindLayers(layerName).FirstOrDefault() as BasicFeatureLayer;
}
});
however the FindLayers returns null.
What would be an appropriate way to wait until the creation is done?
Can someone help me solve this?
I cannot reproduce this. It works for me.
A couple of things which may just be copy-paste issues into the post....
1. You add the layer to "myMap"
2. You attempt to retrieve it from MapView.Active.Map? Are they the same?
also
does RefLayer.Name == layerName? I can't tell from your code.
Is the layer a BasicFeatureLayer?
Thank you Charles. Yes, myMap is the MapView.Active.Map and RefLayer.Name is the layerName.
Your questions helped me find out what the problem was: I was handling the creation in a queued task and FindLayers outside that task. I'm new to C# so I haven't really grasped how the queued tasks work. Thanks again!