Shapefile feature layers does not always show up on the map

313
2
02-02-2023 01:56 PM
MattiasWesterberg
New Contributor III

Hi,

Sometimes my shapefile layers is not shown on the map when i run my method below.
The first row with the Delay solves the problem. But is there another way to do it? Because i dont want to do the delay.

public async Task drawShapeFileAsync()
{
	await Task.Delay(2000);

	ArrayList shpFiles = layersSingleton.getShpLayers();
	
	for (int i = 0; i < shpFiles.Count; i++)
	{
		ShpLayer shpLayer = (ShpLayer)shpFiles[i];
		string filepath = workingDirectory + "\\\\" + shpLayer.fileName;

		ShapefileFeatureTable shapefileFeatureTable = await ShapefileFeatureTable.OpenAsync(filepath);
		FeatureLayer featureLayer = new FeatureLayer(shapefileFeatureTable);

		featureLayer.RenderingMode = FeatureRenderingMode.Dynamic;
		await MyMapView.Map.LoadAsync();
		MyMapView.Map.OperationalLayers.Add(featureLayer);    
	}
}

 

Any input would be appreciated.

Thanks, Mattias

0 Kudos
2 Replies
PreetiMaske
Esri Contributor

Just curious, if there is a reason for loading MyMapView.Map.LoadAsync() in the loop?

Can you try removing `MyMapView.Map.LoadAsync()` from the loop. If loading the map is needed, I suggest either do it before or after the for loop.

0 Kudos
MattiasWesterberg
New Contributor III

No there was no reason for that.

I have now tried to move MyMapView.Map.LoadAsync() to both before and after the loop.

When i have it before the loop it works, but only if i still have the Delay. So it did not solve my problem.

Thanks for the suggestion.

0 Kudos