Ejemplo n.º 1
0
        public static bool AddStyleToLayerWithStyleWizard(IEnumerable <Layer> layers, bool replaceStyle = false)
        {
            bool addedStyle = false;
            var  newLayers  = layers.ToArray();

            foreach (var tmpLayer in newLayers)
            {
                var shapeFileFeatureLayer = tmpLayer as FeatureLayer;
                if (shapeFileFeatureLayer != null &&
                    newLayers.Length == 1)
                {
                    var styleWizardWindow = GisEditor.ControlManager.GetUI <StyleWizardWindow>();
                    styleWizardWindow.StyleCategories = LayerListHelper.GetStyleCategoriesByFeatureLayer(shapeFileFeatureLayer);
                    styleWizardWindow.StyleCategories = styleWizardWindow.StyleCategories ^ StyleCategories.Composite;
                    styleWizardWindow.StyleCategories = styleWizardWindow.StyleCategories ^ StyleCategories.Label;
                    if ((styleWizardWindow as System.Windows.Window).ShowDialog().GetValueOrDefault())
                    {
                        if (styleWizardWindow.StyleWizardResult != null)
                        {
                            if (GisEditor.ActiveMap != null)
                            {
                                GisEditor.ActiveMap.ActiveLayer = shapeFileFeatureLayer;
                            }

                            StyleBuilderArguments arguments = new StyleBuilderArguments();
                            arguments.FeatureLayer             = shapeFileFeatureLayer;
                            arguments.AvailableStyleCategories = LayerListHelper.GetStyleCategoriesByFeatureLayer(shapeFileFeatureLayer);
                            StylePlugin styleProvider = styleWizardWindow.StyleWizardResult.StylePlugin;

                            arguments.AppliedCallback = new Action <StyleBuilderResult>(args =>
                            {
                                if (args.CompositeStyle != null)
                                {
                                    if (replaceStyle)
                                    {
                                        foreach (var customZoomLevel in shapeFileFeatureLayer.ZoomLevelSet.CustomZoomLevels)
                                        {
                                            customZoomLevel.CustomStyles.Clear();
                                        }
                                    }
                                    AddNewStyleToLayer(shapeFileFeatureLayer, args.CompositeStyle, args.FromZoomLevelIndex, args.ToZoomLevelIndex);
                                }
                            });

                            var newStyle = styleProvider.GetDefaultStyle();
                            newStyle.Name = styleProvider.Name;
                            CompositeStyle componentStyle = new CompositeStyle();
                            componentStyle.Name = shapeFileFeatureLayer.Name;
                            componentStyle.Styles.Add(newStyle);
                            arguments.StyleToEdit = componentStyle;

                            arguments.FillRequiredColumnNames();
                            var styleResult = GisEditor.StyleManager.EditStyle(arguments);
                            if (!styleResult.Canceled)
                            {
                                componentStyle = (CompositeStyle)styleResult.CompositeStyle;
                                arguments.AppliedCallback(styleResult);
                                addedStyle = true;
                            }
                        }
                    }
                    //if (GisEditor.StyleManager.UseWizard != styleWizardWindow.IsAlwaysShowWhenLayerIsAdded)
                    //{
                    //    GisEditor.StyleManager.UseWizard = styleWizardWindow.IsAlwaysShowWhenLayerIsAdded;
                    //    GisEditor.InfrastructureManager.SaveSettings(GisEditor.StyleManager);
                    //}
                }
            }
            return(addedStyle);
        }
        private static void AddStyle(StylePlugin styleProvider)
        {
            Style style = null;
            StyleBuilderArguments arguments           = new StyleBuilderArguments();
            FeatureLayer          currentFeatureLayer = null;

            if (GisEditor.LayerListManager.SelectedLayerListItem == null)
            {
                return;
            }

            //add a new style by right-clicking on a layer node
            if (GisEditor.LayerListManager.SelectedLayerListItem.ConcreteObject is FeatureLayer)
            {
                currentFeatureLayer = (FeatureLayer)GisEditor.LayerListManager.SelectedLayerListItem.ConcreteObject;
            }

            //add a new style by right-clicking on a zoomlevel node
            else if (GisEditor.LayerListManager.SelectedLayerListItem.ConcreteObject is ZoomLevel)
            {
                ZoomLevel editingZoomLevel = (ZoomLevel)GisEditor.LayerListManager.SelectedLayerListItem.ConcreteObject;
                arguments.FromZoomLevelIndex = GisEditor.ActiveMap.GetSnappedZoomLevelIndex(editingZoomLevel.Scale, false) + 1;
                arguments.ToZoomLevelIndex   = (int)editingZoomLevel.ApplyUntilZoomLevel;
                currentFeatureLayer          = (FeatureLayer)GisEditor.LayerListManager.SelectedLayerListItem.Parent.ConcreteObject;
            }

            //replace an existing style
            else if (GisEditor.LayerListManager.SelectedLayerListItem.ConcreteObject is Style)
            {
                Style currentStyle = (Style)GisEditor.LayerListManager.SelectedLayerListItem.ConcreteObject;
                currentFeatureLayer = LayerListHelper.FindMapElementInTree <FeatureLayer>(GisEditor.LayerListManager.SelectedLayerListItem);
            }

            arguments.AvailableStyleCategories = LayerListHelper.GetStyleCategoriesByFeatureLayer(currentFeatureLayer);
            arguments.FeatureLayer             = currentFeatureLayer;
            arguments.FillRequiredColumnNames();
            arguments.AppliedCallback = args =>
            {
                if (args.CompositeStyle != null)
                {
                    ZoomLevelHelper.ApplyStyle(args.CompositeStyle, currentFeatureLayer, args.FromZoomLevelIndex, args.ToZoomLevelIndex);
                }
            };

            style      = styleProvider.GetDefaultStyle();
            style.Name = styleProvider.Name;
            var componentStyle = new CompositeStyle(style)
            {
                Name = currentFeatureLayer.Name
            };

            arguments.StyleToEdit = componentStyle;
            //var styleResults = GisEditor.StyleManager.EditStyle(arguments);
            if (currentFeatureLayer != null)
            {
                var featureLayerPlugin = GisEditor.LayerManager.GetLayerPlugins(currentFeatureLayer.GetType()).FirstOrDefault() as FeatureLayerPlugin;
                if (featureLayerPlugin != null)
                {
                    var styleBuilder = GisEditor.StyleManager.GetStyleBuiderUI();
                    if (styleBuilder != null)
                    {
                        styleBuilder.StyleBuilderArguments = arguments;
                        if (styleBuilder.ShowDialog().GetValueOrDefault())
                        {
                            arguments.AppliedCallback(styleBuilder.StyleBuilderResult);
                        }
                    }
                }
            }
        }