These workspaces allow dynamically requesting data from the below mentioned workspaces and render them as ArcGISMapImageLayer.Sublayer collection. Note, these workspaces require use of Local Server.
Below are some examples. You would need to replace the parts of code where it is requiring a path to data.
EnterpriseGeodataWorkspace: Displays dynamic layers based upon layers in an enterprise geodatabase(via database connection string) using local server.Uses the LocalServices.EnterpriseGeodatabaseWorkspace and Mapping.TableSublayerSource to display the layers in an enterprise geodatabase as ArcGISMapImageLayer.Sublayers.
```
LocalMapService myLocalMapService = new LocalMapService(@"Path To MPK");
// Create an enterprise geodatabase workspace.
EnterpriseGeodatabaseWorkspace myEnterpriseGeodatabaseWorkspace = EnterpriseGeodatabaseWorkspace.CreateFromConnectionString("database connection string", "PASSWORD=pwd;SERVER=SQLSRV;INSTANCE=sdeinstance;DBCLIENT=sqlserver;DB_CONNECTION_PROPERTIES=connectionProp;DATABASE=DBName;USER=user;VERSION=DBversion;AUTHENTICATION_MODE=DBMS");
// Create an empty DynamicWorkspace and add a EnterpriseGeodatabaseWorkspace into it's collection.
List<DynamicWorkspace> myIEnumerableOfDynamicWorkpace = new List<DynamicWorkspace>();
myIEnumerableOfDynamicWorkpace.Add(myEnterpriseGeodatabaseWorkspace);
// Now set the DynamicWorkspace of the LocalMapService to the one just created.
myLocalMapService.SetDynamicWorkspaces(myIEnumerableOfDynamicWorkpace);
// Start the local map service.
await myLocalMapService.StartAsync();
// Create an ArcGIS map image layer using the same url as the local map service.
Esri.ArcGISRuntime.Mapping.ArcGISMapImageLayer myArcGISMapImageLayer = new Esri.ArcGISRuntime.Mapping.ArcGISMapImageLayer(myLocalMapService.Url);
myArcGISMapImageLayer.Name = "Enterprise";
// Get the first dynamic workspace from the local map service.
List<DynamicWorkspace> myListOfDynamicWorkspaces = (List<DynamicWorkspace>)myLocalMapService.GetDynamicWorkspaces();
DynamicWorkspace oneDynamicWorkspace = myListOfDynamicWorkspaces[0];
// Cast the DynamicWorkspace to a EnterpriseGeodatabaseWorkspace.
EnterpriseGeodatabaseWorkspace oneEnterpriseGeodatabaseWorkspace = (EnterpriseGeodatabaseWorkspace)oneDynamicWorkspace;
// Create a simple fill symbol
SimpleFillSymbol mySimpleFillSymbol = new SimpleFillSymbol();
mySimpleFillSymbol.Color = Colors.Aqua;
mySimpleFillSymbol.Style = SimpleFillSymbolStyle.Solid;
// Create a simple renderer
SimpleRenderer mySimpleRenderer3 = new SimpleRenderer();
mySimpleRenderer3.Symbol = mySimpleFillSymbol;
// Create a table sub-layer source using the id from the enterprise geodatabase workspace id and a specific layer in the enterprise geodatabase workspace
TableSublayerSource myTableSubLayerSource3 = new TableSublayerSource(oneEnterpriseGeodatabaseWorkspace.Id, "DB.DBO.Tablename");//Fullyqualified table name
// Create a new ArcGIS map image sub-layer based on the table sub-layer source
ArcGISMapImageSublayer myArcGISMapImageSublayer3 = new ArcGISMapImageSublayer(2, myTableSubLayerSource3);
myArcGISMapImageSublayer3.Renderer = mySimpleRenderer3;
// Add the ArcGIS map image sub-layer to the sub-layers collection of the ArcGIS map image layer
myArcGISMapImageLayer.Sublayers.Add(myArcGISMapImageSublayer3);
// Add the dynamic ArcGIS map image layer to the map.
MyMapView.Map.OperationalLayers.Add(myArcGISMapImageLayer);
```
FileGeoDatabaseWorkspace
Displays dynamic layers based upon layers in an enterprise geodatabase (via .sde file) using local server. Uses the
LocalServices.EnterpriseGeodatabaseWorkspace and Mapping.TableSublayerSource to display the layers in an enterprise geodatabase as ArcGISMapImageLayer.Sublayers.
```
LocalMapService myLocalMapService = new LocalMapService(@"Path to Mpk");
// Create an enterprise geodatabase workspace.
EnterpriseGeodatabaseWorkspace myEnterpriseGeodatabaseWorkspace = EnterpriseGeodatabaseWorkspace.CreateFromConnectionFile("sde file", "\\\\SdeFconnectionfile.sde");
// Create an empty DynamicWorkspace and add a EnterpriseGeodatabaseWorkspace into it's collection.
List<DynamicWorkspace> myIEnumerableOfDynamicWorkpace = new List<DynamicWorkspace>();
myIEnumerableOfDynamicWorkpace.Add(myEnterpriseGeodatabaseWorkspace);
// Now set the DynamicWorkspace of the LocalMapService to the one just created.
myLocalMapService.SetDynamicWorkspaces(myIEnumerableOfDynamicWorkpace);
// Start the local map service.
await myLocalMapService.StartAsync();
// Create an ArcGIS map image layer using the same url as the local map service.
Esri.ArcGISRuntime.Mapping.ArcGISMapImageLayer myArcGISMapImageLayer = new Esri.ArcGISRuntime.Mapping.ArcGISMapImageLayer(myLocalMapService.Url);
myArcGISMapImageLayer.Name = "Enterprise";
// Get the first dynamic workspace from the local map service.
List<DynamicWorkspace> myListOfDynamicWorkspaces = (List<DynamicWorkspace>)myLocalMapService.GetDynamicWorkspaces();
DynamicWorkspace oneDynamicWorkspace = myListOfDynamicWorkspaces[0];
// Cast the DynamicWorkspace to a EnterpriseGeodatabaseWorkspace.
EnterpriseGeodatabaseWorkspace oneEnterpriseGeodatabaseWorkspace = (EnterpriseGeodatabaseWorkspace)oneDynamicWorkspace;
// Create a simple fill symbol
SimpleFillSymbol mySimpleFillSymbol = new SimpleFillSymbol();
mySimpleFillSymbol.Color = Colors.Black;
mySimpleFillSymbol.Style = SimpleFillSymbolStyle.Solid;
// Create a simple renderer
SimpleRenderer mySimpleRenderer3 = new SimpleRenderer();
mySimpleRenderer3.Symbol = mySimpleFillSymbol;
// Create a table sub-layer source using the id from the enterprise geodatabase workspace id and a specific layer in the enterprise geodatabase workspace
TableSublayerSource myTableSubLayerSource3 = new TableSublayerSource(oneEnterpriseGeodatabaseWorkspace.Id, "Tablename");
// Create a new ArcGIS map image sub-layer based on the table sub-layer source
ArcGISMapImageSublayer myArcGISMapImageSublayer3 = new ArcGISMapImageSublayer(2, myTableSubLayerSource3);
myArcGISMapImageSublayer3.Renderer = mySimpleRenderer3;
// Add the ArcGIS map image sub-layer to the sub-layers collection of the ArcGIS map image layer
myArcGISMapImageLayer.Sublayers.Add(myArcGISMapImageSublayer3);
// Add the dynamic ArcGIS map image layer to the map.
MyMapView.Map.OperationalLayers.Add(myArcGISMapImageLayer);
```
RasterWorkspace:
Displays dynamic raster layers based in a folder on disk using local server. Uses the LocalServices.RasterWorkspace and Mapping.RasterSublayerSource to display the raster layers in a folder on disk as ArcGISMapImageLayer.Sublayers.
```
LocalMapService myLocalMapService = new LocalMapService(@" Path to mpk");
// Create a raster geodatabase workspace (aka. a folder on disk that contains raster images).
RasterWorkspace myRasterWorkspace = new RasterWorkspace("raster_wkspc", @"PathtoRasterFolder");
// Create an empty DynamicWorkspace and add a RasterWorkspace into it's collection.
List<Esri.ArcGISRuntime.LocalServices.DynamicWorkspace> myIEnumerableOfDynamicWorkpace = new List<Esri.ArcGISRuntime.LocalServices.DynamicWorkspace>();
myIEnumerableOfDynamicWorkpace.Add(myRasterWorkspace);
// Now set the DynamicWorkspace of the LocalMapService to the one just created.
myLocalMapService.SetDynamicWorkspaces(myIEnumerableOfDynamicWorkpace);
// Start the local map service.
await myLocalMapService.StartAsync();
// Create an ArcGIS map image layer using the same url as the local map service.
ArcGISMapImageLayer myArcGISMapImageLayer = new ArcGISMapImageLayer(myLocalMapService.Url);
myArcGISMapImageLayer.Name = "WithRaster";
// Get the first dynamic workspace from the local map service.
List<DynamicWorkspace> myListOfDynamicWorkspaces = (List<DynamicWorkspace>)myLocalMapService.GetDynamicWorkspaces();
DynamicWorkspace oneDynamicWorkspace = myListOfDynamicWorkspaces[0];
// Cast the DynamicWorkspace to a RasterWorkspace
RasterWorkspace oneRasterWorkspace = (RasterWorkspace)oneDynamicWorkspace;
// Create a raster sub-layer source using the id from the raster workspace id and a specific raster image by file name.
RasterSublayerSource myRasterSubLayerSource1 = new RasterSublayerSource(oneRasterWorkspace.Id, "Raster.tif");
// Create a new ArcGIS map image sub-layer based on the raster sub-layer source .
ArcGISMapImageSublayer myArcGISMapImageSublayer1 = new ArcGISMapImageSublayer(0, myRasterSubLayerSource1);
// Add the ArcGIS map image sub-layer to the sub-layers collection of the ArcGIS map image layer.
// NOTE: default rendering of the raster image will be used.
myArcGISMapImageLayer.Sublayers.Add(myArcGISMapImageSublayer1);
// Add the dynamic ArcGIS map image layer to the map.
MyMapView.Map.OperationalLayers.Add(myArcGISMapImageLayer);
```
ShapeFileWorkspace:
Displays dynamic layers based upon shapefiles using local server. Uses the LocalServices.ShapefileWorkspace and
Mapping.TableSublayerSource to display the shapefiles as ArcGISMapImageLayer.Sublayers.
```
LocalMapService myLocalMapService = new LocalMapService(@"Path to mpk");
// Create a shapefile workspace.
ShapefileWorkspace myShapefileWorkspace = new ShapefileWorkspace("MyShapefileWorkspace", @"PathToShapefile");
// Create an empty DynamicWorkspace and add a ShapefileWorkspace into it's collection.
List<DynamicWorkspace> myIEnumerableOfDynamicWorkpace = new List<DynamicWorkspace>();
myIEnumerableOfDynamicWorkpace.Add(myShapefileWorkspace);
// Now set the DynamicWorkspace of the LocalMapService to the one just created.
myLocalMapService.SetDynamicWorkspaces(myIEnumerableOfDynamicWorkpace);
// Start the local map service.
await myLocalMapService.StartAsync();
// Create an ArcGIS map image layer using the same url as the local map service.
ArcGISMapImageLayer myArcGISMapImageLayer = new ArcGISMapImageLayer(myLocalMapService.Url);
// Get the first dynamic workspace from the local map service.
List<DynamicWorkspace> myListOfDynamicWorkspaces = (List<DynamicWorkspace>)myLocalMapService.GetDynamicWorkspaces();
DynamicWorkspace oneDynamicWorkspace = myListOfDynamicWorkspaces[0];
// Cast the DynamicWorkspace to a ShapefileWorkspace
ShapefileWorkspace oneShapeFileWorkspace = (ShapefileWorkspace)oneDynamicWorkspace;
// --------------------------------------------------------------------------
// Create a simple marker symbol
SimpleMarkerSymbol mySimpleMarkerSymbol = new SimpleMarkerSymbol();
mySimpleMarkerSymbol.Color = Colors.Black;
mySimpleMarkerSymbol.Size = 10;
mySimpleMarkerSymbol.Style = SimpleMarkerSymbolStyle.Circle;
// Create a simple renderer
SimpleRenderer mySimpleRenderer1 = new SimpleRenderer();
mySimpleRenderer1.Symbol = mySimpleMarkerSymbol;
// Create a table sub-layer source using the id from the shapefile workspace id and a specific shapefile in the workspace
TableSublayerSource myTableSubLayerSource1 = new TableSublayerSource(oneShapeFileWorkspace.Id, "ShapeFileName.shp");
// Create a new ArcGIS map image sub-layer based on the table sub-layer source
ArcGISMapImageSublayer myArcGISMapImageSublayer1 = new ArcGISMapImageSublayer(0, myTableSubLayerSource1);
myArcGISMapImageSublayer1.Renderer = mySimpleRenderer1;
// Add the ArcGIS map image sub-layer to the sub-layers collection of the ArcGIS map image layer
myArcGISMapImageLayer.Sublayers.Add(myArcGISMapImageSublayer1);
// Add the dynamic ArcGIS map image layer to the map.
MyMapView.Map.OperationalLayers.Add(myArcGISMapImageLayer);
```