// Create a unique value renderer by state sub-region name
        private async Task SetUniqueRenderer()
        {
            try
            {
                // Generate a unique value renderer on the server
                GenerateRendererTask generateRendererTask = new GenerateRendererTask(new Uri(LAYER_URL));

                UniqueValueDefinition uvDef = new UniqueValueDefinition()
                {
                    Fields = new string[] { "sub_region" }
                };
                uvDef.ColorRamps.Add(new ColorRamp()
                {
                    From = Colors.Purple, To = Colors.Yellow, Algorithm = Algorithm.LabLch
                });
                GenerateRendererParameter rendererParams = new GenerateRendererParameter()
                {
                    ClassificationDefinition = uvDef
                };

                var rendererResult = await generateRendererTask.GenerateRendererAsync(rendererParams);

                _graphicsLayer.Renderer = rendererResult.Renderer;
            }
            catch (Exception ex)
            {
                var _ = new MessageDialog(ex.Message, "Sample Error").ShowAsync();
            }
        }
Exemplo n.º 2
0
        // Create a unique value renderer by state sub-region name
        private async Task SetupSymbology()
        {
            try
            {
                // Generate a unique value renderer on the server
                GenerateRendererTask generateRendererTask = new GenerateRendererTask(new Uri(LAYER_URL));

                UniqueValueDefinition uvDef = new UniqueValueDefinition()
                {
                    Fields = new List <string> {
                        "sub_region"
                    }
                };
                uvDef.ColorRamps.Add(new ColorRamp()
                {
                    From = Colors.Purple, To = Colors.Yellow, Algorithm = Algorithm.LabLch
                });
                GenerateRendererParameters rendererParams = new GenerateRendererParameters()
                {
                    ClassificationDefinition = uvDef
                };

                var rendererResult = await generateRendererTask.GenerateRendererAsync(rendererParams);

                _graphicsOverlay.Renderer = rendererResult.Renderer;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Statistics Sample");
            }
        }
        private async Task GenerateRenderer(GenerateRendererParameters rendererParam)
        {
            GenerateRendererResult result = await generateRendererTask.GenerateRendererAsync(rendererParam);

            LayerDrawingOptions          layerDrawingOptions = null;
            LayerDrawingOptionCollection options             = null;

            // If this is the first execution of this sample create a new LayerDrawingOptionsCollection
            if (((ArcGISDynamicMapServiceLayer)map.Layers["USA"]).LayerDrawingOptions == null)
            {
                options = new LayerDrawingOptionCollection();

                // Add a new LayerDrawingOptions for layer ID 2 using the generated renderer
                options.Add(new LayerDrawingOptions()
                {
                    LayerID = 2, Renderer = result.Renderer
                });
            }
            else
            {
                // Otherwise the layer will have an existing LayerDrawingOptionsCollection from a previous button click
                options = ((ArcGISDynamicMapServiceLayer)map.Layers["USA"]).LayerDrawingOptions;

                // Iterate over the LayerDrawingOptionsCollection.
                // For layer ID 2 get the existing LayerDrawingOptions object and apply the newly generated renderer
                foreach (LayerDrawingOptions drawOption in options)
                {
                    if (drawOption.LayerID == 2)
                    {
                        layerDrawingOptions = drawOption;
                        drawOption.Renderer = result.Renderer;
                    }
                }
            }

            // Retrieve the GenerateRendererParameters Where clause and create a new LayerDefinition for layer ID 2
            if (!string.IsNullOrEmpty(rendererParam.Where))
            {
                LayerDefinition layerDefinition = new LayerDefinition()
                {
                    LayerID    = 2,
                    Definition = rendererParam.Where
                };

                ((ArcGISDynamicMapServiceLayer)map.Layers["USA"]).LayerDefinitions =
                    new ObservableCollection <LayerDefinition>()
                {
                    layerDefinition
                };
            }

            // Apply the updated LayerDrawingOptionsCollection to the LayerDrawingOptions property on the layer
            ((ArcGISDynamicMapServiceLayer)map.Layers["USA"]).LayerDrawingOptions = options;
        }
        // When field to summarize on changes, generate a new renderer from the map service
        private async void comboField_SelectionChanged(object sender, Windows.UI.Xaml.Controls.SelectionChangedEventArgs e)
        {
            try
            {
                // Generate a new renderer
                GenerateRendererTask generateRenderer = new GenerateRendererTask(
                    new Uri("http://sampleserver6.arcgisonline.com/arcgis/rest/services/Census/MapServer/2"));

                var colorRamp = new ColorRamp()
                {
                    Algorithm = Algorithm.Hsv,
                    From      = Color.FromArgb(0xFF, 0x99, 0x8E, 0xC3),
                    To        = Color.FromArgb(0xFF, 0xF1, 0xA3, 0x40)
                };

                var classBreaksDef = new ClassBreaksDefinition()
                {
                    BreakCount           = 5,
                    ClassificationField  = ((Windows.UI.Xaml.Controls.ComboBoxItem)comboField.SelectedItem).Tag as string,
                    ClassificationMethod = ClassificationMethod.Quantile,
                    BaseSymbol           = _baseSymbol,
                    ColorRamps           = new ObservableCollection <ColorRamp>()
                    {
                        colorRamp
                    }
                };

                var param = new GenerateRendererParameters()
                {
                    ClassificationDefinition = classBreaksDef,
                    Where = ((ServiceFeatureTable)_featureLayer.FeatureTable).Where
                };

                var result = await generateRenderer.GenerateRendererAsync(param);

                _featureLayer.Renderer = result.Renderer;

                // Reset the legend
                txtLegendTitle.DataContext = comboField.SelectedValue.ToString();
                await CreateLegend((ClassBreaksRenderer)result.Renderer);
            }
            catch (Exception ex)
            {
                var _x = new MessageDialog(ex.Message, "Sample Error").ShowAsync();
            }
        }
        // Create a unique value renderer by state sub-region name
		private async Task SetupSymbology()
        {
            try
            {
                // Generate a unique value renderer on the server
                GenerateRendererTask generateRendererTask = new GenerateRendererTask(new Uri(LAYER_URL));

                UniqueValueDefinition uvDef = new UniqueValueDefinition() { Fields = new List<string> { "sub_region" } };
                uvDef.ColorRamps.Add(new ColorRamp() { From = Colors.Purple, To = Colors.Yellow, Algorithm = Algorithm.LabLch });
                GenerateRendererParameters rendererParams = new GenerateRendererParameters() { ClassificationDefinition = uvDef };

                var rendererResult = await generateRendererTask.GenerateRendererAsync(rendererParams);
				_graphicsOverlay.Renderer = rendererResult.Renderer;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Statistics Sample");
            }
        }
        // When field to summarize on changes, generate a new renderer from the map service
        private async void comboField_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            try
            {
                // Generate a new renderer
                GenerateRendererTask generateRenderer = new GenerateRendererTask(
                    new Uri("http://sampleserver6.arcgisonline.com/arcgis/rest/services/Census/MapServer/2"));

                var colorRamp = new ColorRamp()
                {
                    Algorithm = Algorithm.Hsv,
                    From = Color.FromRgb(0x99, 0x8E, 0xC3),
                    To = Color.FromRgb(0xF1, 0xA3, 0x40)
                };

                var classBreaksDef = new ClassBreaksDefinition()
                {
                    BreakCount = 5,
                    ClassificationField = ((ComboBoxItem)comboField.SelectedItem).Tag as string,
                    ClassificationMethod = ClassificationMethod.Quantile,
                    BaseSymbol = _baseSymbol,
                    ColorRamps = new ObservableCollection<ColorRamp>() { colorRamp }
                };

                var param = new GenerateRendererParameters()
                {
                    ClassificationDefinition = classBreaksDef,
                    Where = ((ServiceFeatureTable)featureLayer.FeatureTable).Where
                };

                var result = await generateRenderer.GenerateRendererAsync(param);

                featureLayer.Renderer = result.Renderer;

                // Reset the legend
                txtLegendTitle.DataContext = comboField.SelectedValue.ToString();
                await CreateLegend((ClassBreaksRenderer)result.Renderer);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Generate Renderer Task Sample");
            }
        }
        // Create a unique value renderer by state sub-region name
        private async Task SetUniqueRenderer()
        {
            try
            {
                // Generate a unique value renderer on the server
                GenerateRendererTask generateRendererTask = new GenerateRendererTask(new Uri(LAYER_URL));

                UniqueValueDefinition uvDef = new UniqueValueDefinition() { Fields = new string[] { "sub_region" } };
                uvDef.ColorRamps.Add(new ColorRamp() { From = Colors.Purple, To = Colors.Yellow, Algorithm = Algorithm.LabLch });
                GenerateRendererParameter rendererParams = new GenerateRendererParameter() { ClassificationDefinition = uvDef };

                var rendererResult = await generateRendererTask.GenerateRendererAsync(rendererParams);
                _graphicsLayer.Renderer = rendererResult.Renderer;
            }
            catch (Exception ex)
            {
                var _ = new MessageDialog(ex.Message, "Sample Error").ShowAsync();
            }
        }