Ejemplo n.º 1
0
        private void GenerateRangeValueClick(object sender, System.Windows.RoutedEventArgs e)
        {
            ClassBreaksDefinition classBreaksDefinition = new ClassBreaksDefinition()
            {
                ClassificationField       = "SQMI",
                ClassificationMethod      = ClassificationMethod.StandardDeviation,
                BreakCount                = 5,
                StandardDeviationInterval = ESRI.ArcGIS.Client.Tasks.StandardDeviationInterval.OneQuarter
            };

            classBreaksDefinition.ColorRamps.Add(new ColorRamp()
            {
                From      = Colors.Blue,
                To        = Colors.Red,
                Algorithm = Algorithm.HSVAlgorithm
            });

            GenerateRendererParameters rendererParams = new GenerateRendererParameters()
            {
                ClassificationDefinition = classBreaksDefinition,
                Where = "STATE_NAME NOT IN ('Alaska', 'Hawaii')"
            };

            generateRendererTask.ExecuteAsync(rendererParams, rendererParams.Where);
        }
        private void RenderButton_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            ObservableCollection <ColorRamp> colorRamps = new ObservableCollection <ColorRamp>();

            colorRamp = new ColorRamp()
            {
                From      = ((StartColorListBox.SelectedItem as ListBoxItem).Background as SolidColorBrush).Color,
                To        = ((EndColorListBox.SelectedItem as ListBoxItem).Background as SolidColorBrush).Color,
                Algorithm = (Algorithm)AlgorithmListBox.SelectedItem,
            };
            colorRamps.Add(colorRamp);

            generateClassesParameters.ClassificationDefinition = new ClassBreaksDefinition()
            {
                BaseSymbol = new ESRI.ArcGIS.Client.Symbols.SimpleFillSymbol()
                {
                    Fill = (ColorRampListBox.SelectedItem as ListBoxItem).Background
                },
                ClassificationField  = ((ClassificationFieldListBox.SelectedItem) as Field).Name,
                ClassificationMethod = (ClassificationMethod)ClassificationMethodListBox.SelectedItem,

                BreakCount = int.Parse(BreakCountTB.Text.Trim()),
                ColorRamps = colorRamps,
            };

            ClassBreaksDefinition classBreakDef =
                generateClassesParameters.ClassificationDefinition as ClassBreaksDefinition;

            if (classBreakDef.ClassificationMethod == ClassificationMethod.StandardDeviation)
            {
                classBreakDef.StandardDeviationInterval = (StandardDeviationInterval)IntervalListBox.SelectedItem;
            }

            if (NormalizationTypeListBox.SelectedItem != null)
            {
                classBreakDef.NormalizationType = (NormalizationType)NormalizationTypeListBox.SelectedItem;

                if (classBreakDef.NormalizationType == NormalizationType.Field)
                {
                    if (NormalizationFieldListBox.SelectedItem != null)
                    {
                        classBreakDef.NormalizationField = ((NormalizationFieldListBox.SelectedItem) as Field).Name;
                    }
                    else
                    {
                        MessageBox.Show("Normalization Field must be selected");
                        return;
                    }
                }
            }
            if (generateRendererTask.IsBusy)
            {
                generateRendererTask.CancelAsync();
            }
            generateRendererTask.ExecuteAsync(generateClassesParameters);

            ThematicPropertiesPage.IsOpen = false;
        }
        // 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();
            }
        }
        private async void GenerateRangeValueClick(object sender, RoutedEventArgs e)
        {
            try
            {
                if (IsBusy)
                {
                    return;
                }

                IsBusy = true;

                ClassBreaksDefinition classBreaksDefinition = new ClassBreaksDefinition()
                {
                    ClassificationField       = "SQMI",
                    ClassificationMethod      = ClassificationMethod.StandardDeviation,
                    BreakCount                = 5,
                    StandardDeviationInterval = StandardDeviationInterval.OneQuarter
                };

                classBreaksDefinition.ColorRamps.Add(new ColorRamp()
                {
                    From      = Colors.Blue,
                    To        = Colors.Red,
                    Algorithm = Algorithm.Hsv
                });

                // Create a new GenerateRendererParameter object and set the ClassificationDefinition
                // Also specify a Where clause on the layer to demonstrate excluding features from the classification
                GenerateRendererParameters rendererParam = new GenerateRendererParameters()
                {
                    ClassificationDefinition = classBreaksDefinition,
                    Where = "STATE_NAME NOT IN ('Alaska', 'Hawaii')"
                };

                await GenerateRenderer(rendererParam);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error generating renderer: " + ex.Message);
            }
            finally
            {
                IsBusy = false;
            }
        }
        private async void GenerateRangeValueClick(object sender, RoutedEventArgs e)
        {
            try
            {
                if (IsBusy)
                    return;

                IsBusy = true;

                ClassBreaksDefinition classBreaksDefinition = new ClassBreaksDefinition()
                {
                    ClassificationField = "SQMI",
                    ClassificationMethod = ClassificationMethod.StandardDeviation,
                    BreakCount = 5,
                    StandardDeviationInterval = StandardDeviationInterval.OneQuarter
                };

                classBreaksDefinition.ColorRamps.Add(new ColorRamp()
                {
                    From = Colors.Blue,
                    To = Colors.Red,
                    Algorithm = Algorithm.Hsv
                });

                // Create a new GenerateRendererParameter object and set the ClassificationDefinition
                // Also specify a Where clause on the layer to demonstrate excluding features from the classification
                GenerateRendererParameters rendererParam = new GenerateRendererParameters()
                {
                    ClassificationDefinition = classBreaksDefinition,
                    Where = "STATE_NAME NOT IN ('Alaska', 'Hawaii')"
                };

                await GenerateRenderer(rendererParam);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error generating renderer: " + ex.Message);
            }
            finally
            {
                IsBusy = false;
            }
        }
        // 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");
            }
        }
        private void GenerateRangeValueClick(object sender, RoutedEventArgs e)
        {
            ClassBreaksDefinition classBreaksDefinition = new ClassBreaksDefinition()
            {
                ClassificationField = "SQMI",
                ClassificationMethod = ClassificationMethod.StandardDeviation,
                BreakCount = 5,
                StandardDeviationInterval = ESRI.ArcGIS.Client.Tasks.StandardDeviationInterval.OneQuarter
            };
            classBreaksDefinition.ColorRamps.Add(new ColorRamp()
                {
                    From = Colors.Blue,
                    To = Colors.Red,
                    Algorithm = Algorithm.HSVAlgorithm
                });

            GenerateRendererParameters rendererParams = new GenerateRendererParameters()
            {
                ClassificationDefinition = classBreaksDefinition,
                Where = "STATE_NAME NOT IN ('Alaska', 'Hawaii')"
            };

            generateRendererTask.ExecuteAsync(rendererParams, rendererParams.Where);
        }
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            layer = (map.Layers[0] as ArcGISDynamicMapServiceLayer);
            DynamicLayerInfoCollection myDynamicLayerInfos = layer.DynamicLayerInfos;
            if (myDynamicLayerInfos == null)
            {
                myDynamicLayerInfos = layer.CreateDynamicLayerInfosFromLayerInfos();
            }

            #region TableDataSource
            DynamicLayerInfo info = new DynamicLayerInfo()
            {
                ID = 1,
                Source = new LayerDataSource()
                {
                    DataSource = new QueryDataSource()
                    {
                        GeometryType = ESRI.ArcGIS.Client.Tasks.GeometryType.Polyline,
                        OIDFields = new string[] { "OBJECTID" },
                        Query = "SELECT * FROM  SDE.china_road where FNODE_ > 1000",
                        WorkspaceID = "MyDatabaseWorkspaceID"
                    }
                }
            };
            #endregion

            #region QueryDataSource
            DynamicLayerInfo info = new DynamicLayerInfo()
            {
                ID = 1,
                Source = new LayerDataSource()
                {
                    DataSource = new QueryDataSource()
                    {
                        GeometryType = ESRI.ArcGIS.Client.Tasks.GeometryType.Polyline,
                        OIDFields = new string[] { "OBJECTID" },
                        Query = "SELECT * FROM  SDE.china_road where FNODE_ > 1000",
                        WorkspaceID = "MyDatabaseWorkspaceID"
                    }
                }
            };
            #endregion

            #region UserDefine Simple Render Line
            //LayerDrawingOptions layerDrawOptions = new LayerDrawingOptions();
            //layerDrawOptions.LayerID = 1;
            //layerDrawOptions.Renderer = new SimpleRenderer()
            //{
            //	Symbol = new SimpleLineSymbol()
            //	{
            //		Color = new SolidColorBrush(Color.FromArgb((int)255, (int)0, (int)0, (int)255)),
            //		Width = 2
            //	}
            //};

            //layer.LayerDrawingOptions = new LayerDrawingOptionsCollection() { layerDrawOptions };
            #endregion

            #region UserDefine Simple Render Poly
            LayerDrawingOptions layerDrawOptions = new LayerDrawingOptions();
            layerDrawOptions.LayerID = 1;
            layerDrawOptions.Renderer = new SimpleRenderer()
            {
                Symbol = new SimpleFillSymbol()
                {
                    Fill = new SolidColorBrush(Color.FromArgb((int)255, (int)0, (int)0, (int)255)),
                }
            };

            layer.LayerDrawingOptions =
                    new LayerDrawingOptionsCollection() { layerDrawOptions };
            #endregion

            #region JoinDataSource
            DynamicLayerInfo info = new DynamicLayerInfo()
            {
                ID = 1,
                Source = new LayerDataSource()
                {

                    DataSource = new JoinDataSource()
                    {

                        JoinType = JoinType.LeftInnerJoin,
                        LeftTableSource = new LayerDataSource()
                        {
                            DataSource = new TableDataSource()
                            {
                                DataSourceName = "SDE.china_county",
                                WorkspaceID = "MyDatabaseWorkspaceID"
                            }
                        },
                        LeftTableKey = "OBJECTID",
                        RightTableSource = new LayerDataSource()
                        {
                            DataSource = new TableDataSource()
                            {
                                DataSourceName = "SDE.china_road",
                                WorkspaceID = "MyDatabaseWorkspaceID"
                            }
                        },
                        RightTableKey = "OBJECTID"
                    }
                }
            };
            #endregion

            #region RasterDataSource
            //DynamicLayerInfo info = new DynamicLayerInfo()
            //{
            //	ID = 1,
            //	Source = new LayerDataSource()
            //	{
            //		DataSource = new RasterDataSource()
            //		{
            //			DataSourceName = "rr1",
            //			WorkspaceID = "MyRasterWorkspaceID"
            //		}
            //	}
            //};
            #endregion

            myDynamicLayerInfos.Add(info);
            layer.DynamicLayerInfos = myDynamicLayerInfos;

            layer.VisibleLayers = new int[] { 1 };
            //layer.Refresh();
            //map.ZoomTo(new Envelope(11.8435360079, 49.4443060783, 11.8568721432, 49.4528247773));
            //map.ZoomTo(layer.Layers[1].e)

            #region Generate Render Class Break
            ClassBreaksDefinition classBreaksDefinition = new ClassBreaksDefinition()
            {
                ClassificationField = "FNODE_",
                ClassificationMethod = ClassificationMethod.StandardDeviation,
                BreakCount = 10,
                StandardDeviationInterval = ESRI.ArcGIS.Client.Tasks.StandardDeviationInterval.OneQuarter
            };
            classBreaksDefinition.ColorRamps.Add(new ColorRamp()
            {
                From = Colors.Blue,
                To = Colors.Red,
                Algorithm = Algorithm.HSVAlgorithm
            });

            GenerateRendererParameters rendererParams = new GenerateRendererParameters()
            {
                ClassificationDefinition = classBreaksDefinition,
                Source = info.Source
            };

            generateRendererTask.ExecuteAsync(rendererParams, rendererParams.Where);
            #endregion

            #region Generate Render Unique Value
            UniqueValueDefinition uniqueValueDefinition = new UniqueValueDefinition()
            {
                Fields = new List<string>() { "FNODE_" }
            };
            uniqueValueDefinition.ColorRamps.Add(new ColorRamp()
            {
                From = Colors.Blue,
                To = Colors.Red,
                Algorithm = Algorithm.CIELabAlgorithm
            });

            GenerateRendererParameters rendererParams = new GenerateRendererParameters()
            {
                ClassificationDefinition = uniqueValueDefinition,
                Source = info.Source
            };

            generateRendererTask.ExecuteAsync(rendererParams, rendererParams.Where);
            #endregion
        }
Ejemplo n.º 9
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            layer = (map.Layers[0] as ArcGISDynamicMapServiceLayer);
            DynamicLayerInfoCollection myDynamicLayerInfos = layer.DynamicLayerInfos;

            if (myDynamicLayerInfos == null)
            {
                myDynamicLayerInfos = layer.CreateDynamicLayerInfosFromLayerInfos();
            }

            #region TableDataSource
            DynamicLayerInfo info = new DynamicLayerInfo()
            {
                ID     = 1,
                Source = new LayerDataSource()
                {
                    DataSource = new QueryDataSource()
                    {
                        GeometryType = ESRI.ArcGIS.Client.Tasks.GeometryType.Polyline,
                        OIDFields    = new string[] { "OBJECTID" },
                        Query        = "SELECT * FROM  SDE.china_road where FNODE_ > 1000",
                        WorkspaceID  = "MyDatabaseWorkspaceID"
                    }
                }
            };
            #endregion

            #region QueryDataSource
            DynamicLayerInfo info = new DynamicLayerInfo()
            {
                ID     = 1,
                Source = new LayerDataSource()
                {
                    DataSource = new QueryDataSource()
                    {
                        GeometryType = ESRI.ArcGIS.Client.Tasks.GeometryType.Polyline,
                        OIDFields    = new string[] { "OBJECTID" },
                        Query        = "SELECT * FROM  SDE.china_road where FNODE_ > 1000",
                        WorkspaceID  = "MyDatabaseWorkspaceID"
                    }
                }
            };
            #endregion

            #region UserDefine Simple Render Line
            //LayerDrawingOptions layerDrawOptions = new LayerDrawingOptions();
            //layerDrawOptions.LayerID = 1;
            //layerDrawOptions.Renderer = new SimpleRenderer()
            //{
            //	Symbol = new SimpleLineSymbol()
            //	{
            //		Color = new SolidColorBrush(Color.FromArgb((int)255, (int)0, (int)0, (int)255)),
            //		Width = 2
            //	}
            //};

            //layer.LayerDrawingOptions = new LayerDrawingOptionsCollection() { layerDrawOptions };
            #endregion

            #region UserDefine Simple Render Poly
            LayerDrawingOptions layerDrawOptions = new LayerDrawingOptions();
            layerDrawOptions.LayerID  = 1;
            layerDrawOptions.Renderer = new SimpleRenderer()
            {
                Symbol = new SimpleFillSymbol()
                {
                    Fill = new SolidColorBrush(Color.FromArgb((int)255, (int)0, (int)0, (int)255)),
                }
            };

            layer.LayerDrawingOptions =
                new LayerDrawingOptionsCollection()
            {
                layerDrawOptions
            };
            #endregion

            #region JoinDataSource
            DynamicLayerInfo info = new DynamicLayerInfo()
            {
                ID     = 1,
                Source = new LayerDataSource()
                {
                    DataSource = new JoinDataSource()
                    {
                        JoinType        = JoinType.LeftInnerJoin,
                        LeftTableSource = new LayerDataSource()
                        {
                            DataSource = new TableDataSource()
                            {
                                DataSourceName = "SDE.china_county",
                                WorkspaceID    = "MyDatabaseWorkspaceID"
                            }
                        },
                        LeftTableKey     = "OBJECTID",
                        RightTableSource = new LayerDataSource()
                        {
                            DataSource = new TableDataSource()
                            {
                                DataSourceName = "SDE.china_road",
                                WorkspaceID    = "MyDatabaseWorkspaceID"
                            }
                        },
                        RightTableKey = "OBJECTID"
                    }
                }
            };
            #endregion

            #region RasterDataSource
            //DynamicLayerInfo info = new DynamicLayerInfo()
            //{
            //	ID = 1,
            //	Source = new LayerDataSource()
            //	{
            //		DataSource = new RasterDataSource()
            //		{
            //			DataSourceName = "rr1",
            //			WorkspaceID = "MyRasterWorkspaceID"
            //		}
            //	}
            //};
            #endregion

            myDynamicLayerInfos.Add(info);
            layer.DynamicLayerInfos = myDynamicLayerInfos;


            layer.VisibleLayers = new int[] { 1 };
            //layer.Refresh();
            //map.ZoomTo(new Envelope(11.8435360079, 49.4443060783, 11.8568721432, 49.4528247773));
            //map.ZoomTo(layer.Layers[1].e)

            #region Generate Render Class Break
            ClassBreaksDefinition classBreaksDefinition = new ClassBreaksDefinition()
            {
                ClassificationField       = "FNODE_",
                ClassificationMethod      = ClassificationMethod.StandardDeviation,
                BreakCount                = 10,
                StandardDeviationInterval = ESRI.ArcGIS.Client.Tasks.StandardDeviationInterval.OneQuarter
            };
            classBreaksDefinition.ColorRamps.Add(new ColorRamp()
            {
                From      = Colors.Blue,
                To        = Colors.Red,
                Algorithm = Algorithm.HSVAlgorithm
            });

            GenerateRendererParameters rendererParams = new GenerateRendererParameters()
            {
                ClassificationDefinition = classBreaksDefinition,
                Source = info.Source
            };

            generateRendererTask.ExecuteAsync(rendererParams, rendererParams.Where);
            #endregion

            #region Generate Render Unique Value
            UniqueValueDefinition uniqueValueDefinition = new UniqueValueDefinition()
            {
                Fields = new List <string>()
                {
                    "FNODE_"
                }
            };
            uniqueValueDefinition.ColorRamps.Add(new ColorRamp()
            {
                From      = Colors.Blue,
                To        = Colors.Red,
                Algorithm = Algorithm.CIELabAlgorithm
            });

            GenerateRendererParameters rendererParams = new GenerateRendererParameters()
            {
                ClassificationDefinition = uniqueValueDefinition,
                Source = info.Source
            };

            generateRendererTask.ExecuteAsync(rendererParams, rendererParams.Where);
            #endregion
        }