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);
            }
        }
Beispiel #2
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.InvalidateTileOverlay();
                GisEditor.UIManager.InvokeRefreshPlugins(new RefreshArgs(GisEditor.LayerListManager.SelectedLayerListItem, RefreshArgsDescriptions.RemoveZoomLevelDescription));
            }
        }
Beispiel #3
0
        //public static MenuItem GetRemoveSubStyleMenuItem()
        //{
        //    var command = new ObservedCommand(RemoveSubStyle, () => true);
        //    return GetMenuItem("Remove", "/GisEditorPluginCore;component/Images/unload.png", command);
        //}

        private static void RemoveSubStyle()
        {
            if (GisEditor.LayerListManager.SelectedLayerListItem == null)
            {
                return;
            }
            Styles.Style style = GisEditor.LayerListManager.SelectedLayerListItem.ConcreteObject as Styles.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.InvalidateTileOverlay();
                GisEditor.UIManager.InvokeRefreshPlugins(new RefreshArgs(GisEditor.LayerListManager.SelectedLayerListItem, RefreshArgsDescriptions.RemoveSubStyleDescription));
            }
        }
        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.InvalidateTileOverlay();
                    GisEditor.UIManager.InvokeRefreshPlugins(new RefreshArgs(GisEditor.LayerListManager.SelectedLayerListItem, RefreshArgsDescriptions.ApplyStyleDescription));
                }
            }
        }
        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.InvalidateTileOverlay();
            GisEditor.UIManager.InvokeRefreshPlugins(new RefreshArgs(selectedZoomLevel, RefreshArgsDescriptions.ResetZoomLevelRangeDescription));
        }
Beispiel #6
0
 private static void RemoveStyle()
 {
     if (GisEditor.LayerListManager.SelectedLayerListItem == null)
     {
         return;
     }
     //var styleItem = GisEditor.LayerListManager.SelectedLayerListItem.ConcreteObject as StyleItem;
     //if (styleItem != null)
     {
         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.InvalidateTileOverlay();
         GisEditor.UIManager.InvokeRefreshPlugins(new RefreshArgs(GisEditor.LayerListManager.SelectedLayerListItem, RefreshArgsDescriptions.RemoveStyleDescription));
     }
 }
        public static void InvalidateTileOverlay()
        {
            TileOverlay tileOverlay = LayerListHelper.FindMapElementInTree <TileOverlay>(GisEditor.LayerListManager.SelectedLayerListItem);

            if (tileOverlay != null)
            {
                tileOverlay.Invalidate();
            }
        }
        public static MenuItem GetStyleBuilderMenuItem()
        {
            var command = new ObservedCommand(() =>
            {
                LayerListHelper.AddStyle();
            }, () => true);

            return(GetMenuItem("Style Builder", "/GisEditorInfrastructure;component/Images/style_builder_16x16.png", command));
        }
Beispiel #9
0
        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.FindMapElementInTree <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.FindMapElementInTree <TileOverlay>(GisEditor.LayerListManager.SelectedLayerListItem);
                if (tileOverlay != null)
                {
                    tileOverlay.Invalidate();
                    GisEditor.UIManager.InvokeRefreshPlugins(new RefreshArgs(GisEditor.LayerListManager.SelectedLayerListItem, RefreshArgsDescriptions.DuplicateDescription));
                }
            }
        }
Beispiel #10
0
        public static MenuItem GetAddStyleWizardMenuItem(FeatureLayer featureLayer)
        {
            var command = new ObservedCommand(() =>
            {
                if (AddStyleToLayerWithStyleWizard(new Layer[] { featureLayer }))
                {
                    LayerListHelper.InvalidateTileOverlay();
                    GisEditor.UIManager.InvokeRefreshPlugins(new RefreshArgs(featureLayer, RefreshArgsDescriptions.GetAddStyleWizardMenuItemDescription));
                }
            }, () => true);

            return(GetMenuItem("Style Wizard", "/GisEditorInfrastructure;component/Images/addstyle.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)
                {
                    //The following check is for issue-7208 and issue-7213.
                    //When we double click on a RegexItem, we actually mean to edit the RegextItem's parent - the RegexStyle.
                    //But the SelectedEntity matches up with the RegextItem, not the RegextStyle, so we need to have this check.
                    //Anyways, this is quite complicated, jsut reconsider before you modify the following code.
                    if (!IsSubStyleSelected(selectedStyle) && selectedStyle != GisEditor.LayerListManager.SelectedLayerListItem.ConcreteObject)
                    {
                        selectedStyle = (Style)GisEditor.LayerListManager.SelectedLayerListItem.ConcreteObject;
                    }
                }

                FeatureLayer currentLayer     = LayerListHelper.FindMapElementInTree <FeatureLayer>(GisEditor.LayerListManager.SelectedLayerListItem);
                ZoomLevel    currentZoomLevel = LayerListHelper.FindMapElementInTree <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.InvalidateTileOverlay();
                GisEditor.UIManager.InvokeRefreshPlugins(new RefreshArgs(GisEditor.LayerListManager.SelectedLayerListItem, RefreshArgsDescriptions.ModifySelectedStyleDescription));
            }
        }
        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.FindMapElementInTree <TileOverlay>(GisEditor.LayerListManager.SelectedLayerListItem);
                    }
                    else
                    {
                        foreach (var item in compositeStyleItem.Children.Reverse())
                        {
                            styleItem.Children.Insert(0, item);
                        }
                        styleItem.UpdateConcreteObject();
                        containingOverlay = LayerListHelper.FindMapElementInTree <TileOverlay>(GisEditor.LayerListManager.SelectedLayerListItem);
                    }
                    if (containingOverlay != null)
                    {
                        containingOverlay.Invalidate();
                        GisEditor.UIManager.InvokeRefreshPlugins(new RefreshArgs(containingOverlay, RefreshArgsDescriptions.InsertFromLibraryDescription));
                    }
                }
            }
        }
Beispiel #13
0
        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", "/GisEditorInfrastructure;component/Images/editstyle.png", command));
        }
Beispiel #14
0
        private static void SetDrawingMargin(MenuItem menuItem, int marginValue)
        {
            if (GisEditor.LayerListManager.SelectedLayerListItem == null)
            {
                return;
            }
            var featureLayer = GisEditor.LayerListManager.SelectedLayerListItem.ConcreteObject as FeatureLayer;

            if (featureLayer != null)
            {
                featureLayer.DrawingMarginInPixel = marginValue;
                var parentOverlay = LayerListHelper.FindMapElementInTree <TileOverlay>(GisEditor.LayerListManager.SelectedLayerListItem);
                parentOverlay.Invalidate();

                foreach (MenuItem item in ((MenuItem)menuItem.Parent).Items)
                {
                    item.IsChecked = item.Header.Equals(marginValue.ToString() + "%");
                }
            }
        }
        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;
                        int to   = 0;

                        var       resultZoomLevels = LayerListHelper.GetZoomLevelsAccordingToSacle(featureLayer);
                        ZoomLevel zoomLevel        = resultZoomLevels.OrderByDescending(zl => zl.Scale).FirstOrDefault(z => z.CustomStyles.Contains(selectedItem.ConcreteObject));

                        if (zoomLevel != null)
                        {
                            from = GisEditor.ActiveMap.GetSnappedZoomLevelIndex(zoomLevel.Scale, false) + 1;
                            to   = (int)zoomLevel.ApplyUntilZoomLevel;
                        }

                        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);
                        }
                        if (from < 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.FindMapElementInTree <TileOverlay>(GisEditor.LayerListManager.SelectedLayerListItem);
                        if (tileOverlay != null && tileOverlay.MapArguments != null)
                        {
                            tileOverlay.Invalidate();
                        }
                    }
                }
                if (needRefresh)
                {
                    GisEditor.UIManager.InvokeRefreshPlugins(new RefreshArgs(selectedItem, RefreshArgsDescriptions.MoveItemDescription));
                }
            }
        }
        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);
                        }
                    }
                }
            }
        }
Beispiel #17
0
        public static void ReplaceFromLibrary()
        {
            StyleLibraryWindow library = new StyleLibraryWindow();

            if (library.ShowDialog().GetValueOrDefault())
            {
                if (GisEditor.LayerListManager.SelectedLayerListItem == null)
                {
                    return;
                }
                var styleItem = GisEditor.LayerListManager.SelectedLayerListItem;
                //var styleItem = GisEditor.LayerListManager.SelectedLayerListItem.ConcreteObject as StyleItem;
                //if (styleItem != null)
                {
                    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.FindMapElementInTree <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.FindMapElementInTree <TileOverlay>(GisEditor.LayerListManager.SelectedLayerListItem);
                    }
                    if (containingOverlay != null)
                    {
                        containingOverlay.Invalidate();
                        GisEditor.UIManager.InvokeRefreshPlugins(new RefreshArgs(containingOverlay, RefreshArgsDescriptions.ReplaceFromLibraryDescription));
                    }
                }
            }
        }
        private static void ZoomToExtent()
        {
            RectangleShape resultExtent = null;

            if (GisEditor.LayerListManager.SelectedLayerListItem == null)
            {
                return;
            }
            if (GisEditor.LayerListManager.SelectedLayerListItem.ConcreteObject is Overlay && GisEditor.LayerListManager.SelectedLayerListItems.Count > 0)
            {
                Collection <RectangleShape> extents = new Collection <RectangleShape>();
                foreach (var item in GisEditor.LayerListManager.SelectedLayerListItems)
                {
                    var tmpOverlay = item.ConcreteObject as Overlay;
                    if (tmpOverlay != null)
                    {
                        extents.Add(tmpOverlay.GetBoundingBox());
                    }
                }
                resultExtent = ExtentHelper.GetBoundingBoxOfItems(extents);
            }
            else if (GisEditor.LayerListManager.SelectedLayerListItems.Count > 0)
            {
                Collection <RectangleShape> extents = new Collection <RectangleShape>();
                foreach (var item in GisEditor.LayerListManager.SelectedLayerListItems)
                {
                    Layer tmpLayer = item.ConcreteObject as Layer;
                    if (tmpLayer != null && tmpLayer.HasBoundingBox)
                    {
                        tmpLayer.SafeProcess(() =>
                        {
                            extents.Add(tmpLayer.GetBoundingBox());
                        });

                        //tmpLayer.Open();
                        //extents.Add(tmpLayer.GetBoundingBox());
                        //tmpLayer.Close();
                    }
                }
                resultExtent = ExtentHelper.GetBoundingBoxOfItems(extents);
            }
            else if (GisEditor.LayerListManager.SelectedLayerListItem.ConcreteObject is Overlay)
            {
                resultExtent = (GisEditor.LayerListManager.SelectedLayerListItem.ConcreteObject as Overlay).GetBoundingBox();
            }
            else if (GisEditor.LayerListManager.SelectedLayerListItem.ConcreteObject is Layer)
            {
                Layer layer = GisEditor.LayerListManager.SelectedLayerListItem.ConcreteObject as Layer;
                if (layer.HasBoundingBox)
                {
                    layer.SafeProcess(() =>
                    {
                        resultExtent = layer.GetBoundingBox();
                    });
                }
            }
            else if (GisEditor.LayerListManager.SelectedLayerListItem.ConcreteObject is ValueItem)
            {
                string       value        = ((ValueItem)GisEditor.LayerListManager.SelectedLayerListItem.ConcreteObject).Value;
                string       columnName   = ((ValueStyle)GisEditor.LayerListManager.SelectedLayerListItem.Parent.ConcreteObject).ColumnName;
                FeatureLayer featureLayer = LayerListHelper.FindMapElementInTree <FeatureLayer>(GisEditor.LayerListManager.SelectedLayerListItem);
                if (featureLayer != null)
                {
                    System.Windows.Forms.DialogResult dialogResult = System.Windows.Forms.DialogResult.Yes;
                    FeatureLayerPlugin[] layerPlugins = GisEditor.LayerManager.GetLayerPlugins(featureLayer.GetType()).OfType <FeatureLayerPlugin>().ToArray();
                    if (layerPlugins.Length > 0 && !layerPlugins[0].CanQueryFeaturesEfficiently)
                    {
                        dialogResult = System.Windows.Forms.MessageBox.Show(GisEditor.LanguageManager.GetStringResource("ZoomToExtentWarning"), GisEditor.LanguageManager.GetStringResource("MapElementsListPluginZoomToExtent"), System.Windows.Forms.MessageBoxButtons.YesNo, System.Windows.Forms.MessageBoxIcon.Information);
                    }
                    if (dialogResult == System.Windows.Forms.DialogResult.Yes)
                    {
                        Collection <Feature> features = new Collection <Feature>();
                        featureLayer.SafeProcess(() =>
                        {
                            features     = featureLayer.QueryTools.GetFeaturesByColumnValue(columnName, value);
                            resultExtent = ExtentHelper.GetBoundingBoxOfItems(features);
                        });
                        if (features.Count == 0)
                        {
                            MessageBoxHelper.ShowMessage("No features matched.", "Zoom to extent", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information);
                        }
                    }
                }
            }

            if (resultExtent != null)
            {
                GisEditor.ActiveMap.CurrentExtent = resultExtent;
                GisEditor.ActiveMap.Refresh();
            }
        }
Beispiel #19
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);
        }
        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);
                    }
                }
            }
        }
Beispiel #21
0
        private void VisibilityChanged(bool value)
        {
            if (ConcreteObject is LayerOverlay && needRefresh)
            {
                foreach (var subEntity in Children)
                {
                    subEntity.needRefresh = false;
                    LayerPlugin layerPlugin = GisEditor.LayerManager.GetLayerPlugins(subEntity.ConcreteObject.GetType()).FirstOrDefault();
                    if (layerPlugin != null)
                    {
                        bool isDataSourceAvailable = layerPlugin.DataSourceResolveTool.IsDataSourceAvailable((Layer)subEntity.ConcreteObject);
                        if (isDataSourceAvailable)
                        {
                            subEntity.IsChecked = IsChecked;
                            ((Layer)subEntity.ConcreteObject).IsVisible = IsChecked;
                        }
                    }
                    subEntity.needRefresh = true;
                }
                var tileOverlay = (TileOverlay)ConcreteObject;
                tileOverlay.IsVisible = isChecked;
                if (!isChecked)
                {
                    RefreshOverlay(tileOverlay);
                }
                GisEditor.UIManager.InvokeRefreshPlugins();
            }
            else if (ConcreteObject is Layer && needRefresh)
            {
                LayerPlugin layerPlugin = GisEditor.LayerManager.GetLayerPlugins(ConcreteObject.GetType()).FirstOrDefault();
                if (layerPlugin != null)
                {
                    bool isDataSourceAvailable = layerPlugin.DataSourceResolveTool.IsDataSourceAvailable((Layer)ConcreteObject);
                    if (!isDataSourceAvailable)
                    {
                        ((Layer)ConcreteObject).IsVisible = false;
                        isChecked = false;
                        OnPropertyChanged("IsChecked");
                        return;
                    }
                }

                if (!isChecked)
                {
                    Image image = warningImages.FirstOrDefault(i => i.Name.Equals("InEditing", StringComparison.InvariantCultureIgnoreCase));
                    if (image != null)
                    {
                        warningImages.Remove(image);
                    }
                }
                ((Layer)ConcreteObject).IsVisible = isChecked;
                Parent.needRefresh = false;
                Parent.IsChecked   = Parent.Children.Any(m => m.IsChecked);
                Parent.needRefresh = true;
                TileOverlay tileOverlay = Parent.ConcreteObject as TileOverlay;
                if (tileOverlay != null)
                {
                    //In this case, tileOverlay will execute Refresh() in default.
                    if (!tileOverlay.IsVisible && Parent.IsChecked)
                    {
                        tileOverlay.IsVisible = Parent.IsChecked;
                    }
                    else
                    {
                        tileOverlay.IsVisible = Parent.IsChecked;
                        tileOverlay.Invalidate();
                        RefreshOverlay(tileOverlay);
                    }
                }
                GisEditor.UIManager.InvokeRefreshPlugins();
            }

            if (!(ConcreteObject is Layer) && !(ConcreteObject is LayerOverlay))
            {
                TryChangeIsVisiblePropertyOfMapElement();
            }

            if (ConcreteObject is Styles.Style)
            {
                Styles.Style concreteStyle = (Styles.Style)ConcreteObject;
                concreteStyle.IsActive = value;
                Layer layer = LayerListHelper.FindMapElementInTree <Layer>(this);
                if (layer != null && layer.IsVisible)
                {
                    LayerOverlay layerOverlay = LayerListHelper.FindMapElementInTree <LayerOverlay>(this);
                    if (layerOverlay != null && layerOverlay.IsVisible)
                    {
                        layerOverlay.Invalidate();
                        RefreshOverlay(layerOverlay);
                    }
                }
            }
        }
        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.FindMapElementInTree <TileOverlay>(GisEditor.LayerListManager.SelectedLayerListItem);
                if (overlay != null)
                {
                    overlay.Invalidate();
                }
            }
            return(needRefresh);
        }