Hi Rich,
I did not call Map.Redraw, but I have now...
Since Map.Redraw is called on the MapView object I had to switch from the Map object to MapView.
Hence, selectedMapAjour is now of type MapView.
The code look now as follows:
if (selectedMapAjour != null && !string.IsNullOrEmpty(PathGdbAjour))
{
foreach (FeatureLayer layer in selectedMapAjour.Map.Layers.OfType<FeatureLayer>())
{
GetSetDataConnection(selectedMapAjour, layer, PathGdbAjour);
}
}
private async void GetSetDataConnection(MapView mapview, FeatureLayer layer, string newGDB)
{
await QueuedTask.Run(() =>
{
CIMFeatureLayer def = layer.GetDefinition() as CIMFeatureLayer;
var dcon = def.FeatureTable.DataConnection as CIMStandardDataConnection;
dcon.WorkspaceConnectionString = System.IO.Path.Combine(newGDB, layer.Name);
dcon.Dataset = layer.Name;
layer.SetDefinition(def);
mapview.Redraw(true);
});
}
Line 18 does not change the result.
When I adjust the data source for a layer manually, then I have to select the appropriate feature class within the geodatabase. Confirming the 'Change Data Source' dialogue makes the layer properties dialogue flash and thereafter the property for the database contains the path to the database. All other information of the layers data source properties are populated. The property 'Feature Class' does not only have the name of the feature class but also a button, holding information about the 'Object Class ID'.
When I run my code, the property for the database in the layer property dialogue is showing the entire path, down to the feature class
C:\Projects\Support\geo_507474_20200721_12_42.gdb\Bassin.
The property for Feature Class in the dialogue show the name of the feature class (without the button for the 'Object Class ID'), while all other properties only show a 'Not Available'.
Putting the redraw into the GetSetDataConnection method means that for every layer the map view will be redrawn. I set the redraw in there because when having it right after line 6 I am told that the redraw method must be called on the thread this object was created. Do I have to set the redraw into the GetSetDataConnection method or can I do this also at a more 'central place' where the map view is only updated once all layers got their new data source.
- We are living in the 21st century.
GIS moved on and nobody needs a format consisting out of at least three files! No, nobody needs shapefiles, not even for the sake of an exchange format. Folks, use GeoPackage to exchange data with other GIS!