예제 #1
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);
            }));
        }
예제 #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>
        /// <param name="featureLayer"></param>
        /// <returns>
        /// ![Unique Value renderer](http://Esri.github.io/arcgis-pro-sdk/images/Renderers/unique-value.png)
        /// </returns>
        internal static Task UniqueValueRendererAsync(FeatureLayer featureLayer)
        {
            return(QueuedTask.Run(() =>
            {
                //construct unique value renderer definition
                UniqueValueRendererDefinition uvr = new
                                                    UniqueValueRendererDefinition()
                {
                    ValueFields = new 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);
            }));
        }