Map map = MapView.Active.Map;
IEnumerable<Layer> layers = map.GetLayersAsFlattenedList(); //.Where(l => l.Name.Contains("world"))
foreach (Layer lyr in layers)
{
MessageBox.Show(lyr.Name);
}
MapView mapView = MapView.Active;
IReadOnlyList<Layer> selectedLayers = mapView.GetSelectedLayers();
foreach (Layer lyr in selectedLayers)
{
MessageBox.Show("选择:"+lyr.Name);
}
IReadOnlyList<StandaloneTable> selectedTables = mapView.GetSelectedStandaloneTables();
foreach (StandaloneTable ptab in selectedTables)
{
MessageBox.Show("独立:"+ptab.Name);
}
//create a layer from a shapefile
string uriShp = @"\MachineSharedFolderCensus.shp";
Layer lyr = LayerFactory.Instance.CreateLayer(new Uri(uriShp), map);
//create a layer from a feature class off an sde
string uriSde = @"c:MyDataConnectionsMySDE.sdeCensus";
Layer lyr = LayerFactory.Instance.CreateLayer(new Uri(uriSde), map);
//create a layer using a URL
string url = @"http://sampleserver6.arcgisonline.com/arcgis/rest/services/NapervilleShelters/FeatureServer/0";
Layer lyr = LayerFactory.Instance.CreateLayer(new Uri(url), map);
// create a layer and add it to a groupLayer
string urlLyrx = @"\MachineSharedFolderCensus.lyrx";
Layer lyr = LayerFactory.Instance.CreateLayer(new Uri(urlLyrx), grpLayer);
var uri = new Uri(@"c:MyDataConnectionsMySDE.sdeLANDUSE_polygon");
var createParams = new LayerCreationParams(uri)
{
Name = "Landuse",
IsVisible = false,
};
var layer = LayerFactory.Instance.CreateLayer<Layer>(createParams, MapView.Active.Map);
来自:https://github.com/esri/arcgis-pro-sdk/wiki/ProConcepts-Map-Authoring