Parameters
- color
- ArcGIS.Core.CIM.CIMColor
- width
- The width of stroke to construct.
- lineStyle
- SimpleLineStyle
{
//Create a simple 2D rectangle graphic and apply simple fill and
//outline symbols.
await QueuedTask.Run(() =>
{
//Build 2D envelope geometry
Coordinate2D rec_ll = new Coordinate2D(1.0, 4.75);
Coordinate2D rec_ur = new Coordinate2D(3.0, 5.75);
Envelope rec_env = EnvelopeBuilderEx.CreateEnvelope(rec_ll, rec_ur);
//Set symbology, create and add element to layout
CIMStroke outline = SymbolFactory.Instance.ConstructStroke(
ColorFactory.Instance.BlackRGB, 5.0, SimpleLineStyle.Solid);
CIMPolygonSymbol polySym = SymbolFactory.Instance.ConstructPolygonSymbol(
ColorFactory.Instance.GreenRGB, SimpleFillStyle.DiagonalCross, outline);
GraphicElement recElm = ElementFactory.Instance.CreateGraphicElement(
layout, rec_env, polySym, "New Rectangle");
//Or use Predefined shape
GraphicElement recElm2 = ElementFactory.Instance.CreatePredefinedShapeGraphicElement(
layout, PredefinedShape.Rectangle, rec_env, polySym,
"New Rectangle2");
});
}
{
CIMStroke outline = SymbolFactory.Instance.ConstructStroke(ColorFactory.Instance.BlueRGB, 2.0, SimpleLineStyle.Solid);
CIMPolygonSymbol fillWithOutline = SymbolFactory.Instance.ConstructPolygonSymbol(ColorFactory.Instance.RedRGB, SimpleFillStyle.Solid, outline);
}
{
//create marker from the Font, char index,size,color
await QueuedTask.Run(() =>
{
var cimMarker = SymbolFactory.Instance.ConstructMarker(125, "Wingdings 3", "Regular", 6, ColorFactory.Instance.BlueRGB) as CIMCharacterMarker;
var polygonMarker = cimMarker.Symbol;
//modifying the polygon's outline and fill
//This is the outline
polygonMarker.SymbolLayers[0] = SymbolFactory.Instance.ConstructStroke(ColorFactory.Instance.GreenRGB, 2, SimpleLineStyle.Solid);
//This is the fill
polygonMarker.SymbolLayers[1] = SymbolFactory.Instance.ConstructSolidFill(ColorFactory.Instance.BlueRGB);
//create a symbol from the marker
//Note this overload of ConstructPointSymbol does not need to be run within QueuedTask.Run.
var pointSymbol = SymbolFactory.Instance.ConstructPointSymbol(cimMarker);
});
}
{
var mapToClip = MapView.Active.Map;
await QueuedTask.Run(() =>
{
//A layer to use for the clip extent
var lyrOfInterest = mapToClip.GetLayersAsFlattenedList().OfType<FeatureLayer>().Where(l => l.Name == "TestPoly").FirstOrDefault();
//Get the polygon to use to clip the map
var extent = lyrOfInterest.QueryExtent();
var polygonForClipping = PolygonBuilderEx.CreatePolygon(extent);
//Clip the map using the layer's extent
mapToClip.SetClipGeometry(polygonForClipping,
SymbolFactory.Instance.ConstructLineSymbol(
SymbolFactory.Instance.ConstructStroke(
ColorFactory.Instance.BlueRGB, 2.0, SimpleLineStyle.Dash)));
});
}
{
await QueuedTask.Run(() =>
{
//get the first line element in the layer
var ge = graphicsLayer.FindElement("Line 10") as GraphicElement;
var graphic = ge.GetGraphic();
if (graphic is CIMLineGraphic lineGraphic)
{
//change its symbol
lineGraphic.Symbol =
SymbolFactory.Instance.ConstructLineSymbol(
SymbolFactory.Instance.ConstructStroke(
ColorFactory.Instance.BlueRGB, 2, SimpleLineStyle.DashDot)).MakeSymbolReference();
//apply the change
ge.SetGraphic(lineGraphic);
}
});
}
/// <summary> /// Renders a Polygon feature layer using a single symbol. ///  /// </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 == "USDemographics"); if (featureLayer == null) { MessageBox.Show("This renderer works with the USDemographics feature layer available with the ArcGIS Pro SDK Sample data", "Data missing"); } //Creating a polygon with a red fill and blue outline. CIMStroke outline = SymbolFactory.Instance.ConstructStroke( ColorFactory.Instance.BlueRGB, 2.0, SimpleLineStyle.Solid); CIMPolygonSymbol fillWithOutline = SymbolFactory.Instance.ConstructPolygonSymbol( ColorFactory.Instance.CreateRGBColor(255, 190, 190), SimpleFillStyle.Solid, outline); await QueuedTask.Run(() => { //Get the layer's current renderer CIMSimpleRenderer renderer = featureLayer.GetRenderer() as CIMSimpleRenderer; //Update the symbol of the current simple renderer renderer.Symbol = fillWithOutline.MakeSymbolReference(); //Update the feature layer renderer featureLayer.SetRenderer(renderer); }); }
/// <summary> /// Creates a point symbol with custom fill and outline ///  /// </summary> { //Note: Run withing QueuedTask var circlePtCustomFileOutlineSymbol = SymbolFactory.Instance.ConstructPointSymbol(ColorFactory.Instance.BlueRGB, 6, SimpleMarkerStyle.Circle); //Modifying this point symbol with the attributes we want. //getting the marker that is used to render the symbol var marker = circlePtCustomFileOutlineSymbol.SymbolLayers[0] as CIMVectorMarker; //Getting the polygon symbol layers components in the marker var polySymbol = marker.MarkerGraphics[0].Symbol as CIMPolygonSymbol; //modifying the polygon's outline and width per requirements polySymbol.SymbolLayers[0] = SymbolFactory.Instance.ConstructStroke(ColorFactory.Instance.BlackRGB, 2, SimpleLineStyle.Solid); //This is the outline polySymbol.SymbolLayers[1] = SymbolFactory.Instance.ConstructSolidFill(ColorFactory.Instance.GreenRGB); //This is the fill //To apply the symbol to a point feature layer //var renderer = pointLayer.GetRenderer() as CIMSimpleRenderer; //renderer.Symbol = circlePtCustomFileOutlineSymbol.MakeSymbolReference(); //pointLayer.SetRenderer(renderer); }
/// <summary> /// Create a polygon symbol with a diagonal cross hatch fill. <br/> ///  /// </summary> { var trans = 50.0;//semi transparent CIMStroke outline = SymbolFactory.Instance.ConstructStroke(CIMColor.CreateRGBColor(0, 0, 0, trans), 2.0, SimpleLineStyle.Solid); //Stroke for the fill var solid = SymbolFactory.Instance.ConstructStroke(CIMColor.CreateRGBColor(255, 0, 0, trans), 1.0, SimpleLineStyle.Solid); //Mimic cross hatch CIMFill[] diagonalCross = { new CIMHatchFill() { Enable = true, Rotation = 45.0, Separation = 5.0, LineSymbol = new CIMLineSymbol() { SymbolLayers = new CIMSymbolLayer[1] { solid } } }, new CIMHatchFill() { Enable = true, Rotation = -45.0, Separation = 5.0, LineSymbol = new CIMLineSymbol() { SymbolLayers = new CIMSymbolLayer[1] { solid } } } }; List<CIMSymbolLayer> symbolLayers = [ outline, .. diagonalCross ]; //This is the polygon symbol with a diagonal cross hatch fill CIMPolygonSymbol diagonalCrossHatchFillSymbol = new() { SymbolLayers = [.. symbolLayers] }; //To apply the symbol to a polygon feature layer //var renderer = theLayer.GetRenderer() as CIMSimpleRenderer; //renderer.Symbol = diagonalCrossHatchFillSymbol.MakeSymbolReference(); //theLayer.SetRenderer(renderer); }
/// <summary> /// Create a polygon symbol using the ConstructHatchFill method . <br/> ///  /// </summary> { CIMStroke lineStroke = SymbolFactory.Instance.ConstructStroke(CIMColor.CreateRGBColor(51, 51, 51, 60), 4, SimpleLineStyle.Solid); //gradient var hatchFill = SymbolFactory.Instance.ConstructHatchFill(lineStroke, 45, 6, 0); List<CIMSymbolLayer> symbolLayers = new() { hatchFill }; //This is the polygon symbol with a diagonal cross hatch fill CIMPolygonSymbol crossHatchPolygonSymbol = new CIMPolygonSymbol() { SymbolLayers = symbolLayers.ToArray() }; //To apply the symbol to a polygon feature layer //var renderer = theLayer.GetRenderer() as CIMSimpleRenderer; //renderer.Symbol = crossHatchPolygonSymbol.MakeSymbolReference(); //theLayer.SetRenderer(renderer); }
/// <summary> /// Create a polygon symbol with a dash dot fill. <br/> ///  /// </summary> { //Note: Run withing QueuedTask var trans = 50.0;//semi transparent CIMStroke outline = SymbolFactory.Instance.ConstructStroke(CIMColor.CreateRGBColor(0, 0, 0, trans), 2.0, SimpleLineStyle.Solid); //Stroke for the fill var dashDot = SymbolFactory.Instance.ConstructStroke(ColorFactory.Instance.RedRGB, 1.0, SimpleLineStyle.DashDotDot); //Mimic cross hatch CIMFill[] solidColorHatch = { new CIMHatchFill() { Enable = true, Rotation = 0.0, Separation = 2.5, LineSymbol = new CIMLineSymbol(){SymbolLayers = new CIMSymbolLayer[1] {dashDot } } }, new CIMSolidFill() { Enable = true, Color = ColorFactory.Instance.CreateRGBColor(255, 255, 0) }, }; List<CIMSymbolLayer> symbolLayers = [outline, .. solidColorHatch]; //This is the polygon symbol with a dash dot fill CIMPolygonSymbol dashDotFillPolygon = new CIMPolygonSymbol() { SymbolLayers = symbolLayers.ToArray() }; //To apply the symbol to a polygon feature layer //var renderer = theLayer.GetRenderer() as CIMSimpleRenderer; //renderer.Symbol = dashDotFillPolygon.MakeSymbolReference(); //theLayer.SetRenderer(renderer); }
/// <summary> /// Create a polygon symbol with a gradient color fill. <br/> ///  /// 1. Create a solid colored stroke with 50% transparency /// 1. Create a fill using gradient colors red through green /// 1. Apply both the stroke and fill as a symbol layer array to the new PolygonSymbol /// </summary> { //Note: Run withing QueuedTask var trans = 50.0;//semi transparent CIMStroke outline = SymbolFactory.Instance.ConstructStroke(CIMColor.CreateRGBColor(0, 0, 0, trans), 2.0, SimpleLineStyle.Solid); //Mimic cross hatch CIMFill solidColorHatch = new CIMGradientFill() { ColorRamp = ColorFactory.Instance.ConstructColorRamp(ColorRampAlgorithm.LinearContinuous, ColorFactory.Instance.RedRGB, ColorFactory.Instance.GreenRGB) }; List<CIMSymbolLayer> symbolLayers = new List<CIMSymbolLayer> { outline, solidColorHatch }; CIMPolygonSymbol gradientColorFillPolygon = new CIMPolygonSymbol() { SymbolLayers = symbolLayers.ToArray() }; //To apply the symbol to a polygon feature layer //var renderer = theLayer.GetRenderer() as CIMSimpleRenderer; //renderer.Symbol = gradientColorFillPolygon.MakeSymbolReference(); //theLayer.SetRenderer(renderer); }
/// <summary> /// Create a polygon symbol using the ConstructGradientFill method. Constructs a gradient fill using the specified color ramp. <br/> ///  /// </summary> { //Note: Run withing QueuedTask //outine CIMStroke outline = SymbolFactory.Instance.ConstructStroke(CIMColor.CreateRGBColor(49, 49, 49), 2.0, SimpleLineStyle.Solid); //gradient fill using a color ramp var gradientFill = SymbolFactory.Instance.ConstructGradientFill(GetColorRamp(), GradientFillMethod.Linear); List<CIMSymbolLayer> symbolLayers = new List<CIMSymbolLayer> { outline, gradientFill }; CIMPolygonSymbol gradientColorRampSymbol = new CIMPolygonSymbol() { SymbolLayers = symbolLayers.ToArray() }; //To apply the symbol to a polygon feature layer //var renderer = theLayer.GetRenderer() as CIMSimpleRenderer; //renderer.Symbol = gradientColorRampSymbol.MakeSymbolReference(); //theLayer.SetRenderer(renderer); //Helper method to get a color ramp from the "ArcGIS Colors" style. static CIMColorRamp GetColorRamp() { //Get a ColorRamp StyleProjectItem style = Project.Current.GetItems<StyleProjectItem>().FirstOrDefault(s => s.Name == "ArcGIS Colors"); var colorRampList = style.SearchColorRamps("Heat Map 4 - Semitransparent"); CIMColorRamp colorRamp = colorRampList[0].ColorRamp; return colorRamp; } }
/// <summary> /// Constructs a picture fill with the specified parameters. ///  /// </summary> { //Note: Run withing QueuedTask CIMStroke outline = SymbolFactory.Instance.ConstructStroke(CIMColor.CreateRGBColor(110, 110, 110), 2.0, SimpleLineStyle.Solid); //picture var imgPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), @"Images\CaliforniaEmblem.png"); var pictureFill = SymbolFactory.Instance.ConstructPictureFill(imgPath, 64); List<CIMSymbolLayer> symbolLayers = new() { outline, pictureFill }; CIMPolygonSymbol pictureFillPolygonSymbol = new CIMPolygonSymbol() { SymbolLayers = symbolLayers.ToArray() }; //To apply the symbol to a polygon feature layer //var renderer = theLayer.GetRenderer() as CIMSimpleRenderer; //renderer.Symbol = pictureFillPolygonSymbol.MakeSymbolReference(); //theLayer.SetRenderer(renderer); }
/// <summary> /// Constructs a water fill of specific color, waterbody size and wave strength. This fill can be used on polygon feature classes in a Scene view only. ///  /// </summary> { //Note: Run withing QueuedTask CIMStroke outline = SymbolFactory.Instance.ConstructStroke(CIMColor.CreateRGBColor(49, 49, 49, 50.0), 2.0, SimpleLineStyle.Solid); var waterFill = SymbolFactory.Instance.ConstructWaterFill(CIMColor.CreateRGBColor(3, 223, 252), WaterbodySize.Large, WaveStrength.Rippled); List<CIMSymbolLayer> symbolLayers = new List<CIMSymbolLayer> { outline, waterFill }; CIMPolygonSymbol waterFillPolygonSymbol = new CIMPolygonSymbol() { SymbolLayers = symbolLayers.ToArray() }; //To apply the symbol to a polygon feature layer //var renderer = theLayer.GetRenderer() as CIMSimpleRenderer; //renderer.Symbol = waterFillPolygonSymbol.MakeSymbolReference(); //theLayer.SetRenderer(renderer); }
Target Platforms: Windows 11 Home, Pro, Enterprise (64 bit)