예제 #1
0
        private static void RemoveStyle()
        {
            if (GisEditor.LayerListManager.SelectedLayerListItem == null)
            {
                return;
            }
            var featureLayer = GisEditor.LayerListManager.SelectedLayerListItem.Parent.ConcreteObject as FeatureLayer;

            if (featureLayer != null)
            {
                var style = GisEditor.LayerListManager.SelectedLayerListItem.ConcreteObject as Style;
                foreach (var zoomLevel in featureLayer.ZoomLevelSet.CustomZoomLevels)
                {
                    if (zoomLevel.CustomStyles.Contains(style))
                    {
                        zoomLevel.CustomStyles.Remove(style);
                    }
                }
            }
            else
            {
                var parent = GisEditor.LayerListManager.SelectedLayerListItem.Parent as StyleLayerListItem;
                if (parent != null)
                {
                    parent.Children.Remove(GisEditor.LayerListManager.SelectedLayerListItem);
                    parent.UpdateConcreteObject();
                }
            }
            LayerListHelper.RefreshCache();
            GisEditor.UIManager.BeginRefreshPlugins(new RefreshArgs(GisEditor.LayerListManager.SelectedLayerListItem, RefreshArgsDescription.RemoveStyleDescription));
        }
        protected override LayerListItem GetLayerListItemCore(Layer layer)
        {
            var layerListItem = base.GetLayerListItemCore(layer);
            var csvLayer      = (CsvFeatureLayer)layer;

            if (!csvLayer.RequireIndex)
            {
                const string noIndexToolTip = "This layer doesn't use spatial index file";
                if (GisEditor.LanguageManager != null)
                {
                    GisEditor.LanguageManager.GetStringResource("MapElementsListUserControlNoIndexFileToolTip");
                }
                layerListItem.WarningImages.Add(new Image {
                    Source = new BitmapImage(new Uri("pack://application:,,,/GisEditorInfrastructure;component/Images/NoIndexFile.png", UriKind.Absolute)), Width = 14, Height = 14, ToolTip = noIndexToolTip
                });
            }
            if (layerListItem.Children.Count == 0)
            {
                LayerListItem noStyleEntity = new LayerListItem
                {
                    Name = GisEditor.LanguageManager.GetStringResource("DelimitedTextFeatureLayerPluginDoubleClick"),
                    CheckBoxVisibility = Visibility.Collapsed,
                    DoubleClicked      = () => LayerListHelper.AddStyle(new PointStyle(), csvLayer),
                    Parent             = layerListItem,
                    ConcreteObject     = csvLayer,
                    FontWeight         = FontWeights.Bold
                };
                layerListItem.Children.Add(noStyleEntity);
            }
            return(layerListItem);
        }
        private static void RemoveSubStyle()
        {
            if (GisEditor.LayerListManager.SelectedLayerListItem == null)
            {
                return;
            }
            Style  style = GisEditor.LayerListManager.SelectedLayerListItem.ConcreteObject as Style;
            object parentActualObject = GisEditor.LayerListManager.SelectedLayerListItem.Parent.ConcreteObject;

            if (style != null)
            {
                if (parentActualObject is ValueStyle)
                {
                    var valueStyle      = (ValueStyle)parentActualObject;
                    var resultValueItem = valueStyle.ValueItems.Where(valueItem => valueItem.CustomStyles.Contains(style)).FirstOrDefault();
                    valueStyle.ValueItems.Remove(resultValueItem);
                }
                else if (parentActualObject is ClassBreakStyle)
                {
                    var classBreakStyle  = (ClassBreakStyle)parentActualObject;
                    var resultClassBreak = classBreakStyle.ClassBreaks.Where(classBreak => classBreak.CustomStyles.Contains(style)).FirstOrDefault();
                    classBreakStyle.ClassBreaks.Remove(resultClassBreak);
                }
                else if (parentActualObject is RegexStyle)
                {
                    var regexStyle      = (RegexStyle)parentActualObject;
                    var resultRegexItem = regexStyle.RegexItems.Where(regexItem => regexItem.CustomStyles.Contains(style)).FirstOrDefault();
                    regexStyle.RegexItems.Remove(resultRegexItem);
                }

                LayerListHelper.RefreshCache();
                GisEditor.UIManager.BeginRefreshPlugins(new RefreshArgs(GisEditor.LayerListManager.SelectedLayerListItem, RefreshArgsDescription.RemoveSubStyleDescription));
            }
        }
        public MenuItem GetKeyColorsMenuItem(RasterLayer layer)
        {
            var menuItem = new MenuItem();

            menuItem.Header = "Transparency Colors";
            menuItem.Icon   = new Image()
            {
                Source = new BitmapImage(new Uri("/GisEditorInfrastructure;component/Images/Transparent.png", UriKind.RelativeOrAbsolute)), Width = 16, Height = 16
            };
            menuItem.Click += (s, e) =>
            {
                if (layer != null)
                {
                    MrSidKeyColorConfigureWindow window = new MrSidKeyColorConfigureWindow(layer.KeyColors);
                    if (window.ShowDialog().GetValueOrDefault())
                    {
                        MrSidKeyColorConfigureViewModel model = window.DataContext as MrSidKeyColorConfigureViewModel;
                        layer.KeyColors.Clear();

                        foreach (var color in model.Colors)
                        {
                            layer.KeyColors.Add(new GeoColor(color.Color.A, color.Color.R, color.Color.G, color.Color.B));
                        }
                        TileOverlay tileOverlay = LayerListHelper.FindMapElementInLayerList <TileOverlay>(GisEditor.LayerListManager.SelectedLayerListItem);
                        if (tileOverlay != null)
                        {
                            tileOverlay.Refresh();
                        }
                    }
                }
            };

            return(menuItem);
        }
        public static void ResetZoomLevelRange(ZoomLevel selectedZoomLevel, FeatureLayer featureLayer, int from, int to)
        {
            for (int i = 0; i < featureLayer.ZoomLevelSet.CustomZoomLevels.Count; i++)
            {
                var zoomLevel = featureLayer.ZoomLevelSet.CustomZoomLevels[i];
                if (i >= from - 1 && i <= to - 1)
                {
                    foreach (var style in selectedZoomLevel.CustomStyles)
                    {
                        if (!zoomLevel.CustomStyles.Contains(style))
                        {
                            zoomLevel.CustomStyles.Add(style);
                        }
                    }
                }
                else
                {
                    foreach (var style in selectedZoomLevel.CustomStyles)
                    {
                        if (zoomLevel.CustomStyles.Contains(style))
                        {
                            zoomLevel.CustomStyles.Remove(style);
                        }
                    }
                }
            }

            LayerListHelper.RefreshCache();
            GisEditor.UIManager.BeginRefreshPlugins(new RefreshArgs(selectedZoomLevel, RefreshArgsDescription.ResetZoomLevelRangeDescription));
        }
        public static void ApplyStyle(Style newStyle, FeatureLayer currentFeatureLayer, int fromZoomLevel, int toZoomLevel, bool needsRefresh = true)
        {
            currentFeatureLayer.ZoomLevelSet
            .CustomZoomLevels
            .Where(tmpLevel => tmpLevel.CustomStyles.Contains(newStyle))
            .ForEach(tmpLevel => tmpLevel.CustomStyles.Remove(newStyle));

            if (GisEditor.LayerListManager.SelectedLayerListItem != null && GisEditor.LayerListManager.SelectedLayerListItem.ConcreteObject != null)
            {
                FeatureLayer featureLayer = null;
                ZoomLevel    zoomLevel    = null;
                Style        currentStyle = null;
                if ((featureLayer = GisEditor.LayerListManager.SelectedLayerListItem.ConcreteObject as FeatureLayer) != null)
                {
                    AddStyleToZoomLevels(newStyle, fromZoomLevel, toZoomLevel, featureLayer.ZoomLevelSet.CustomZoomLevels);
                }
                else if ((zoomLevel = GisEditor.LayerListManager.SelectedLayerListItem.ConcreteObject as ZoomLevel) != null)
                {
                    var customZoomLevels = (GisEditor.LayerListManager.SelectedLayerListItem.Parent.ConcreteObject as FeatureLayer).ZoomLevelSet.CustomZoomLevels;
                    AddStyleToZoomLevels(newStyle, fromZoomLevel, toZoomLevel, customZoomLevels);
                }
                else if ((currentStyle = GisEditor.LayerListManager.SelectedLayerListItem.ConcreteObject as Style) != null)
                {
                    featureLayer = GisEditor.LayerListManager.SelectedLayerListItem.Parent.Parent.ConcreteObject as FeatureLayer;
                    ReplaceStyle(featureLayer, currentStyle, newStyle);
                }

                if (needsRefresh)
                {
                    LayerListHelper.RefreshCache();
                    GisEditor.UIManager.BeginRefreshPlugins(new RefreshArgs(GisEditor.LayerListManager.SelectedLayerListItem, RefreshArgsDescription.ApplyStyleDescription));
                }
            }
        }
예제 #7
0
        private static void RemoveZoomLevel()
        {
            if (GisEditor.LayerListManager.SelectedLayerListItem == null)
            {
                return;
            }
            ZoomLevel selectedZoomLevel = GisEditor.LayerListManager.SelectedLayerListItem.ConcreteObject as ZoomLevel;

            if (selectedZoomLevel != null)
            {
                FeatureLayer featureLayer = (FeatureLayer)GisEditor.LayerListManager.SelectedLayerListItem.Parent.ConcreteObject;
                foreach (var zoomLevel in featureLayer.ZoomLevelSet.CustomZoomLevels)
                {
                    foreach (var style in selectedZoomLevel.CustomStyles)
                    {
                        if (zoomLevel.CustomStyles.Contains(style))
                        {
                            zoomLevel.CustomStyles.Remove(style);
                        }
                    }
                }

                LayerListHelper.RefreshCache();
                GisEditor.UIManager.BeginRefreshPlugins(new RefreshArgs(selectedZoomLevel, RefreshArgsDescription.RemoveZoomLevelDescription));
            }
        }
예제 #8
0
        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) + 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.FindMapElementInLayerList <FeatureLayer>(GisEditor.LayerListManager.SelectedLayerListItem);
            }

            arguments.AvailableStyleCategories = StylePluginHelper.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 (!styleResults.Canceled)
            {
                ZoomLevelHelper.ApplyStyle(styleResults.CompositeStyle, currentFeatureLayer, styleResults.FromZoomLevelIndex, styleResults.ToZoomLevelIndex);
            }
        }
        public static void RefreshCache()
        {
            TileOverlay tileOverlay = LayerListHelper.FindMapElementInLayerList <TileOverlay>(GisEditor.LayerListManager.SelectedLayerListItem);

            if (tileOverlay != null && tileOverlay.TileCache != null)
            {
                tileOverlay.Invalidate();
            }
        }
        private static void Duplicate()
        {
            if (GisEditor.LayerListManager.SelectedLayerListItem == null)
            {
                return;
            }
            var  compositeStyle = GisEditor.LayerListManager.SelectedLayerListItem.ConcreteObject as CompositeStyle;
            bool needRefersh    = false;

            if (compositeStyle != null)
            {
                var newStyle     = compositeStyle.CloneDeep();
                var featureLayer = LayerListHelper.FindMapElementInLayerList <FeatureLayer>(GisEditor.LayerListManager.SelectedLayerListItem);
                if (newStyle != null && featureLayer != null)
                {
                    foreach (var zoomLevel in featureLayer.ZoomLevelSet.CustomZoomLevels)
                    {
                        var index = zoomLevel.CustomStyles.IndexOf(compositeStyle);
                        if (index >= 0)
                        {
                            zoomLevel.CustomStyles.Insert(index, newStyle);
                        }
                    }
                    needRefersh = true;
                }
            }
            else
            {
                var newStyle = (GisEditor.LayerListManager.SelectedLayerListItem.ConcreteObject as Style).CloneDeep();
                if (newStyle != null)
                {
                    var newStyleItem = GisEditor.StyleManager.GetStyleLayerListItem(newStyle);
                    if (newStyleItem != null)
                    {
                        var parent = GisEditor.LayerListManager.SelectedLayerListItem.Parent as StyleLayerListItem;
                        if (parent != null)
                        {
                            parent.Children.Insert(0, newStyleItem);
                            parent.UpdateConcreteObject();
                            needRefersh = true;
                        }
                    }
                }
            }
            if (needRefersh)
            {
                var tileOverlay = LayerListHelper.FindMapElementInLayerList <TileOverlay>(GisEditor.LayerListManager.SelectedLayerListItem);
                if (tileOverlay != null)
                {
                    tileOverlay.Invalidate();
                    GisEditor.UIManager.BeginRefreshPlugins(new RefreshArgs(GisEditor.LayerListManager.SelectedLayerListItem, RefreshArgsDescription.DuplicateDescription));
                }
            }
        }
예제 #11
0
        public static MenuItem GetAddStyleWizardMenuItem(ShapeFileFeatureLayer shapeFileFeatureLayer)
        {
            var command = new ObservedCommand(() =>
            {
                if (GisEditorWpfMapExtension.AddStyleToLayerWithStyleWizard(new Layer[] { shapeFileFeatureLayer }))
                {
                    LayerListHelper.RefreshCache();
                    GisEditor.UIManager.BeginRefreshPlugins(new RefreshArgs(shapeFileFeatureLayer, RefreshArgsDescription.GetAddStyleWizardMenuItemDescription));
                }
            }, () => true);

            return(GetMenuItem("Style Wizard", "/GisEditorPluginCore;component/Images/addstyle.png", command));
        }
        public static void InsertFromLibrary()
        {
            StyleLibraryWindow library = new StyleLibraryWindow();

            if (library.ShowDialog().GetValueOrDefault())
            {
                var styleItem = GisEditor.LayerListManager.SelectedLayerListItem as StyleLayerListItem;
                if (styleItem != null)
                {
                    TileOverlay containingOverlay  = null;
                    var         compositeStyle     = styleItem.ConcreteObject as CompositeStyle;
                    var         compositeStyleItem = GisEditor.StyleManager.GetStyleLayerListItem(library.Result.CompositeStyle);
                    if (compositeStyle != null)
                    {
                        foreach (var item in compositeStyleItem.Children.Reverse())
                        {
                            styleItem.Children.Insert(0, item);
                        }
                        styleItem.UpdateConcreteObject();
                        containingOverlay = GisEditor.LayerListManager.SelectedLayerListItem.Parent.Parent.ConcreteObject as TileOverlay;
                    }
                    else if (styleItem.ConcreteObject is Styles.Style && styleItem.Parent.ConcreteObject is Styles.Style)
                    {
                        var index = styleItem.Parent.Children.IndexOf(styleItem);
                        foreach (var item in compositeStyleItem.Children)
                        {
                            index++;
                            styleItem.Parent.Children.Insert(index, item);
                        }
                        ((StyleLayerListItem)styleItem.Parent).UpdateConcreteObject();
                        containingOverlay = LayerListHelper.FindMapElementInLayerList <TileOverlay>(GisEditor.LayerListManager.SelectedLayerListItem);
                    }
                    else
                    {
                        foreach (var item in compositeStyleItem.Children.Reverse())
                        {
                            styleItem.Children.Insert(0, item);
                        }
                        styleItem.UpdateConcreteObject();
                        containingOverlay = LayerListHelper.FindMapElementInLayerList <TileOverlay>(GisEditor.LayerListManager.SelectedLayerListItem);
                    }
                    if (containingOverlay != null)
                    {
                        containingOverlay.Invalidate();
                        GisEditor.UIManager.BeginRefreshPlugins(new RefreshArgs(containingOverlay, RefreshArgsDescription.InsertFromLibraryDescription));
                    }
                }
            }
        }
        public static MenuItem GetEditStyleMenuItem()
        {
            var command = new ObservedCommand(new Action(() =>
            {
                LayerListHelper.EditStyle(GisEditor.LayerListManager.SelectedLayerListItem);
            }), new Func <bool>(() =>
            {
                if (GisEditor.LayerListManager.SelectedLayerListItem == null)
                {
                    return(false);
                }
                return(GisEditor.LayerListManager.SelectedLayerListItem.ConcreteObject is Style);
            }));

            return(GetMenuItem("Edit", "/GisEditorPluginCore;component/Images/editstyle.png", command));
        }
        public static void ModifySelectedStyle(Style selectedStyle, Style newStyle, int from, int to)
        {
            if (GisEditor.LayerListManager.SelectedLayerListItem != null && GisEditor.LayerListManager.SelectedLayerListItem.ConcreteObject is Style)
            {
                if (selectedStyle != GisEditor.LayerListManager.SelectedLayerListItem.ConcreteObject)
                {
                    if (!IsSubStyleSelected(selectedStyle) && selectedStyle != GisEditor.LayerListManager.SelectedLayerListItem.ConcreteObject)
                    {
                        selectedStyle = (Style)GisEditor.LayerListManager.SelectedLayerListItem.ConcreteObject;
                    }
                }

                FeatureLayer currentLayer     = LayerListHelper.FindMapElementInLayerList <FeatureLayer>(GisEditor.LayerListManager.SelectedLayerListItem);
                ZoomLevel    currentZoomLevel = LayerListHelper.FindMapElementInLayerList <ZoomLevel>(GisEditor.LayerListManager.SelectedLayerListItem);
                int          originalFrom     = GisEditor.ActiveMap.GetSnappedZoomLevelIndex(currentZoomLevel.Scale, false) + 1;
                int          originalTo       = (int)currentZoomLevel.ApplyUntilZoomLevel;

                Style nextSelectedStyle = newStyle.CloneDeep();
                ReplaceStyle(currentLayer, selectedStyle, newStyle);

                if (originalFrom != from || originalTo != to)
                {
                    for (int i = 0; i < currentLayer.ZoomLevelSet.CustomZoomLevels.Count; i++)
                    {
                        var zoomLevel = currentLayer.ZoomLevelSet.CustomZoomLevels[i];
                        if (i >= from - 1 && i <= to - 1)
                        {
                            if (!zoomLevel.CustomStyles.Contains(newStyle))
                            {
                                zoomLevel.CustomStyles.Add(newStyle);
                            }
                        }
                        else
                        {
                            if (zoomLevel.CustomStyles.Contains(newStyle))
                            {
                                zoomLevel.CustomStyles.Remove(newStyle);
                            }
                        }
                    }
                }
                GisEditor.LayerListManager.SelectedLayerListItem.ConcreteObject = newStyle;
                LayerListHelper.RefreshCache();
                GisEditor.UIManager.BeginRefreshPlugins(new RefreshArgs(GisEditor.LayerListManager.SelectedLayerListItem, RefreshArgsDescription.ModifySelectedStyleDescription));
            }
        }
        private void ExchangeElement(LayerListItem dragedEntity, LayerListItem targetEntity)
        {
            var dragEntityParent   = dragedEntity.Parent;
            var targetEntityParent = targetEntity.Parent;

            if (dragEntityParent == targetEntityParent)
            {
                var targetStyleItem = targetEntityParent as StyleLayerListItem;
                if (targetStyleItem != null)
                {
                    var targetStyle = ((StyleLayerListItem)targetEntity);
                    var dragedStyle = ((StyleLayerListItem)dragedEntity);
                    if (targetStyle != null && dragedStyle != null)
                    {
                        int targetStyleIndex = targetStyleItem.Children.IndexOf(targetStyle);
                        int dragedStyleIndex = targetStyleItem.Children.IndexOf(dragedStyle);

                        targetStyleItem.Children[targetStyleIndex] = dragedStyle;
                        targetStyleItem.Children[dragedStyleIndex] = targetStyle;
                        targetStyleItem.UpdateConcreteObject();
                    }
                }
                RearrangeStylesInZoomLevel(dragedEntity, targetEntity);

                var componentStyleEntity = LayerListHelper.FindItemInLayerList <CompositeStyle>(dragedEntity);

                if (componentStyleEntity != null)
                {
                    var bitmapSource = new BitmapImage();
                    bitmapSource = ((StyleLayerListItem)componentStyleEntity).GetPreviewSource(23, 23) as BitmapImage;
                    componentStyleEntity.PreviewImage = new Image {
                        Source = bitmapSource
                    };
                    var featureLayer = componentStyleEntity.Parent.ConcreteObject as FeatureLayer;
                }
                dragedEntity.IsSelected = true;
                TileOverlay overlay = LayerListHelper.FindMapElementInLayerList <TileOverlay>(dragedEntity);
                if (overlay != null)
                {
                    overlay.Invalidate();
                }
            }
        }
        private void OverlayItemPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            var currentLayerListItem = sender as LayerListItem;

            if (e.PropertyName == "IsChecked")
            {
                if (GisEditor.LayerListManager.SelectedLayerListItems.Contains(currentLayerListItem))
                {
                    foreach (var item in GisEditor.LayerListManager.SelectedLayerListItems)
                    {
                        if (item.IsChecked != currentLayerListItem.IsChecked)
                        {
                            item.IsChecked = currentLayerListItem.IsChecked;
                        }
                    }
                }
                if (!currentLayerListItem.IsChecked)
                {
                    LayerListHelper.RefreshInteractiveOverlays(currentLayerListItem);
                }
            }
        }
        private void Tree_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs <object> e)
        {
            LayerListItem selectedItem = tree.SelectedItem as LayerListItem;

            if (selectedItem != null)
            {
                GisEditor.LayerListManager.SelectedLayerListItem = selectedItem;
                var overlay = LayerListHelper.FindMapElementInLayerList <Overlay>(selectedItem);
                var layer   = LayerListHelper.FindMapElementInLayerList <Layer>(selectedItem);

                if (GisEditor.ActiveMap != null)
                {
                    if (overlay != null)
                    {
                        GisEditor.ActiveMap.ActiveOverlay = overlay;
                    }
                    if (layer != null)
                    {
                        GisEditor.ActiveMap.ActiveLayer = layer;
                    }
                }
            }
        }
 private void Map_Drop(object sender, DragEventArgs e)
 {
     LayerListHelper.AddDropFilesToActiveMap(e);
 }
        public static void ReplaceFromLibrary()
        {
            StyleLibraryWindow library = new StyleLibraryWindow();

            if (library.ShowDialog().GetValueOrDefault())
            {
                if (GisEditor.LayerListManager.SelectedLayerListItem == null)
                {
                    return;
                }
                var         styleItem         = GisEditor.LayerListManager.SelectedLayerListItem;
                TileOverlay containingOverlay = null;
                var         compositeStyle    = GisEditor.LayerListManager.SelectedLayerListItem.ConcreteObject as CompositeStyle;
                if (compositeStyle != null)
                {
                    FeatureLayer currentFeatureLayer = GisEditor.LayerListManager.SelectedLayerListItem.Parent.ConcreteObject as FeatureLayer;
                    if (currentFeatureLayer != null)
                    {
                        foreach (var zoomLevel in currentFeatureLayer.ZoomLevelSet.CustomZoomLevels)
                        {
                            var index = zoomLevel.CustomStyles.IndexOf(compositeStyle);
                            if (index >= 0)
                            {
                                zoomLevel.CustomStyles.RemoveAt(index);
                                zoomLevel.CustomStyles.Insert(index, library.Result.CompositeStyle);
                            }
                        }
                        containingOverlay = GisEditor.LayerListManager.SelectedLayerListItem.Parent.Parent.ConcreteObject as TileOverlay;
                    }
                }
                else if (styleItem.ConcreteObject is Styles.Style && styleItem.Parent.ConcreteObject is Styles.Style)
                {
                    var index = styleItem.Parent.Children.IndexOf(styleItem);
                    styleItem.Parent.Children.RemoveAt(index);
                    var compositeStyleItem = GisEditor.StyleManager.GetStyleLayerListItem(library.Result.CompositeStyle);
                    foreach (var item in compositeStyleItem.Children)
                    {
                        styleItem.Parent.Children.Insert(index, item);
                        index++;
                    }
                    ((StyleLayerListItem)styleItem.Parent).UpdateConcreteObject();
                    containingOverlay = LayerListHelper.FindMapElementInLayerList <TileOverlay>(GisEditor.LayerListManager.SelectedLayerListItem);
                }
                else
                {
                    styleItem.Children.Clear();
                    var compositeStyleItem = GisEditor.StyleManager.GetStyleLayerListItem(library.Result.CompositeStyle);
                    foreach (var item in compositeStyleItem.Children)
                    {
                        styleItem.Children.Add(item);
                    }
                    ((StyleLayerListItem)styleItem).UpdateConcreteObject();
                    containingOverlay = LayerListHelper.FindMapElementInLayerList <TileOverlay>(GisEditor.LayerListManager.SelectedLayerListItem);
                }
                if (containingOverlay != null)
                {
                    containingOverlay.Invalidate();
                    GisEditor.UIManager.BeginRefreshPlugins(new RefreshArgs(containingOverlay, RefreshArgsDescription.ReplaceFromLibraryDescription));
                }
            }
        }
        public static void EditStyle(LayerListItem selectedLayerListItem)
        {
            var componentStyleItem = LayerListHelper.FindItemInLayerList <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 = StylePluginHelper.GetStyleCategoriesByFeatureLayer(styleArguments.FeatureLayer);
                    int from = 0;
                    int to   = GisEditor.ActiveMap.ZoomLevelSet.CustomZoomLevels.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().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);
                                }
                            }
                            foreach (var overlay in GisEditor.ActiveMap.GetOverlaysContaining(styleArguments.FeatureLayer))
                            {
                                if (overlay.MapArguments != null)
                                {
                                    overlay.Invalidate();
                                }
                            }
                            GisEditor.UIManager.BeginRefreshPlugins(new RefreshArgs(styleResults, RefreshArgsDescription.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);
                    if (styleBuilder.ShowDialog().GetValueOrDefault())
                    {
                        styleArguments.AppliedCallback(styleBuilder.StyleBuilderResult);
                    }
                }
            }
        }
        protected override LayerListItem GetLayerListItemCore(object concreteObject)
        {
            if (concreteObject is Overlay)
            {
                var overlay         = (Overlay)concreteObject;
                var overlayListItem = new LayerListItem();
                overlayListItem.ConcreteObject              = concreteObject;
                overlayListItem.CheckBoxVisibility          = Visibility.Visible;
                overlayListItem.ChildrenContainerVisibility = Visibility.Visible;
                overlayListItem.IsChecked = overlay.IsVisible;
                overlayListItem.Name      = overlay.Name;
                overlayListItem.HighlightBackgroundBrush = GetDefaultLayerGroupBackground();
                overlayListItem.PropertyChanged         += OverlayItemPropertyChanged;
                if (GisEditor.LayerListManager.SelectedLayerListItem != null && overlay == GisEditor.LayerListManager.SelectedLayerListItem.ConcreteObject)
                {
                    overlayListItem.HighlightBackgroundBrush         = new SolidColorBrush(Colors.LightBlue);
                    GisEditor.LayerListManager.SelectedLayerListItem = overlayListItem;
                }
                MenuItem toTopMenuItem    = LayerListMenuItemHelper.GetMovementMenuItem(MovementAction.ToTop);
                MenuItem toBottomMenuItem = LayerListMenuItemHelper.GetMovementMenuItem(MovementAction.ToBottom);
                MenuItem upMenuItem       = LayerListMenuItemHelper.GetMovementMenuItem(MovementAction.Up);
                MenuItem downMenuItem     = LayerListMenuItemHelper.GetMovementMenuItem(MovementAction.Down);

                overlayListItem.ContextMenuItems.Add(toTopMenuItem);
                overlayListItem.ContextMenuItems.Add(toBottomMenuItem);
                overlayListItem.ContextMenuItems.Add(upMenuItem);
                overlayListItem.ContextMenuItems.Add(downMenuItem);
                overlayListItem.ContextMenuItems.Add(new MenuItem()
                {
                    Header = "--"
                });
                overlayListItem.ContextMenuItems.Add(LayerListMenuItemHelper.GetZoomToExtentMenuItem());
                overlayListItem.ContextMenuItems.Add(LayerListMenuItemHelper.GetRenameMenuItem());
                overlayListItem.ContextMenuItems.Add(LayerListMenuItemHelper.GetRemoveOverlayMenuItem());
                overlayListItem.ContextMenuItems.Add(new MenuItem()
                {
                    Header = "--"
                });
                if (concreteObject is LayerOverlay)
                {
                    overlayListItem.ContextMenuItems.Add(LayerListMenuItemHelper.GetAddLayerMenuItem());
                    MenuItem newLayerItem = LayerListMenuItemHelper.GetNewLayerMenuItem();
                    if (newLayerItem != null)
                    {
                        overlayListItem.ContextMenuItems.Add(newLayerItem);
                    }
                    overlayListItem.ContextMenuItems.Add(LayerListMenuItemHelper.GetRefreshLayersMenuItem((LayerOverlay)concreteObject));
                    //overlayListItem.ContextMenuItems.Add(LayerListMenuItemHelper.GetCloneLayerCountMenuItem((LayerOverlay)concreteObject));
                }
                if (concreteObject is TileOverlay)
                {
                    overlayListItem.ContextMenuItems.Add(LayerListMenuItemHelper.GetTileTypeMenuItem((TileOverlay)concreteObject));
                }

                //overlayListItem.ContextMenuItems.Add(new MenuItem() { Header = "--" });
                //overlayListItem.ContextMenuItems.Add(LayerListMenuItemHelper.GetSetExceptionModeMenuItem());

                if (overlayListItem.ConcreteObject is BingMapsOverlay)
                {
                    //e.LayerListItem.Icon = new Image { Source = new BitmapImage(new Uri("/GisEditorPluginCore;component/Images/BingMaps.png", UriKind.Relative)) };
                    overlayListItem.SideImage = new Image {
                        Source = new BitmapImage(new Uri("/GisEditorPluginCore;component/Images/dr_base_maps.png", UriKind.Relative)), Width = 16, Height = 16
                    };
                    overlayListItem.ContextMenuItems.Add(LayerListMenuItemHelper.GetBingMapStyleMenuItem());
                    overlayListItem.ContextMenuItems.Add(LayerListMenuItemHelper.GetBaseMapsCacheMenuItem());
                    overlayListItem.ContextMenuItems.Add(LayerListMenuItemHelper.GetTransparencyMenuItem(((BingMapsOverlay)overlayListItem.ConcreteObject).OverlayCanvas.Opacity));
                }
                else if (overlayListItem.ConcreteObject is OpenStreetMapOverlay)
                {
                    //e.LayerListItem.Icon = new Image { Source = new BitmapImage(new Uri("/GisEditorPluginCore;component/Images/osm_logo.png", UriKind.Relative)) };
                    overlayListItem.SideImage = new Image {
                        Source = new BitmapImage(new Uri("/GisEditorPluginCore;component/Images/dr_base_maps.png", UriKind.Relative)), Width = 16, Height = 16
                    };
                    overlayListItem.ContextMenuItems.Add(LayerListMenuItemHelper.GetBaseMapsCacheMenuItem());
                    overlayListItem.ContextMenuItems.Add(LayerListMenuItemHelper.GetTransparencyMenuItem(((OpenStreetMapOverlay)overlayListItem.ConcreteObject).OverlayCanvas.Opacity));
                }
                else if (overlayListItem.ConcreteObject is WorldMapKitMapOverlay)
                {
                    overlayListItem.SideImage = new Image {
                        Source = new BitmapImage(new Uri("/GisEditorPluginCore;component/Images/dr_base_maps.png", UriKind.Relative)), Width = 16, Height = 16
                    };
                    overlayListItem.ContextMenuItems.Add(LayerListMenuItemHelper.GetWorldMapKitStyleMenuItem());
                    overlayListItem.ContextMenuItems.Add(LayerListMenuItemHelper.GetBaseMapsCacheMenuItem());

                    //e.LayerListItem.Icon = new Image { Source = new BitmapImage(new Uri("/GisEditorPluginCore;component/Images/WMKOverlay.png", UriKind.Relative)) };
                    overlayListItem.ContextMenuItems.Add(LayerListMenuItemHelper.GetTransparencyMenuItem(((WorldMapKitMapOverlay)overlayListItem.ConcreteObject).OverlayCanvas.Opacity));
                }
                else if (overlayListItem.ConcreteObject is DynamicLayerOverlay)
                {
                    overlayListItem.Name       = string.IsNullOrEmpty(overlay.Name) ? "Dynamic Layer Group" : overlay.Name;
                    toTopMenuItem.IsEnabled    = false;
                    toBottomMenuItem.IsEnabled = false;
                    upMenuItem.IsEnabled       = false;
                    downMenuItem.IsEnabled     = false;
                    InMemoryFeatureLayer[] featureLayersToDelete = ((DynamicLayerOverlay)overlay).Layers.OfType <InMemoryFeatureLayer>().Where(l => l.InternalFeatures.Count == 0).ToArray();
                    foreach (var item in featureLayersToDelete)
                    {
                        ((DynamicLayerOverlay)overlay).Layers.Remove(item);
                    }

                    //overlayListItem = null;
                }
                else if (overlayListItem.ConcreteObject is MeasureTrackInteractiveOverlay)
                {
                    if (Singleton <MeasureSetting> .Instance.AllowCollectFixedElements)
                    {
                        overlayListItem = LayerListHelper.CreateLayerListItemForMeasureOverlay(overlayListItem);
                    }
                    else
                    {
                        overlayListItem = null;
                    }
                }
                else if (overlayListItem.ConcreteObject is LayerOverlay)
                {
                    var layerOverlay = (LayerOverlay)overlay;

                    //e.LayerListItem.Icon = new Image { Source = new BitmapImage(new Uri("/GisEditorPluginCore;component/Images/LayerOverlay.png", UriKind.Relative)) };
                    overlayListItem.Name = string.IsNullOrEmpty(layerOverlay.Name) ? "Layer Group" : layerOverlay.Name;
                    overlayListItem.ChildrenContainerVisibility = Visibility.Visible;
                    overlayListItem.SideImage = new Image {
                        Source = new BitmapImage(new Uri("/GisEditorPluginCore;component/Images/up.png", UriKind.Relative))
                    };

                    //Dictionary<Layer, bool> elementVisibleDictionary = new Dictionary<Layer, bool>();
                    //layerOverlay.Layers.ForEach(layer => { elementVisibleDictionary.Add(layer, layer.IsVisible); });
                    overlayListItem.IsChecked = layerOverlay.Layers.Any(layer => layer.IsVisible);

                    //entity.SubEntities.ForEach(mapEntity => { mapEntity.IsVisible = elementVisibleDictionary[mapEntity]; });
                }
                else
                {
                    overlayListItem = null;
                }
                return(overlayListItem);
            }
            else if (concreteObject is Layer)
            {
                GdiPlusRasterLayerPlugin gdiPlusRasterLayerPlugin = new GdiPlusRasterLayerPlugin();
                LayerListItem            layerListItem            = gdiPlusRasterLayerPlugin.GetLayerListItem(concreteObject as Layer);
                if (string.IsNullOrEmpty(layerListItem.Name))
                {
                    layerListItem.Name = concreteObject.GetType().Name;
                }
                layerListItem.ContextMenuItems.Add(LayerListMenuItemHelper.GetMovementMenuItem(MovementAction.ToTop));
                layerListItem.ContextMenuItems.Add(LayerListMenuItemHelper.GetMovementMenuItem(MovementAction.ToBottom));
                layerListItem.ContextMenuItems.Add(LayerListMenuItemHelper.GetMovementMenuItem(MovementAction.Up));
                layerListItem.ContextMenuItems.Add(LayerListMenuItemHelper.GetMovementMenuItem(MovementAction.Down));
                layerListItem.ContextMenuItems.Add(LayerListMenuItemHelper.GetZoomToExtentMenuItem());
                layerListItem.ContextMenuItems.Add(LayerListMenuItemHelper.GetRenameMenuItem());
                layerListItem.ContextMenuItems.Add(LayerListMenuItemHelper.GetRemoveLayerMenuItem());
                return(layerListItem);
            }
            else
            {
                return(null);
            }
        }
        private static void MoveItem(MovementAction movementAction)
        {
            var selectedItem = GisEditor.LayerListManager.SelectedLayerListItem;

            if (selectedItem != null && selectedItem.ConcreteObject != null)
            {
                Layer   layer       = selectedItem.ConcreteObject as Layer;
                Overlay overlay     = selectedItem.ConcreteObject as Overlay;
                Style   styleItem   = selectedItem.ConcreteObject as Style;
                bool    needRefresh = false;

                if (layer != null)
                {
                    Overlay parentOverlay = GisEditor.ActiveMap.GetOverlaysContaining(layer).FirstOrDefault();
                    if (parentOverlay is LayerOverlay)
                    {
                        LayerOverlay layerOverlay = (LayerOverlay)parentOverlay;
                        needRefresh = MoveLayerInLayerOverlay(layer, layerOverlay, movementAction);
                    }
                }
                else if (overlay != null)
                {
                    needRefresh = MoveOverlay(overlay, movementAction);
                }
                else if (styleItem != null)
                {
                    var featureLayer = selectedItem.Parent.ConcreteObject as FeatureLayer;
                    if (featureLayer != null && selectedItem is StyleLayerListItem)
                    {
                        int from = 0, to = 0;
                        var array = ((StyleLayerListItem)selectedItem).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);
                        }
                        needRefresh = MoveStyle(styleItem, featureLayer, from, to, movementAction);
                    }
                    else
                    {
                        var parent = selectedItem.Parent as StyleLayerListItem;
                        if (parent != null)
                        {
                            var currentIndex = parent.Children.IndexOf(selectedItem);
                            var styleCount   = parent.Children.Count;
                            switch (movementAction)
                            {
                            case MovementAction.Down:
                                if (currentIndex + 1 <= styleCount - 1)
                                {
                                    parent.Children.RemoveAt(currentIndex);
                                    parent.Children.Insert(currentIndex + 1, selectedItem);
                                    parent.UpdateConcreteObject();
                                    needRefresh = true;
                                }
                                break;

                            case MovementAction.Up:
                                if (currentIndex - 1 >= 0)
                                {
                                    parent.Children.RemoveAt(currentIndex);
                                    parent.Children.Insert(currentIndex - 1, selectedItem);
                                    parent.UpdateConcreteObject();
                                    needRefresh = true;
                                }
                                break;

                            case MovementAction.ToTop:
                                if (currentIndex != 0)
                                {
                                    parent.Children.RemoveAt(currentIndex);
                                    parent.Children.Insert(0, selectedItem);
                                    parent.UpdateConcreteObject();
                                    needRefresh = true;
                                }
                                break;

                            case MovementAction.ToBottom:
                                if (currentIndex != styleCount - 1)
                                {
                                    parent.Children.RemoveAt(currentIndex);
                                    parent.Children.Add(selectedItem);
                                    parent.UpdateConcreteObject();
                                    needRefresh = true;
                                }
                                break;
                            }
                        }
                    }
                    if (needRefresh)
                    {
                        var tileOverlay = LayerListHelper.FindMapElementInLayerList <TileOverlay>(GisEditor.LayerListManager.SelectedLayerListItem);
                        if (tileOverlay != null && tileOverlay.MapArguments != null)
                        {
                            tileOverlay.Invalidate();
                        }
                    }
                }
                if (needRefresh)
                {
                    GisEditor.UIManager.BeginRefreshPlugins(new RefreshArgs(selectedItem, RefreshArgsDescription.MoveItemDescription));
                }
            }
        }
        private static bool MoveStyle(Style style, FeatureLayer featureLayer, int from, int to, MovementAction movementAction)
        {
            var  customZoomLevels = featureLayer.ZoomLevelSet.CustomZoomLevels;
            bool needRefresh      = false;

            for (int i = from - 1; i < to; i++)
            {
                var zoomLevel    = customZoomLevels[i];
                var currentIndex = zoomLevel.CustomStyles.IndexOf(style);
                var styleCount   = zoomLevel.CustomStyles.Count;
                switch (movementAction)
                {
                case MovementAction.Down:
                    if (currentIndex - 1 >= 0)
                    {
                        zoomLevel.CustomStyles.RemoveAt(currentIndex);
                        zoomLevel.CustomStyles.Insert(currentIndex - 1, style);
                        needRefresh = true;
                    }
                    break;

                case MovementAction.Up:
                    if (currentIndex + 1 <= styleCount - 1)
                    {
                        zoomLevel.CustomStyles.RemoveAt(currentIndex);
                        zoomLevel.CustomStyles.Insert(currentIndex + 1, style);
                        needRefresh = true;
                    }
                    break;

                case MovementAction.ToTop:
                    if (currentIndex != styleCount - 1)
                    {
                        zoomLevel.CustomStyles.RemoveAt(currentIndex);
                        zoomLevel.CustomStyles.Add(style);
                        needRefresh = true;
                    }
                    break;

                case MovementAction.ToBottom:
                    if (currentIndex != 0)
                    {
                        zoomLevel.CustomStyles.RemoveAt(currentIndex);
                        zoomLevel.CustomStyles.Insert(0, style);
                        needRefresh = true;
                    }
                    break;

                default:
                    break;
                }
            }
            if (needRefresh)
            {
                TileOverlay overlay = LayerListHelper.FindMapElementInLayerList <TileOverlay>(GisEditor.LayerListManager.SelectedLayerListItem);
                if (overlay != null)
                {
                    overlay.Invalidate();
                }
            }
            return(needRefresh);
        }