| Exception | Description |
|---|---|
| ArcGIS.Core.CalledOnWrongThreadException | This method or property must be called within the lambda passed to QueuedTask.Run. |
{
await QueuedTask.Run(() =>
{
//Get the map's definition
var mapDefn = map.GetDefinition();
//Get the Map's Maplex labelling engine properties
var mapDefnPlacementProps = mapDefn.GeneralPlacementProperties as CIMMaplexGeneralPlacementProperties;
//Define the abbreviations we need in an array
List<CIMMaplexDictionaryEntry> abbreviationDictionary = new List<CIMMaplexDictionaryEntry>
{
new CIMMaplexDictionaryEntry {
Abbreviation = "Hts",
Text = "Heights",
MaplexAbbreviationType = MaplexAbbreviationType.Ending
},
new CIMMaplexDictionaryEntry
{
Abbreviation = "Ct",
Text = "Text",
MaplexAbbreviationType = MaplexAbbreviationType.Ending
}
//etc
};
//The Maplex Dictionary - can hold multiple Abbreviation collections
var maplexDictionary = new List<CIMMaplexDictionary>
{
new CIMMaplexDictionary {
Name = "NameEndingsAbbreviations",
MaplexDictionary = abbreviationDictionary.ToArray()
}
};
//Set the Maplex Label Engine Dictionary property to the Maplex Dictionary collection created above.
mapDefnPlacementProps.Dictionaries = maplexDictionary.ToArray();
//Set the Map definition
map.SetDefinition(mapDefn);
});
}
{
await QueuedTask.Run(() =>
{
//Creates Abbreviation dictionary and adds to Map Definition
//Refer to the " Create Abbreviation Dictionary in the Map Definition to a layer" snippet above
//Get the layer's definition
var lyrDefn = featureLayer.GetDefinition() as CIMFeatureLayer;
//Get the label classes - we need the first one
var listLabelClasses = lyrDefn.LabelClasses.ToList();
var theLabelClass = listLabelClasses.FirstOrDefault();
//Modify label Placement props to use abbreviation dictionary
CIMGeneralPlacementProperties labelEngine = map.GetDefinition().GeneralPlacementProperties;
//Get the dictionary from the map definition
theLabelClass.MaplexLabelPlacementProperties.DictionaryName = "NameEndingsAbbreviations";
theLabelClass.MaplexLabelPlacementProperties.CanAbbreviateLabel = true;
theLabelClass.MaplexLabelPlacementProperties.CanStackLabel = false;
//Set the labelClasses back
lyrDefn.LabelClasses = listLabelClasses.ToArray();
//set the layer's definition
featureLayer.SetDefinition(lyrDefn);
});
}
{
var map = MapView.Active?.Map;
if (map == null)
return;
await QueuedTask.Run(() =>
{
//Get the active map's definition - CIMMap.
var cimMap = map.GetDefinition();
//Get the labeling engine from the map definition
CIMGeneralPlacementProperties labelEngine = cimMap.GeneralPlacementProperties;
});
}
{
var map = MapView.Active?.Map;
if (map == null)
return;
await QueuedTask.Run(() =>
{
//Get the active map's definition - CIMMap.
var cimMap = map.GetDefinition();
//Get the labeling engine from the map definition
var cimGeneralPlacement = cimMap.GeneralPlacementProperties;
if (cimGeneralPlacement is CIMMaplexGeneralPlacementProperties)
{
//Current labeling engine is Maplex labeling engine
//Create a new standard label engine properties
var cimStandardPlacementProperties = new CIMStandardGeneralPlacementProperties();
//Set the CIMMap's GeneralPlacementProperties to the new label engine
cimMap.GeneralPlacementProperties = cimStandardPlacementProperties;
}
else
{
//Current labeling engine is Standard labeling engine
//Create a new Maplex label engine properties
var cimMaplexGeneralPlacementProperties = new CIMMaplexGeneralPlacementProperties();
//Set the CIMMap's GeneralPlacementProperties to the new label engine
cimMap.GeneralPlacementProperties = cimMaplexGeneralPlacementProperties;
}
//Set the map's definition
map.SetDefinition(cimMap);
});
}
{
var map = MapView.Active?.Map;
if (map == null)
return;
await QueuedTask.Run(() =>
{
//Get the layer's definition
var lyrDefn = featureLayer.GetDefinition() as CIMFeatureLayer;
//Get the label classes - we need the first one
var listLabelClasses = lyrDefn.LabelClasses.ToList();
var theLabelClass = listLabelClasses.FirstOrDefault();
//Modify label Placement
//Check if the label engine is Maplex or standard.
CIMGeneralPlacementProperties labelEngine =
map.GetDefinition().GeneralPlacementProperties;
if (labelEngine is CIMStandardGeneralPlacementProperties)
{
//Current labeling engine is Standard labeling engine
var lineLablePosition = new CIMStandardLineLabelPosition
{
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 back
featureLayer.SetDefinition(lyrDefn); //set the layer's definition
});
}
{
var map = MapView.Active?.Map;
if (map == null)
return;
await QueuedTask.Run(() =>
{
//Get the layer's definition
var lyrDefn = featureLayer.GetDefinition() as CIMFeatureLayer;
//Get the label classes - we need the first one
var listLabelClasses = lyrDefn.LabelClasses.ToList();
var theLabelClass = listLabelClasses.FirstOrDefault();
//Modify label Placement
//Check if the label engine is Maplex or standard.
CIMGeneralPlacementProperties labelEngine = map.GetDefinition().GeneralPlacementProperties;
if (labelEngine is CIMStandardGeneralPlacementProperties)
{
//Current labeling engine is Standard Labeling engine
theLabelClass.StandardLabelPlacementProperties.PolygonPlacementMethod =
StandardPolygonPlacementMethod.AlwaysHorizontal;
theLabelClass.StandardLabelPlacementProperties.PlaceOnlyInsidePolygon = true;
}
else
{
//Current labeling engine is Maplex labeling engine
theLabelClass.MaplexLabelPlacementProperties.PolygonFeatureType =
MaplexPolygonFeatureType.LandParcel;
theLabelClass.MaplexLabelPlacementProperties.AvoidPolygonHoles = true;
theLabelClass.MaplexLabelPlacementProperties.PolygonPlacementMethod =
MaplexPolygonPlacementMethod.HorizontalInPolygon;
theLabelClass.MaplexLabelPlacementProperties.CanPlaceLabelOutsidePolygon = true;
}
lyrDefn.LabelClasses = listLabelClasses.ToArray(); //Set the labelClasses back
featureLayer.SetDefinition(lyrDefn); //set the layer's definition
//set the label's visiblity
featureLayer.SetLabelVisibility(true);
});
}
{
var map = MapView.Active?.Map;
if (map == null)
return;
await QueuedTask.Run(() =>
{
//Check if the label engine is Maplex or standard.
CIMGeneralPlacementProperties labelEngine = map.GetDefinition().GeneralPlacementProperties;
if (labelEngine is CIMStandardGeneralPlacementProperties)
{
return;
}
//Get the layer's definition
var lyrDefn = featureLayer.GetDefinition() as CIMFeatureLayer;
//Get the label classes - we need the first one
var listLabelClasses = lyrDefn.LabelClasses.ToList();
var theLabelClass = listLabelClasses.FirstOrDefault();
//Modify label Orientation
theLabelClass.MaplexLabelPlacementProperties.GraticuleAlignment = true;
theLabelClass.MaplexLabelPlacementProperties.GraticuleAlignmentType = MaplexGraticuleAlignmentType.Curved;
lyrDefn.LabelClasses = listLabelClasses.ToArray(); //Set the labelClasses back
featureLayer.SetDefinition(lyrDefn); //set the layer's definition
});
}
{
var map = MapView.Active?.Map;
if (map == null)
return;
await QueuedTask.Run(() =>
{
//Check if the label engine is Maplex or standard.
CIMGeneralPlacementProperties labelEngine = map.GetDefinition().GeneralPlacementProperties;
if (labelEngine is CIMStandardGeneralPlacementProperties)
{
return;
}
//Get the layer's definition
var lyrDefn = featureLayer.GetDefinition() as CIMFeatureLayer;
//Get the label classes - we need the first one
var listLabelClasses = lyrDefn.LabelClasses.ToList();
var theLabelClass = listLabelClasses.FirstOrDefault();
//Modify label Orientation
theLabelClass.MaplexLabelPlacementProperties.AlignLabelToLineDirection = true;
lyrDefn.LabelClasses = listLabelClasses.ToArray(); //Set the labelClasses back
featureLayer.SetDefinition(lyrDefn); //set the layer's definition
});
}
{
var map = MapView.Active?.Map;
if (map == null)
return;
await QueuedTask.Run(() =>
{
//Check if the label engine is Maplex or standard.
CIMGeneralPlacementProperties labelEngine = map.GetDefinition().GeneralPlacementProperties;
if (labelEngine is CIMStandardGeneralPlacementProperties)
{
return;
}
//Get the layer's definition
var lyrDefn = featureLayer.GetDefinition() as CIMFeatureLayer;
//Get the label classes - we need the first one
var listLabelClasses = lyrDefn.LabelClasses.ToList();
var theLabelClass = listLabelClasses.FirstOrDefault();
//Modify label Rotation
CIMMaplexRotationProperties rotationProperties = new CIMMaplexRotationProperties
{
Enable = true, //Enable rotation
RotationField = "ELEVATION", //Field that is used to define rotation angle
AdditionalAngle = 15, //Additional rotation
RotationType = MaplexLabelRotationType.Arithmetic,
AlignmentType = MaplexRotationAlignmentType.Perpendicular,
AlignLabelToAngle = true
};
theLabelClass.MaplexLabelPlacementProperties.RotationProperties = rotationProperties;
lyrDefn.LabelClasses = listLabelClasses.ToArray(); //Set the labelClasses back
featureLayer.SetDefinition(lyrDefn); //set the layer's definition
});
}
{
var map = MapView.Active?.Map;
if (map == null)
return;
await QueuedTask.Run(() =>
{
//Check if the label engine is Maplex or standard.
CIMGeneralPlacementProperties labelEngine = map.GetDefinition().GeneralPlacementProperties;
if (labelEngine is CIMStandardGeneralPlacementProperties)
{
return;
}
//Get the layer's definition
var lyrDefn = featureLayer.GetDefinition() as CIMFeatureLayer;
//Get the label classes - we need the first one
var listLabelClasses = lyrDefn.LabelClasses.ToList();
var theLabelClass = listLabelClasses.FirstOrDefault();
//Spread Labels (words and characters to fill feature)
// Spread words to fill feature
theLabelClass.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 back
featureLayer.SetDefinition(lyrDefn); //set the layer's definition
});
}
{
var map = MapView.Active?.Map;
if (map == null)
return;
await QueuedTask.Run(() =>
{
//Check if the label engine is Maplex or standard.
CIMGeneralPlacementProperties labelEngine = map.GetDefinition().GeneralPlacementProperties;
if (labelEngine is CIMStandardGeneralPlacementProperties)
{
return;
}
//Get the layer's definition
var lyrDefn = featureLayer.GetDefinition() as CIMFeatureLayer;
//Get the label classes - we need the first one
var listLabelClasses = lyrDefn.LabelClasses.ToList();
var theLabelClass = listLabelClasses.FirstOrDefault();
//If TextSymbol is a call-out the leader line anchor point can be modified
theLabelClass.MaplexLabelPlacementProperties.PolygonAnchorPointType = MaplexAnchorPointType.Perimeter;
lyrDefn.LabelClasses = [.. listLabelClasses]; //Set the labelClasses back
featureLayer.SetDefinition(lyrDefn); //set the layer's definition
});
}
{
await QueuedTask.Run(() =>
{
var cimMap = activeMap.GetDefinition();
CIMTextSymbol simpleTextSymbol = SymbolFactory.Instance.ConstructTextSymbol(ColorFactory.Instance.GreenRGB, 8.5, "Corbel", "Regular");
var lyrDefn = theLayerToLabel.GetDefinition() as CIMFeatureLayer;
//Get the label classes - we need the first one
var listLabelClasses = lyrDefn.LabelClasses.ToList();
var theLabelClass = listLabelClasses.FirstOrDefault();
//Place all labels horizontally
theLabelClass.StandardLabelPlacementProperties.LineLabelPosition.Horizontal = true;
//theLabelClass.MaplexLabelPlacementProperties.AlignLabelToLineDirection = true;
//Set the label classes' symbol to the custom text symbol
theLabelClass.TextSymbol.Symbol = simpleTextSymbol;
lyrDefn.LabelClasses = listLabelClasses.ToArray(); //Set the labelClasses back
theLayerToLabel.SetDefinition(lyrDefn);
(theLayerToLabel as FeatureLayer).SetLabelVisibility(true);
});
}
Target Platforms: Windows 11 Home, Pro, Enterprise (64 bit)