/// <summary>
        /// Renders a feature layer using an unclassed color gradient.
        /// ![cb-unclassed.png](http://Esri.github.io/arcgis-pro-sdk/images/Renderers/cb-unclassed.png "Class breaks unclassed renderer.")
        /// </summary>
        /// <returns>
        /// </returns>
        internal static Task UnclassedRenderer()
        {
            //Check feature layer name
            //Code works with the USDemographics feature layer available with the ArcGIS Pro SDK Sample data
            var featureLayer = MapView.Active.Map.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");
                return(Task.FromResult(0));
            }
            return(QueuedTask.Run(() =>
            {
                //Gets the first numeric field of the feature layer
                var firstNumericFieldOfFeatureLayer = SDKHelpers.GetNumericField(featureLayer);
                //Gets the min and max value of the field
                var labels = SDKHelpers.GetFieldMinMax(featureLayer, firstNumericFieldOfFeatureLayer);
                UnclassedColorsRendererDefinition ucDef = new UnclassedColorsRendererDefinition()
                {
                    Field = firstNumericFieldOfFeatureLayer,
                    ColorRamp = SDKHelpers.GetColorRamp(),
                    LowerColorStop = Convert.ToDouble(labels.Item1),
                    UpperColorStop = Convert.ToDouble(labels.Item2),
                    UpperLabel = labels.Item2,
                    LowerLabel = labels.Item1,
                };
                CIMClassBreaksRenderer renderer = (CIMClassBreaksRenderer)featureLayer.CreateRenderer(ucDef);
                featureLayer?.SetRenderer(renderer);
            }));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Renders a feature layer using unique values from one or multiple fields
        /// </summary>
        /// <remarks>
        /// ![Unique Value renderer](http://Esri.github.io/arcgis-pro-sdk/images/Renderers/unique-value.png)
        /// </remarks>
        /// <returns>
        /// ![Unique Value renderer](http://Esri.github.io/arcgis-pro-sdk/images/Renderers/unique-value.png)
        /// </returns>
        internal static Task UniqueValueRendererAsync()
        {
            //Check feature layer name
            //Code works with the USDemographics feature layer available with the ArcGIS Pro SDK Sample data
            var featureLayer = MapView.Active.Map.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");
                return(Task.FromResult(0));
            }
            return(QueuedTask.Run(() =>
            {
                //construct unique value renderer definition
                UniqueValueRendererDefinition uvr = new
                                                    UniqueValueRendererDefinition()
                {
                    ValueFields = new List <string> {
                        SDKHelpers.GetDisplayField(featureLayer)
                    },                                     //multiple fields in the array if needed.
                    ColorRamp = SDKHelpers.GetColorRamp(), //Specify color ramp
                };

                //Creates a "Renderer"
                var cimRenderer = featureLayer.CreateRenderer(uvr);

                //Sets the renderer to the feature layer
                featureLayer.SetRenderer(cimRenderer);
            }));
        }
 /// <summary>
 /// Renders a feature layer using graduated colors to draw quantities. The outline width is varied based on attributes.
 /// ![graduatedColorOutline.png](http://Esri.github.io/arcgis-pro-sdk/images/Renderers/graduatedColorOutline.png "Graduated colors with natural breaks renderer.")
 /// </summary>
 /// <param name="featureLayer"></param>
 /// <returns></returns>
 internal static Task CBRendererGraduatedColorsOutline(FeatureLayer featureLayer)
 {
     return(QueuedTask.Run(() =>
     {
         //Gets the first numeric field of the feature layer
         var firstNumericFieldOfFeatureLayer = SDKHelpers.GetNumericField(featureLayer);
         //Gets the min and max value of the field
         var minMax = SDKHelpers.GetFieldMinMax(featureLayer, firstNumericFieldOfFeatureLayer);
         GraduatedColorsRendererDefinition gcDef = new GraduatedColorsRendererDefinition()
         {
             ClassificationField = SDKHelpers.GetNumericField(featureLayer),
             ClassificationMethod = ClassificationMethod.NaturalBreaks,
             BreakCount = 5,
             ColorRamp = SDKHelpers.GetColorRamp()
         };
         CIMClassBreaksRenderer renderer = (CIMClassBreaksRenderer)featureLayer.CreateRenderer(gcDef);
         //Create array of CIMVisualVariables to hold the outline information.
         var visualVariables = new CIMVisualVariable[] {
             new CIMSizeVisualVariable
             {
                 ValueExpressionInfo = new CIMExpressionInfo
                 {
                     Title = "Custom",
                     Expression = "$feature.AREA",
                     ReturnType = ExpressionReturnType.Default
                 },
                 AuthoringInfo = new CIMVisualVariableAuthoringInfo
                 {
                     MinSliderValue = Convert.ToDouble(minMax.Item1),
                     MaxSliderValue = Convert.ToDouble(minMax.Item2),
                     ShowLegend = false,
                     Heading = firstNumericFieldOfFeatureLayer
                 },
                 VariableType = SizeVisualVariableType.Graduated,
                 Target = "outline",
                 MinSize = 1,
                 MaxSize = 13,
                 MinValue = Convert.ToDouble(minMax.Item1),
                 MaxValue = Convert.ToDouble(minMax.Item2)
             },
         };
         renderer.VisualVariables = visualVariables;
         featureLayer?.SetRenderer(renderer);
     }));
 }