ProSnippets Labeling - Esri/arcgis-pro-sdk GitHub Wiki
Language: C#
Subject: Labeling
Contributor: ArcGIS Pro SDK Team <[email protected]>
Organization: Esri, http://www.esri.com
Date: 11/18/2026
ArcGIS Pro: 3.8
IDE: Visual Studio 2026, Visual Studio Code
Get the active map's labeling engine - Maplex or Standard labeling engine
varmap=MapView.Active?.Map;if(map==null)return;awaitQueuedTask.Run(()=>{//Get the active map's definition - CIMMap.varcimMap=map.GetDefinition();//Get the labeling engine from the map definitionCIMGeneralPlacementPropertieslabelEngine=cimMap.GeneralPlacementProperties;});
Change the active map's labeling engine from Standard to Maplex or vice versa
varmap=MapView.Active?.Map;if(map==null)return;awaitQueuedTask.Run(()=>{//Get the active map's definition - CIMMap.varcimMap=map.GetDefinition();//Get the labeling engine from the map definitionvarcimGeneralPlacement=cimMap.GeneralPlacementProperties;if(cimGeneralPlacementisCIMMaplexGeneralPlacementProperties){//Current labeling engine is Maplex labeling engine//Create a new standard label engine propertiesvarcimStandardPlacementProperties=newCIMStandardGeneralPlacementProperties();//Set the CIMMap's GeneralPlacementProperties to the new label enginecimMap.GeneralPlacementProperties=cimStandardPlacementProperties;}else{//Current labeling engine is Standard labeling engine//Create a new Maplex label engine propertiesvarcimMaplexGeneralPlacementProperties=newCIMMaplexGeneralPlacementProperties();//Set the CIMMap's GeneralPlacementProperties to the new label enginecimMap.GeneralPlacementProperties=cimMaplexGeneralPlacementProperties;}//Set the map's definitionmap.SetDefinition(cimMap);});
Apply text symbol to a feature layer
awaitQueuedTask.Run(()=>{//Get the layer's definitionvarlyrDefn=featureLayer.GetDefinition()asCIMFeatureLayer;//Get the label classes - we need the first onevarlistLabelClasses=lyrDefn.LabelClasses.ToList();vartheLabelClass=listLabelClasses.FirstOrDefault();//Set the label classes' symbol to the custom text symbol//Refer to the ProSnippets-TextSymbols wiki page for help with creating custom text symbols.//Example: var textSymbol = await CreateTextSymbolWithHaloAsync();theLabelClass.TextSymbol.Symbol=textSymbol;lyrDefn.LabelClasses=listLabelClasses.ToArray();//Set the labelClasses backfeatureLayer.SetDefinition(lyrDefn);//set the layer's definition//set the label's visibilityfeatureLayer.SetLabelVisibility(true);});
Enable labeling of a layer
awaitQueuedTask.Run(()=>{if(!featureLayer.IsLabelVisible){//set the label's visibilityfeatureLayer.SetLabelVisibility(true);}});
Modify the Placement/Position of labels - Point geometry
varmap=MapView.Active?.Map;if(map==null)return;awaitQueuedTask.Run(()=>{//Get the layer's definitionvarlyrDefn=featureLayer.GetDefinition()asCIMFeatureLayer;//Get the label classes - we need the first onevarlistLabelClasses=lyrDefn.LabelClasses.ToList();vartheLabelClass=listLabelClasses.FirstOrDefault();//Modify label Placement//Check if the label engine is Maplex or standard.CIMGeneralPlacementPropertieslabelEngine=map.GetDefinition().GeneralPlacementProperties;if(labelEngineisCIMStandardGeneralPlacementProperties)//Current labeling engine is Standard labeling engine{theLabelClass.StandardLabelPlacementProperties.PointPlacementMethod=StandardPointPlacementMethod.OnTopPoint;}else//Current labeling engine is Maplex labeling engine{theLabelClass.MaplexLabelPlacementProperties.PointPlacementMethod=MaplexPointPlacementMethod.CenteredOnPoint;}lyrDefn.LabelClasses=listLabelClasses.ToArray();//Set the labelClasses backfeatureLayer.SetDefinition(lyrDefn);//set the layer's definition});
Modify the Placement/Position of labels - Line geometry
varmap=MapView.Active?.Map;if(map==null)return;awaitQueuedTask.Run(()=>{//Get the layer's definitionvarlyrDefn=featureLayer.GetDefinition()asCIMFeatureLayer;//Get the label classes - we need the first onevarlistLabelClasses=lyrDefn.LabelClasses.ToList();vartheLabelClass=listLabelClasses.FirstOrDefault();//Modify label Placement//Check if the label engine is Maplex or standard.CIMGeneralPlacementPropertieslabelEngine=map.GetDefinition().GeneralPlacementProperties;if(labelEngineisCIMStandardGeneralPlacementProperties){//Current labeling engine is Standard labeling enginevarlineLablePosition=newCIMStandardLineLabelPosition{Perpendicular=true,Parallel=false,ProduceCurvedLabels=false,Horizontal=false,OnTop=true};theLabelClass.StandardLabelPlacementProperties.LineLabelPosition=lineLablePosition;}else//Current labeling engine is Maplex labeling engine{theLabelClass.MaplexLabelPlacementProperties.LinePlacementMethod=MaplexLinePlacementMethod.CenteredPerpendicularOnLine;theLabelClass.MaplexLabelPlacementProperties.LineFeatureType=MaplexLineFeatureType.General;}//theLabelClass.MaplexLabelPlacementProperties.LinePlacementMethod = MaplexLinePlacementMethod.CenteredPerpendicularOnLine;lyrDefn.LabelClasses=listLabelClasses.ToArray();//Set the labelClasses backfeatureLayer.SetDefinition(lyrDefn);//set the layer's definition});
Modify the Placement/Position of labels - Polygon geometry
varmap=MapView.Active?.Map;if(map==null)return;awaitQueuedTask.Run(()=>{//Get the layer's definitionvarlyrDefn=featureLayer.GetDefinition()asCIMFeatureLayer;//Get the label classes - we need the first onevarlistLabelClasses=lyrDefn.LabelClasses.ToList();vartheLabelClass=listLabelClasses.FirstOrDefault();//Modify label Placement//Check if the label engine is Maplex or standard.CIMGeneralPlacementPropertieslabelEngine=map.GetDefinition().GeneralPlacementProperties;if(labelEngineisCIMStandardGeneralPlacementProperties){//Current labeling engine is Standard Labeling enginetheLabelClass.StandardLabelPlacementProperties.PolygonPlacementMethod=StandardPolygonPlacementMethod.AlwaysHorizontal;theLabelClass.StandardLabelPlacementProperties.PlaceOnlyInsidePolygon=true;}else{//Current labeling engine is Maplex labeling enginetheLabelClass.MaplexLabelPlacementProperties.PolygonFeatureType=MaplexPolygonFeatureType.LandParcel;theLabelClass.MaplexLabelPlacementProperties.AvoidPolygonHoles=true;theLabelClass.MaplexLabelPlacementProperties.PolygonPlacementMethod=MaplexPolygonPlacementMethod.HorizontalInPolygon;theLabelClass.MaplexLabelPlacementProperties.CanPlaceLabelOutsidePolygon=true;}lyrDefn.LabelClasses=listLabelClasses.ToArray();//Set the labelClasses backfeatureLayer.SetDefinition(lyrDefn);//set the layer's definition//set the label's visiblityfeatureLayer.SetLabelVisibility(true);});
Modify Orientation of a label using the MaplexEngine - Points and Polygon geometry
varmap=MapView.Active?.Map;if(map==null)return;awaitQueuedTask.Run(()=>{//Check if the label engine is Maplex or standard.CIMGeneralPlacementPropertieslabelEngine=map.GetDefinition().GeneralPlacementProperties;if(labelEngineisCIMStandardGeneralPlacementProperties){return;}//Get the layer's definitionvarlyrDefn=featureLayer.GetDefinition()asCIMFeatureLayer;//Get the label classes - we need the first onevarlistLabelClasses=lyrDefn.LabelClasses.ToList();vartheLabelClass=listLabelClasses.FirstOrDefault();//Modify label OrientationtheLabelClass.MaplexLabelPlacementProperties.GraticuleAlignment=true;theLabelClass.MaplexLabelPlacementProperties.GraticuleAlignmentType=MaplexGraticuleAlignmentType.Curved;lyrDefn.LabelClasses=listLabelClasses.ToArray();//Set the labelClasses backfeatureLayer.SetDefinition(lyrDefn);//set the layer's definition});
Modify Orientation of a label using the MaplexEngine - Line geometry
varmap=MapView.Active?.Map;if(map==null)return;awaitQueuedTask.Run(()=>{//Check if the label engine is Maplex or standard.CIMGeneralPlacementPropertieslabelEngine=map.GetDefinition().GeneralPlacementProperties;if(labelEngineisCIMStandardGeneralPlacementProperties){return;}//Get the layer's definitionvarlyrDefn=featureLayer.GetDefinition()asCIMFeatureLayer;//Get the label classes - we need the first onevarlistLabelClasses=lyrDefn.LabelClasses.ToList();vartheLabelClass=listLabelClasses.FirstOrDefault();//Modify label OrientationtheLabelClass.MaplexLabelPlacementProperties.AlignLabelToLineDirection=true;lyrDefn.LabelClasses=listLabelClasses.ToArray();//Set the labelClasses backfeatureLayer.SetDefinition(lyrDefn);//set the layer's definition});
Modify label Rotation - Point geometry
varmap=MapView.Active?.Map;if(map==null)return;awaitQueuedTask.Run(()=>{//Check if the label engine is Maplex or standard.CIMGeneralPlacementPropertieslabelEngine=map.GetDefinition().GeneralPlacementProperties;if(labelEngineisCIMStandardGeneralPlacementProperties){return;}//Get the layer's definitionvarlyrDefn=featureLayer.GetDefinition()asCIMFeatureLayer;//Get the label classes - we need the first onevarlistLabelClasses=lyrDefn.LabelClasses.ToList();vartheLabelClass=listLabelClasses.FirstOrDefault();//Modify label RotationCIMMaplexRotationPropertiesrotationProperties=newCIMMaplexRotationProperties{Enable=true,//Enable rotationRotationField="ELEVATION",//Field that is used to define rotation angleAdditionalAngle=15,//Additional rotationRotationType=MaplexLabelRotationType.Arithmetic,AlignmentType=MaplexRotationAlignmentType.Perpendicular,AlignLabelToAngle=true};theLabelClass.MaplexLabelPlacementProperties.RotationProperties=rotationProperties;lyrDefn.LabelClasses=listLabelClasses.ToArray();//Set the labelClasses backfeatureLayer.SetDefinition(lyrDefn);//set the layer's definition});
Spread labels across Polygon geometry
varmap=MapView.Active?.Map;if(map==null)return;awaitQueuedTask.Run(()=>{//Check if the label engine is Maplex or standard.CIMGeneralPlacementPropertieslabelEngine=map.GetDefinition().GeneralPlacementProperties;if(labelEngineisCIMStandardGeneralPlacementProperties){return;}//Get the layer's definitionvarlyrDefn=featureLayer.GetDefinition()asCIMFeatureLayer;//Get the label classes - we need the first onevarlistLabelClasses=lyrDefn.LabelClasses.ToList();vartheLabelClass=listLabelClasses.FirstOrDefault();//Spread Labels (words and characters to fill feature)// Spread words to fill featuretheLabelClass.MaplexLabelPlacementProperties.SpreadWords=true;//Spread Characters to a fixed limit of 50%theLabelClass.MaplexLabelPlacementProperties.SpreadCharacters=true;theLabelClass.MaplexLabelPlacementProperties.MaximumCharacterSpacing=50.0;lyrDefn.LabelClasses=listLabelClasses.ToArray();//Set the labelClasses backfeatureLayer.SetDefinition(lyrDefn);//set the layer's definition});
Modify label's Leader Line Anchor point properties - Polygon geometry
varmap=MapView.Active?.Map;if(map==null)return;awaitQueuedTask.Run(()=>{//Check if the label engine is Maplex or standard.CIMGeneralPlacementPropertieslabelEngine=map.GetDefinition().GeneralPlacementProperties;if(labelEngineisCIMStandardGeneralPlacementProperties){return;}//Get the layer's definitionvarlyrDefn=featureLayer.GetDefinition()asCIMFeatureLayer;//Get the label classes - we need the first onevarlistLabelClasses=lyrDefn.LabelClasses.ToList();vartheLabelClass=listLabelClasses.FirstOrDefault();//If TextSymbol is a call-out the leader line anchor point can be modifiedtheLabelClass.MaplexLabelPlacementProperties.PolygonAnchorPointType=MaplexAnchorPointType.Perimeter;lyrDefn.LabelClasses=[..listLabelClasses];//Set the labelClasses backfeatureLayer.SetDefinition(lyrDefn);//set the layer's definition});