I have a Feature Service in my Map, no local sde files or file geodatabase (aside from default.gdb which I do not use).
I published this service with Version Management set to "true", from a Map with layers that reference a Branch - Versioned dataset.
Is the only way to retrieve the data source is by iteration through layer(s) using the ArcGIS Pro SDK? I am trying to create a custom versioning tool and I wanted to place it in the same Tab as the other Versioning commands, and when that tab is active, no layers are selected in the TOC. How do the existing commands (Post, Reconcile, Manage Versions etc) know the current selected data source? I even tried subscribing to TOCSelectionChangedEvent, however the only arguments returned are MapViewEventArgs, which do not contain any context about selected Datasource in the TOC.
Hi Kevin,
Try this to get selected layers, then from layer you can get datasource and etc.:
BasicFeatureLayer layer = null;
await ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() =>
{
//find selected layer
if (MapView.Active.GetSelectedLayers().Count == 0)
{
MessageBox.Show("Select a feature class from the Content 'Table of Content' first.");
return;
}
layer = MapView.Active.GetSelectedLayers()[0] as BasicFeatureLayer;
});
Gintautas,
The tool that I am writing using the condition: esri_mapping_itemSelectedIsVersionableCondition to control the enabled status of my Add-in button. This does not allow me to have a selected layer and selected datasource at the same time.
What I am asking for, is any way to get the list of data sources in the project. If I want to get all the Layers in the Map, I would use MapView.Active.Layers. Is there any sort of .GetDatasources() or GetSelectedDatasources() for the project that you have seen in the SDK? I could not find anything and I do not want to have to rely on the layers being selected, or pulled from the Map.
Thanks,
Kevin
Hi Kevin,
You can look at the sample here: https://github.com/Esri/arcgis-pro-sdk-community-samples/blob/f5f9dda18efa173a56d128f3ea64ca34ac3f68... specifically the GetDatasource method. This method will retrieve the data source for your BasicFeatureLayers. In order to get a list of all layers you have to use the active MapView's Map member and get the list of layers from there:
MapView.Active.Map.Layers
Make sure to check if the layer is really a BasicFeatureLayer type.
Hope this answers your question.
- Wolf
Wolf,
I should have written my initial question better, it is a little misleading so I have corrected it. In a nutshell, what I am asking is:
Is the only way to retrieve the datasource is by iteration through layer(s) using the ArcGIS Pro SDK? I am trying to create a custom post/reconcile tool and I wanted to place it in the same Tab as the other Versioning commands, and when that tab is active, no layers are selected in the TOC. How do the existing commands (Post, Reconcile, Manage Versions etc) know the current selected data source? I even tried subscribing to TOCSelectionChangedEvent, however the only arguments returned are MapViewEventArgs, which do not contain any context about selected Datasource in the TOC.
Hi Kevin,
I haven't tried this yet, but if you listen to the TOCSelectionChangedEvent you get the MapViewEventArgs parameter which contains the MapView property. If you use the MapView.GetSelectedLayers() method you should be able to get the DataSource(s) from the returned list of layers.
Wolf,
Is the only way to get a DataSource in my map project from a Layer?
Thanks,
Kevin
I think that's the only way. You can get the list of edited datasources using a project property: https://pro.arcgis.com/en/pro-app/sdk/api-reference/#topic20358.html
If you want to re-use some of the states and conditions of ArcGIS Pro for your button(s) you can take a look at the editing.daml file at this default location: C:\Program Files\ArcGIS\Pro\bin\Extensions\Editing
For example search for: esri_mapping_TOCSelectionValidForReconcile_condition
You could use this condition to enable your button's functionality without having to listen to any changes in the TOC.
Wolf,
After trying out Project.Current.EditedDatastores(), it only returns ones with active edits for that client session.
Scenario 1: Draw a point, my datasource shows up in Project.Current.EditedDatastores
Scenario 2: Draw a point, save edits, Project.Current.EditedDatastores is empty.
esri_mapping_TOCSelectionValidForReconcile_condition is viable for button enabling/disabling.
Hi,
I've the exact same problem. Did you solved it?