Returns a collection of symbol style items that satisfy the search criteria. This method must be called on the MCT. Use QueuedTask.Run.
Create Line Element
{
var project = Project.Current;
await 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.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");
});
}
Create Point Element
{
var project = Project.Current;
await QueuedTask.Run(() =>
{
//Build geometry
Coordinate2D coord2D = new Coordinate2D(2.0, 10.0);
//Reference a point symbol in a style
StyleProjectItem stylePrjItm = project.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);
});
}
Create point graphic with symbology
{
//Create a simple 2D point graphic and apply an existing point style item as the symbology.
var project = Project.Current;
await QueuedTask.Run(() =>
{
//Build 2D point geometry
Coordinate2D coord2D = new Coordinate2D(2.0, 10.0);
//(optionally) Reference a point symbol in a style
StyleProjectItem ptStylePrjItm = project.GetItems<StyleProjectItem>()
.FirstOrDefault(item => item.Name == "ArcGIS 2D");
SymbolStyleItem ptSymStyleItm = ptStylePrjItm.SearchSymbols(
StyleItemType.PointSymbol, "City Hall")[0];
CIMPointSymbol pointSym = ptSymStyleItm.Symbol as CIMPointSymbol;
pointSym.SetSize(50);
//Set symbology, create and add element to layout
//An alternative simple symbol is also commented out below.
//This would eliminate the four optional lines of code above that
//reference a style.
//CIMPointSymbol pointSym = SymbolFactory.Instance.ConstructPointSymbol(
// ColorFactory.Instance.RedRGB, 25.0, SimpleMarkerStyle.Star);
GraphicElement ptElm = ElementFactory.Instance.CreateGraphicElement(
layout, coord2D.ToMapPoint(), pointSym);
ptElm.SetName("New Point");
});
}
Create line graphic with symbology
{
//Create a simple 2D line graphic and apply an existing line
//style item as the symbology.
var project = Project.Current;
await QueuedTask.Run(() =>
{
//Build 2d line 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);
//(optionally) Reference a line symbol in a style
StyleProjectItem lnStylePrjItm = project.GetItems<StyleProjectItem>()
.FirstOrDefault(item => item.Name == "ArcGIS 2D");
SymbolStyleItem lnSymStyleItm = lnStylePrjItm.SearchSymbols(
StyleItemType.LineSymbol, "Line with 2 Markers")[0];
CIMLineSymbol lineSym = lnSymStyleItm.Symbol as CIMLineSymbol;
lineSym.SetSize(20);
//Set symbology, create and add element to layout
//An alternative simple symbol is also commented out below.
//This would eliminate the four optional lines of code above that
//reference a style.
//
//CIMLineSymbol lineSym = SymbolFactory.Instance.ConstructLineSymbol(
// ColorFactory.Instance.BlueRGB, 4.0, SimpleLineStyle.Solid);
GraphicElement lineElm = ElementFactory.Instance.CreateGraphicElement(
layout, linePl, lineSym);
lineElm.SetName("New Line");
});
}
How to search for point symbols in a style
{
//Search for point symbols
//Note: styleProjectItem was created above in the variable initialization section
//Search for point symbols
await QueuedTask.Run(() => styleProjectItem.SearchSymbols(StyleItemType.PointSymbol, "searchString"));
}
How to search for line symbols in a style
{
//Note: styleProjectItem was created above in the variable initialization section
//Search for line symbols
await QueuedTask.Run(() => styleProjectItem.SearchSymbols(StyleItemType.LineSymbol, "searchString"));
}
How to search for polygon symbols in a style
{
//Note: styleProjectItem was created above in the variable initialization section
//Search for polygon symbols
await QueuedTask.Run(() => styleProjectItem.SearchSymbols(StyleItemType.PolygonSymbol, "searchString"));
}
How to apply a point symbol from a style to a feature layer
{
//Get the ArcGIS 2D System style from the Project
var arcGIS2DStyle =
Project.Current.GetItems<StyleProjectItem>().FirstOrDefault(s => s.Name == "ArcGIS 2D");
await QueuedTask.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);
});
}
Simple Renderer for a Line feature layer using a style from a StyleProjectItem.
/// <summary>
/// Renders a Line feature layer using a style from a StyleProjectItem.
/// 
/// </summary>
{
//Check feature layer name
//Code works with the USDemographics feature layer available with the ArcGIS Pro SDK Sample data
var featureLayer = activeMap.GetLayersAsFlattenedList().OfType<FeatureLayer>().FirstOrDefault(f => f.Name == "U.S. National Transportation Atlas Interstate Highways");
if (featureLayer == null)
{
MessageBox.Show("This renderer works with the U.S. National Transportation Atlas Interstate Highways feature layer available with the ArcGIS Pro SDK Sample data", "Data missing");
}
//Get all styles in the project
var styleProjectItem2D = project.GetItems<StyleProjectItem>().FirstOrDefault(s => s.Name == "ArcGIS 2D");
//Get a specific style in the project by name
var arrowLineSymbol = styleProjectItem2D.SearchSymbols(StyleItemType.LineSymbol, "Arrow Line 2 (Mid)")[0];
if (arrowLineSymbol == null)
{
return;
}
await QueuedTask.Run(() =>
{
//Get the layer's current renderer
var renderer = featureLayer?.GetRenderer() as CIMSimpleRenderer;
//Update the symbol of the current simple renderer
renderer.Symbol = arrowLineSymbol.Symbol.MakeSymbolReference();
//Update the feature layer renderer
featureLayer.SetRenderer(renderer);
});
}
Snippet Creates a point callout text symbol
/// <summary>
/// Creates a highway shield callout text symbol. The [CIMPointSymbolCallout](https://doc.esri.com/en/arcgis-pro/latest/sdk/api-reference/#topic4116.html) created is a highway shield point symbol from the ArcGIS 2D style.
/// 
/// </summary>
{
//Get a Shield symbolStyleItem from ArcGIS 2D StyleProjectitem
var symbolStyleItem = await GetPointSymbolAsync(project, "ArcGIS 2D", "Shield 1");
await QueuedTask.Run(() =>
{
//create a text symbol
var textSymbolPointCallout = SymbolFactory.Instance.ConstructTextSymbol(ColorFactory.Instance.WhiteRGB, 6, "Tahoma", "Bold");
//Create a call out
var shieldCalloutSymbol = new CIMPointSymbolCallout();
//assign the point symbol (Highway shield) to the callout
shieldCalloutSymbol.PointSymbol = symbolStyleItem.Symbol as CIMPointSymbol;
shieldCalloutSymbol.PointSymbol.SetSize(18.0); //set symbol size
//Assign the callout to the text symbol
textSymbolPointCallout.Callout = shieldCalloutSymbol;
});
//Refer to the snippet "How to apply a Text Symbol to labels of a layer" below to see how to apply this text symbol to a label class
//Gets a Highway point symbol from a style
static Task<SymbolStyleItem> GetPointSymbolAsync(Project project, string styleProjectItemName, string symbolStyleName)
{
return QueuedTask.Run(() =>
{
var style2DProjectItem = project.GetItems<StyleProjectItem>().Where(p => p.Name == styleProjectItemName).FirstOrDefault();
var symbolStyle = style2DProjectItem.SearchSymbols(StyleItemType.PointSymbol, symbolStyleName).FirstOrDefault();
return symbolStyle;
});
}
}
Target Platforms: Windows 11 Home, Pro, Enterprise (64 bit)
ArcGIS Pro version: 3.0 or higher.