public static void AddStyle()
        {
            if (GisEditor.LayerListManager.SelectedLayerListItem == null)
            {
                return;
            }
            var featureLayer = GisEditor.LayerListManager.SelectedLayerListItem.ConcreteObject as FeatureLayer;

            if (featureLayer == null)
            {
                featureLayer = GisEditor.LayerListManager.SelectedLayerListItem.Parent.ConcreteObject as FeatureLayer;
            }
            if (featureLayer != null)
            {
                var styleArguments     = new StyleBuilderArguments();
                var featureLayerPlugin = GisEditor.LayerManager.GetLayerPlugins(featureLayer.GetType()).FirstOrDefault() as FeatureLayerPlugin;
                switch (featureLayerPlugin.GetFeatureSimpleShapeType(featureLayer))
                {
                case SimpleShapeType.Point:
                    styleArguments.AvailableStyleCategories = StyleCategories.Point | StyleCategories.Label | StyleCategories.Composite;
                    break;

                case SimpleShapeType.Line:
                    styleArguments.AvailableStyleCategories = StyleCategories.Line | StyleCategories.Label | StyleCategories.Composite;
                    break;

                case SimpleShapeType.Area:
                    styleArguments.AvailableStyleCategories = StyleCategories.Area | StyleCategories.Label | StyleCategories.Composite;
                    break;
                }
                var componentStyle = new CompositeStyle();
                styleArguments.StyleToEdit        = componentStyle;
                styleArguments.FeatureLayer       = featureLayer;
                styleArguments.FromZoomLevelIndex = 1;
                styleArguments.ToZoomLevelIndex   = GisEditor.ActiveMap.ZoomLevelSet.GetZoomLevels().Where(z => z.GetType() == typeof(ZoomLevel)).Count();
                styleArguments.AppliedCallback    = new Action <StyleBuilderResult>((styleResult) =>
                {
                    if (!styleResult.Canceled)
                    {
                        foreach (var zoomLevel in featureLayer.ZoomLevelSet.CustomZoomLevels)
                        {
                            zoomLevel.CustomStyles.Remove(componentStyle);
                        }

                        for (int i = styleResult.FromZoomLevelIndex - 1; i < styleResult.ToZoomLevelIndex; i++)
                        {
                            featureLayer.ZoomLevelSet.CustomZoomLevels[i].CustomStyles.Add(styleResult.CompositeStyle);
                        }

                        LayerListHelper.InvalidateTileOverlay();
                        GisEditor.UIManager.InvokeRefreshPlugins(new RefreshArgs(featureLayer, RefreshArgsDescriptions.AddStyleCommandDescription));
                        componentStyle = styleResult.CompositeStyle as CompositeStyle;
                    }
                });

                styleArguments.FillRequiredColumnNames();
                var styleResults = GisEditor.StyleManager.EditStyle(styleArguments);
                styleArguments.AppliedCallback(styleResults);
            }
        }
        private static StyleBuilderArguments GetDuplicateStyleArguments(StyleCategories styleCategories, StyleBuilderArguments styleArguments)
        {
            StyleBuilderArguments newStyleBuilderArguments = new StyleBuilderArguments
            {
                AppliedCallback          = styleArguments.AppliedCallback,
                AvailableStyleCategories = styleCategories | StyleCategories.Label | StyleCategories.Composite,
                AvailableUIElements      = styleArguments.AvailableUIElements,
                FeatureLayer             = styleArguments.FeatureLayer,
                FromZoomLevelIndex       = styleArguments.FromZoomLevelIndex,
                SelectedConcreteObject   = styleArguments.SelectedConcreteObject,
                StyleToEdit      = styleArguments.StyleToEdit,
                ToZoomLevelIndex = styleArguments.ToZoomLevelIndex
            };

            newStyleBuilderArguments.FillRequiredColumnNames();

            return(newStyleBuilderArguments);
        }
        public static void EditStyle(LayerListItem selectedLayerListItem)
        {
            var componentStyleItem = LayerListHelper.FindViewModelInTree <CompositeStyle>(selectedLayerListItem) as StyleLayerListItem;

            if (componentStyleItem != null)
            {
                var componentStyle = componentStyleItem.ConcreteObject as CompositeStyle;
                var styleArguments = new StyleBuilderArguments();
                styleArguments.FeatureLayer = componentStyleItem.Parent.ConcreteObject as FeatureLayer;
                var featureLayerPlugin = GisEditor.LayerManager.GetLayerPlugins(styleArguments.FeatureLayer.GetType()).FirstOrDefault() as FeatureLayerPlugin;
                if (featureLayerPlugin != null)
                {
                    styleArguments.AvailableStyleCategories = GetStyleCategoriesByFeatureLayer(styleArguments.FeatureLayer);
                    int from = 1;
                    int to   = GisEditor.ActiveMap.ZoomLevelSet.CustomZoomLevels.Where(z => z.GetType() == typeof(ZoomLevel)).Count();
                    if (!string.IsNullOrEmpty(componentStyleItem.ZoomLevelRange))
                    {
                        var array = componentStyleItem.ZoomLevelRange.Split(" to ".ToArray(), StringSplitOptions.RemoveEmptyEntries);
                        if (array.Length == 2)
                        {
                            int.TryParse(array[0].Replace("(", "").Trim(), out from);
                            int.TryParse(array[1].Replace(")", "").Trim(), out to);
                        }
                    }

                    styleArguments.FromZoomLevelIndex = from;
                    styleArguments.ToZoomLevelIndex   = to;
                    styleArguments.AppliedCallback    = new Action <StyleBuilderResult>((styleResults) =>
                    {
                        if (!styleResults.Canceled)
                        {
                            var resultStyle = styleResults.CompositeStyle as CompositeStyle;
                            var count       = GisEditor.ActiveMap.ZoomLevelSet.GetZoomLevels().Where(z => z.GetType() == typeof(ZoomLevel)).Count();
                            for (int i = 0; i < count; i++)
                            {
                                var customStyles = styleArguments.FeatureLayer.ZoomLevelSet.CustomZoomLevels[i].CustomStyles;
                                if (i >= styleResults.FromZoomLevelIndex - 1 && i < styleResults.ToZoomLevelIndex)
                                {
                                    if (!customStyles.Contains(componentStyle))
                                    {
                                        customStyles.Add(componentStyle);
                                    }
                                    componentStyle.Styles.Clear();
                                    componentStyle.Name = resultStyle.Name;
                                    foreach (var item in resultStyle.Styles)
                                    {
                                        componentStyle.Styles.Add(item);
                                    }
                                }
                                else
                                {
                                    customStyles.Remove(componentStyle);
                                }
                            }
                            if (styleArguments.FeatureLayer.IsVisible)
                            {
                                foreach (var overlay in GisEditor.ActiveMap.GetOverlaysContaining(styleArguments.FeatureLayer))
                                {
                                    overlay.Invalidate();
                                }
                            }
                            GisEditor.UIManager.InvokeRefreshPlugins(new RefreshArgs(styleResults, RefreshArgsDescriptions.EditStyleDescription));
                        }
                    });
                    var styleItems = new Collection <StyleLayerListItem>();
                    foreach (var style in componentStyle.Styles)
                    {
                        var item = GisEditor.StyleManager.GetStyleLayerListItem(style);
                        if (item != null)
                        {
                            styleItems.Add(item);
                        }
                    }

                    var clonedStyleItems     = new Collection <StyleLayerListItem>();
                    var clonedCompositeStyle = componentStyle.CloneDeep() as CompositeStyle;

                    styleArguments.StyleToEdit = clonedCompositeStyle;

                    foreach (var style in clonedCompositeStyle.Styles)
                    {
                        var item = GisEditor.StyleManager.GetStyleLayerListItem(style);
                        if (item != null)
                        {
                            clonedStyleItems.Add(item);
                        }
                    }

                    object selectedClonedObject = FindSelectedObject(styleItems.ToList(), clonedStyleItems.ToList(), selectedLayerListItem.ConcreteObject);
                    styleArguments.FillRequiredColumnNames();
                    styleArguments.SelectedConcreteObject = selectedClonedObject;
                    var styleBuilder = GisEditor.StyleManager.GetStyleBuiderUI(styleArguments);
                    //styleBuilder.StyleBuilderArguments = styleArguments;
                    //var styleResult = GisEditor.StyleManager.EditStyle(styleArguments, selectedClonedObject);
                    if (styleBuilder.ShowDialog().GetValueOrDefault())
                    {
                        styleArguments.AppliedCallback(styleBuilder.StyleBuilderResult);
                    }
                }
            }
        }
Exemple #4
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);
                        }
                    }
                }
            }
        }