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);
        }
Beispiel #2
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));
                }
            }
        }
        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 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 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;
                    }
                }
            }
        }
        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));
                }
            }
        }
        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);
        }