ArcGIS Pro二次开发-获得地图的信息和打开图层
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 = @"\\Machine\SharedFolder\Census.shp";
Layer lyr = LayerFactory.Instance.CreateLayer(new Uri(uriShp), map);
//create a layer from a feature class off an sde
string uriSde = @"c:\MyDataConnections\MySDE.sde\Census";
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 = @"\\Machine\SharedFolder\Census.lyrx";
Layer lyr = LayerFactory.Instance.CreateLayer(new Uri(urlLyrx), grpLayer);
var uri = new Uri(@"c:\MyDataConnections\MySDE.sde\LANDUSE_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