I am trying to make an add-in that allows a user to switch between multiple historical moments for a feature service. I also want to allow switching to the default view, sans historical moments. In the Pro UI, there is a radio button that allows you to return to the current time, and reflects that in the data source view of the contents panel. Unfortunately, I can't figure out how to replicate that functionality in my add-in.
I am able to switch versions with Map.ChangeVersion, but getting the default from version manager (GetDefaultVersion) and switching to that does nothing, and switching to DateTime.Now just places the feature service in another historical moment.
Any help is greatly appreciated!
Hi,
Have you seen that thread?
Hello,
Yes I did, this thread was how I learned how to switch to historical moments. But I'm still not sure how to revert to current time after switching.
Have you tried to read current version before changing and save it for later using?
private ArcGIS.Core.Data.Version _fromVersion;
private Task ChangeToHistoricVersion()
{
// Before changing to historic version
_fromVersion = versionManager.GetCurrentVersion();
}
private Task ChangeToCurrentVersion()
{
// changing back to current version
MapView.Active.Map.ChangeVersion(historicalVersion, _fromVersion);
}
This may work, but it's not a viable solution for me, as the user might open a project with a feature service already on a historical moment. They can also switch between historical moments multiple times. I'm not sure how to differentiate between a historical moment and the current one.
There must be a way, I wish I could peek at the underlying code of that radio button 😅
Create a historical version with DateTime.Now, and switch to it.
HistoricalVersionDescription historicalVersionDescription = new HistoricalVersionDescription(versionName, DateTime.Now);
HistoricalVersion historicalVersion = versionManager.CreateHistoricalVersion(historicalVersionDescription);
Hello,
Thanks for the reply. I'm not sure this is possible, since I am trying to switch the moments for a feature service. Correct me if I'm wrong, but named historical moments for feature services are not supported. When trying to create a historical version, I get the error: "System.NotSupportedException: 'The underlying data store does not support this operation.'"
To switch to a specific date/time, I usually call version_manager.GetHistoricalVersion(date);
Is there an alternative?
VersionManager.CreateHistoricalVersion creates a named historical version in an enterprise geodatabase. As you noted, feature services do not support this.
To connect to an historical moment, create an HistoricalVersion object using VersionManager.GetHistoricalVersion(DateTime), then pass it to Mapview.Active.Map.ChangeVersion()
Yes I know, my issue is returning to the current moment from a historical moment, rather than switching to one in the first place. I have used the method above to connect to one. I now need to remove that and just see the default, which is the behavior achieved by the "return to current time" button in the History Dockpane.