private void Add()
        {
            if (string.IsNullOrEmpty(ColumnName))
            {
                System.Windows.Forms.MessageBox.Show(GisEditor.LanguageManager.GetStringResource("ValueStyleViewModelColumnCanntEmptyMessage"), "Column is Empty");
            }
            else
            {
                var stylePlugin = GisEditor.StyleManager.GetDefaultStylePlugin(requiredValues.AvailableStyleCategories);
                if (stylePlugin != null)
                {
                    var newValueItem = new ValueItem();
                    newValueItem.Value = "Undefined";
                    newValueItem.CustomStyles.Add(stylePlugin.GetDefaultStyle());

                    var image           = StyleHelper.GetImageFromStyle(newValueItem.CustomStyles[0]);
                    var valueItemEntity = GetValueItemEntity(image, newValueItem.Value, newValueItem);

                    //if (RequiredValues.FeatureLayer is ShapeFileFeatureLayer)
                    //{
                    //    valueItemEntity.Count = StyleHelper.CalculateSpeceficValuesCount(ColumnName
                    //        , newValueItem.Value, (ShapeFileFeatureLayer)RequiredValues.FeatureLayer);
                    //}
                    //else if (RequiredValues.FeatureLayer != null)
                    //{
                    //    if (distinctColumnValues == null)
                    //    {
                    //        RequiredValues.FeatureLayer.SafeProcess(() =>
                    //        {
                    //            distinctColumnValues = RequiredValues.FeatureLayer.FeatureSource.GetDistinctColumnValues(ColumnName);
                    //        });
                    //    }

                    //    if (distinctColumnValues != null && distinctColumnValues.Count > 0)
                    //    {
                    //        var distinctColumnValue = distinctColumnValues.FirstOrDefault(tmpFeature
                    //            => tmpFeature.ColumnValue
                    //            .Equals(newValueItem.Value, StringComparison.Ordinal));
                    //        if (distinctColumnValue != null)
                    //        {
                    //            valueItemEntity.Count = distinctColumnValue.ColumnValueCount;
                    //        }
                    //    }
                    //}
                    ValueItems.Add(valueItemEntity);
                    RaisePropertyChanged("ValueItems");
                }
            }
        }
示例#2
0
        public PressureValueStyle()
        {
            SquareTextPointStyle highPressurePointStyle = new SquareTextPointStyle();

            highPressurePointStyle.Text             = "H";
            highPressurePointStyle.SymbolSolidBrush = new GeoSolidBrush(GeoColor.FromArgb(255, 39, 39, 245));

            SquareTextPointStyle lowPressurePointStyle = new SquareTextPointStyle();

            lowPressurePointStyle.Text             = "L";
            lowPressurePointStyle.SymbolSolidBrush = new GeoSolidBrush(GeoColor.StandardColors.Red);

            ValueItems.Add(new ValueItem("L", lowPressurePointStyle));
            ValueItems.Add(new ValueItem("H", highPressurePointStyle));
        }
        private void InitValueItem <T>(StyleCategories styleProviderType, DistinctColumnValue columnValueGroup, string columnName) where T : Style
        {
            Collection <Style> styles = new Collection <Style>();

            if (styleProviderType == StyleCategories.Composite)
            {
                Collection <StylePlugin> plugins = new Collection <StylePlugin>();
                var areaPlugin = GisEditor.StyleManager.GetDefaultStylePlugin(StyleCategories.Area);
                if (areaPlugin != null)
                {
                    plugins.Add(areaPlugin);
                }
                var linePlugin = GisEditor.StyleManager.GetDefaultStylePlugin(StyleCategories.Line);
                if (linePlugin != null)
                {
                    plugins.Add(linePlugin);
                }
                var pointPlugin = GisEditor.StyleManager.GetDefaultStylePlugin(StyleCategories.Point);
                if (pointPlugin != null)
                {
                    plugins.Add(pointPlugin);
                }
                foreach (var item in plugins)
                {
                    Style style = GetStyleByPlugin(item);
                    if (style != null)
                    {
                        styles.Add(style);
                    }
                }
            }
            else
            {
                var styleProvider = GisEditor.StyleManager.GetDefaultStylePlugin(styleProviderType);
                if (styleProvider != null)
                {
                    Style style = GetStyleByPlugin(styleProvider);
                    if (style != null)
                    {
                        styles.Add(style);
                    }
                }
            }

            if (styles.Count > 0)
            {
                ValueItem valueItem = new ValueItem();
                valueItem.Value = columnValueGroup.ColumnValue;
                styles.ForEach(s => valueItem.CustomStyles.Add(s));

                ValueItemEntity valueItemEntity = ValueItems.FirstOrDefault(tmpItem
                                                                            => tmpItem.MatchedValue.Equals(columnValueGroup.ColumnValue, StringComparison.Ordinal));

                if (valueItemEntity == null)
                {
                    valueItem       = new ValueItem();
                    valueItem.Value = columnValueGroup.ColumnValue;
                    styles.ForEach(s => valueItem.CustomStyles.Add(s));

                    var image = StyleHelper.GetImageFromStyle(styles);
                    var newValueItemEntity = GetValueItemEntity(image, columnValueGroup.ColumnValue, valueItem);
                    newValueItemEntity.Count = columnValueGroup.ColumnValueCount;
                    ValueItems.Add(newValueItemEntity);
                }
                else
                {
                    //valueItemEntity.Update(valueItem);
                    valueItemEntity.Count = columnValueGroup.ColumnValueCount;
                }
            }
        }
        private void AutoGenerate()
        {
            if (string.IsNullOrEmpty(ColumnName))
            {
                System.Windows.Forms.MessageBox.Show(GisEditor.LanguageManager.GetStringResource("ValueStyleViewModelColumnCanntEmptyMessage"), "Column is Empty");
            }
            else
            {
                FeatureLayer       featureLayer       = RequiredValues.FeatureLayer;
                FeatureLayerPlugin featureLayerPlugin = GisEditor.LayerManager.GetLayerPlugins(featureLayer.GetType()).FirstOrDefault() as FeatureLayerPlugin;
                if (featureLayerPlugin == null)
                {
                    return;
                }

                string selectedColumnName = ColumnName;

                featureLayer.Open();
                if (featureLayer.FeatureSource.CanGetCountQuickly())
                {
                    int count = featureLayer.FeatureSource.GetCount();
                    if (count > 500000)
                    {
                        //MessageBoxResult result = MessageBox.Show(string.Format("{0} contains a large amount of records, it might spend too much time to process. Do you want to continue?", featureLayer.Name), "Info", MessageBoxButton.YesNo, MessageBoxImage.Information);
                        //if (result == MessageBoxResult.No)
                        //{
                        //    return;
                        //}
                    }
                }

                //Collection<DistinctColumnValue> distinctColumnValues = null;
                if (distinctColumnValues == null)
                {
                    featureLayer.SafeProcess(() =>
                    {
                        distinctColumnValues = featureLayer.FeatureSource.GetDistinctColumnValues(selectedColumnName);
                    });
                }
                if (distinctColumnValues != null && distinctColumnValues.Count() > 0)
                {
                    SimpleShapeType shpType = SimpleShapeType.Unknown;
                    featureLayer.SafeProcess(() =>
                    {
                        shpType = featureLayerPlugin.GetFeatureSimpleShapeType(featureLayer);
                    });

                    foreach (var columnValue in distinctColumnValues)
                    {
                        switch (shpType)
                        {
                        case SimpleShapeType.Point:
                            InitValueItem <PointStyle>(StyleCategories.Point, columnValue, selectedColumnName);
                            break;

                        case SimpleShapeType.Line:
                            InitValueItem <LineStyle>(StyleCategories.Line, columnValue, selectedColumnName);
                            break;

                        case SimpleShapeType.Area:
                            InitValueItem <AreaStyle>(StyleCategories.Area, columnValue, selectedColumnName);
                            break;

                        case SimpleShapeType.Unknown:
                            InitValueItem <Style>(StyleCategories.Composite, columnValue, selectedColumnName);
                            break;
                        }
                    }
                    var itemSourceList = ValueItems.OrderBy(itemValue => itemValue.ValueItem.Value).ToList();
                    ValueItems.Clear();
                    foreach (var item in itemSourceList.Where(i => !String.IsNullOrEmpty(i.MatchedValue)))
                    {
                        ValueItems.Add(item);
                    }
                    foreach (var item in itemSourceList.Where(i => String.IsNullOrEmpty(i.MatchedValue)))
                    {
                        ValueItems.Add(item);
                    }

                    SyncActualValueItems();
                    RaisePropertyChanged("ValueItems");
                }
                else
                {
                    System.Windows.Forms.MessageBox.Show(GisEditor.LanguageManager.GetStringResource("ValueStyleViewModelColumnNoValueMatchedMessage"));
                }
            }
        }