| Exception | Description |
|---|---|
| ArcGIS.Core.CalledOnWrongThreadException | This property must be called within the lambda passed to QueuedTask.Run |
{
//Note: Must be on QueuedTask.Run
//Build geometry
List<Coordinate2D> plCoords = new List<Coordinate2D>();
plCoords.Add(new Coordinate2D(1, 8.5));
plCoords.Add(new Coordinate2D(1.66, 9));
plCoords.Add(new Coordinate2D(2.33, 8.1));
plCoords.Add(new Coordinate2D(3, 8.5));
Polyline linePl = PolylineBuilderEx.CreatePolyline(plCoords);
//Reference a line symbol in a style
var ProjectStyles = Project.Current.GetItems<StyleProjectItem>();
StyleProjectItem style = ProjectStyles.First(x => x.Name == "ArcGIS 2D");
var symStyle = style.SearchSymbols(StyleItemType.LineSymbol, "Line with 2 Markers")[0];
CIMLineSymbol lineSym = symStyle.Symbol as CIMLineSymbol;
lineSym.SetSize(20);
//Set symbology, create and add element to layout
//CIMLineSymbol lineSym = SymbolFactory.Instance.ConstructLineSymbol(ColorFactory.Instance.BlueRGB, 4.0, SimpleLineStyle.Solid);
ElementFactory.Instance.CreateGraphicElement(
layout, linePl, lineSym, "New Line");
}
{
//Note: Must be on QueuedTask.Run(() => { ...
//Build geometry
Coordinate2D coord2D = new Coordinate2D(2.0, 10.0);
//Reference a point symbol in a style
StyleProjectItem stylePrjItm = Project.Current.GetItems<StyleProjectItem>()
.FirstOrDefault(item => item.Name == "ArcGIS 2D");
SymbolStyleItem symStyleItm = stylePrjItm.SearchSymbols(
StyleItemType.PointSymbol, "City Hall")[0];
CIMPointSymbol pointSym = symStyleItm.Symbol as CIMPointSymbol;
pointSym.SetSize(50);
var elemInfo = new ElementInfo()
{
CustomProperties = new List<CIMStringMap>() {
new CIMStringMap() { Key = "Key1", Value = "Value1"},
new CIMStringMap() { Key = "Key2", Value = "Value2"}
},
Anchor = Anchor.TopRightCorner,
Rotation = 45.0
};
var graphic = GraphicFactory.Instance.CreateSimpleGraphic(
coord2D.ToMapPoint(), pointSym);
ElementFactory.Instance.CreateGraphicElement(
layout, graphic, "New Point", true, elemInfo);
}
{
//Note: call within QueuedTask.Run()
CIMSymbol symbolForSwatch = SymbolFactory.Instance.ConstructPointSymbol(ColorFactory.Instance.GreenRGB, 1.0, SimpleMarkerStyle.Circle);
//You can generate a swatch for a text symbols also.
var si = new SymbolStyleItem()
{
Symbol = symbolForSwatch,
PatchHeight = 64,
PatchWidth = 64
};
}
{
//Note: Needs QueuedTask to run
//Get simple renderer from the feature layer
CIMSimpleRenderer currentRenderer = featureLayer.GetRenderer() as CIMSimpleRenderer;
if (currentRenderer == null)
return;
//Get symbol from the SymbolStyleItem
CIMSymbol symbolToApply = symbolStyleItem.Symbol;
//Set symbol's real world setting to be the same as that of the feature layer
symbolToApply.SetRealWorldUnits(featureLayer.UsesRealWorldSymbolSizes);
//Update the symbol of the current simple renderer
currentRenderer.Symbol = symbolToApply.MakeSymbolReference();
//Update the feature layer renderer
featureLayer.SetRenderer(currentRenderer);
}
{
//Get the ArcGIS 2D System style from the Project
var arcGIS2DStyle =
Project.Current.GetItems<StyleProjectItem>().FirstOrDefault(s => s.Name == "ArcGIS 2D");
//Note: Needs QueuedTask to run
//Search for the symbolName style items within the ArcGIS 2D style project item.
var items = arcGIS2DStyle.SearchSymbols(StyleItemType.PointSymbol, "Circle 1");
//Gets the CIMSymbol
CIMSymbol symbolToUse = items.FirstOrDefault().Symbol;
//Get the renderer of the point feature layer
CIMSimpleRenderer renderer = featureLayer.GetRenderer() as CIMSimpleRenderer;
//Set symbol's real world setting to be the same as that of the feature layer
symbolToUse.SetRealWorldUnits(featureLayer.UsesRealWorldSymbolSizes);
//Apply the symbol to the feature layer's current renderer
renderer.Symbol = symbolToUse.MakeSymbolReference();
//Apply the renderer to the feature layer
featureLayer.SetRenderer(renderer);
}
Target Platforms: Windows 11 Home, Pro, Enterprise (64 bit)