コード例 #1
0
        private static Style GetStyleByPlugin(StylePlugin styleProvider)
        {
            Style style       = null;
            bool  needRestore = false;

            if (!styleProvider.UseRandomColor)
            {
                styleProvider.UseRandomColor = true;
                needRestore = true;
            }

            // Apply more colors to avoid duplicated colors.
            GeoColorHelper.RandomColorType = RandomColorType.All;
            Style tmpStyle = styleProvider.GetDefaultStyle();

            GeoColorHelper.RandomColorType = RandomColorType.Pastel;

            if (needRestore)
            {
                styleProvider.UseRandomColor = false;
            }
            if (tmpStyle != null)
            {
                style      = tmpStyle.CloneDeep();
                style.Name = GisEditor.StyleManager.GetStylePluginByStyle(style).Name;
            }
            return(style);
        }
コード例 #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);
            }
        }