Shapefile feature layers does not always show up on the map

02-02-2023 01:56 PM
New Contributor III


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();


Any input would be appreciated.

Thanks, Mattias

0 Kudos
2 Replies
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
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