Parameters
- uri
- A System.Uri represents the path or url to a dataset or .lyrx or .lpkx file.
Some sample paths to:
| A FeatureClass in a FileGeodatabase | C:\Data\MyFileGDB.gdb\Census |
| A shape file in a folder | \\Machine\SharedFolder\MySpatialData.dbf |
| A RasterDataset in a FileGeodatabase | C:\Data\MyFileGDB.gdb\DEM |
| A FeatureClass from a SDE | C:\Connections\MySDEConnection.sde\Roads |
| An image file in a folder | \\Machine\SharedFolder\Imagery.tif |
| A .lyrx or .lpkx file | \\Machine\SharedFolder\Fires.lyrx |
| A map service layer | http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer |
| A feature layer off a map or feature service | http://sampleserver6.arcgisonline.com/arcgis/rest/services/NapervilleShelters/FeatureServer/0 |
//Connect to the AGS service. Note: the connection will persist for the
//duration of the Pro session.
var serverUrl = "https://sampleserver6.arcgisonline.com/arcgis/rest/services";
var username = "user1";
var password = "user1";
await QueuedTask.Run(() =>
{
//at any point before creating a layer, first make a connection to the server
//if one has not been already established for the current session
var uri = new Uri(serverUrl);
var props = new ServiceConnectionProperties(uri)
{
User = username
};
//It is preferred that you use the Windows Credential Manager to store the password
//However, it can be set as clear text if you so choose
props.Password = password; //not recommended
//Establish a connection to the server at any point in time _before_
//creating a layer from a service on the server
var gdb = new Geodatabase(props);
gdb.Dispose();//you do not need the geodatabase object after you have connected.
});
//later in the session, as needed...create a layer from one of the services
//on the server
var serviceUrl = "https://sampleserver6.arcgisonline.com/arcgis/rest/services/Wildfire_secure/MapServer";
var map = MapView.Active.Map;
QueuedTask.Run(() =>
{
var lc = new LayerCreationParams(new Uri(serviceUrl));
LayerFactory.Instance.CreateLayer<MapImageLayer>(lc, map);
});
var sceneLayerUrl = @"https://myportal.com/server/rest/services/Hosted/SceneLayerServiceName/SceneServer"; //portal items also ok as long as the portal is the current active portal... //var sceneLayerUrl = @"https://myportal.com/home/item.html?id=123456789abcdef1234567890abcdef0"; await QueuedTask.Run(() => { //Create with initial visibility set to false. Add to current scene var createparams = new LayerCreationParams(new Uri(sceneLayerUrl, UriKind.Absolute)) { IsVisible = false }; //cast to specific type of scene layer being created - in this case FeatureSceneLayer var sceneLayer = LayerFactory.Instance.CreateLayer<Layer>( createparams, MapView.Active.Map) as FeatureSceneLayer; //or...specify the cast directly var sceneLayer2 = LayerFactory.Instance.CreateLayer<FeatureSceneLayer>( createparams, MapView.Active.Map); //ditto for BuildingSceneLayer, PointCloudSceneLayer, IntegratedMeshSceneLayer //... });
Target Platforms: Windows 11, Windows 10