I just found one way of accessing file geodatabase through the local server as follows.
private ArcGISMapImageSublayer _fileGeodatabaseSublayer;
private LocalServer _LocalServer;
public MainWindow()
{
InitializeComponent();
Initialize();
}
private async void Initialize()
{
// Create a map and add it to the view
MyMapView.Map = new Map(BasemapType.Topographic, 39.7294, -104.8319, 12);
try
{
// Start the local server instance
await LocalServer.Instance.StartAsync();
}
catch (InvalidOperationException ex)
{
MessageBox.Show(String.Format("Please ensure that local server is installed prior to using the sample. See instructions in readme.md or metadata.json. Message: {0}", ex.Message), "Local Server failed to start");
}
}
private void m_Button_Click(object sender, RoutedEventArgs e)
{
string filePath = "D:\\test\\test.gdb";
string fileName = "featureclass1";
StartLocalMapService(fileName, filePath);
}
private async void StartLocalMapService(string fileName, string filePath)
{
// any mpk file - don't know why
string mapServiceUrl = System.IO.Path.GetDirectoryName(filePath) + "\\mpk_blank.mpk";
// Create the local map service
var localMapService = new LocalMapService(mapServiceUrl);
FileGeodatabaseWorkspace ws = new FileGeodatabaseWorkspace("file_wkspc", filePath);
TableSublayerSource source = new TableSublayerSource(ws.Id, fileName);
_fileGeodatabaseSublayer = new ArcGISMapImageSublayer(0, source);
localMapService.SetDynamicWorkspaces(new List<DynamicWorkspace>()
{
ws
});
localMapService.StatusChanged += localMapService_StatusChanged;
await localMapService.StartAsync();
}
private async void localMapService_StatusChanged(object sender, StatusChangedEventArgs e)
{
if (e.Status == LocalServerStatus.Started)
{
if (!(sender is LocalMapService localService))
{
return;
}
ArcGISMapImageLayer imageryLayer = new ArcGISMapImageLayer(localService.Url);
imageryLayer.LoadStatusChanged += (q, ex) =>
{
// Add the layer to the map once loaded
if (ex.Status == Esri.ArcGISRuntime.LoadStatus.Loaded)
{
// Create a default symbol style
SimpleLineSymbol lineSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle.Solid, System.Drawing.Color.Red, 3);
// Apply the symbol style with a renderer
_fileGeodatabaseSublayer.Renderer = new SimpleRenderer(lineSymbol);
imageryLayer.Sublayers.Add(_fileGeodatabaseSublayer);
}
};
await imageryLayer.LoadAsync();
MyMapView.Map.OperationalLayers.Clear();
// Add the image layer to the map
MyMapView.Map.OperationalLayers.Add(imageryLayer);
}
}