ArcGIS Pro二次开发-图层标注
if (MapView.Active.GetSelectedLayers().Count != 1) { ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("One feature layer must be selected in the Contents pane. Exiting...", "Info"); return; } var lyr = MapView.Active.GetSelectedLayers().First() as FeatureLayer; if (lyr == null) return; QueuedTask.Run(() => { //Get the layer's definition //community sample Data\Admin\AdminSample.aprx var lyrDefn = lyr.GetDefinition() as CIMFeatureLayer; if (lyrDefn == null) return; //Get the label classes - we need the first one var listLabelClasses = lyrDefn.LabelClasses.ToList(); var theLabelClass = listLabelClasses.FirstOrDefault(); //set the label class Expression to use the Arcade expression theLabelClass.Expression = "return $feature.gisoracleid + TextFormatting.NewLine + $feature.objectid;"; //Set the label definition back to the layer. lyr.SetDefinition(lyrDefn); lyr.SetLabelVisibility(true); });