Esempio n. 1
0
        public LegendOptionsWindow(MapLegend legend)
        {
            InitializeComponent();
            Legend = legend;

            DataContext = this;

            BackgroundColor = Legend.BackgroundColor;
            BorderColor     = Legend.BorderColor;
            BorderWidth     = Legend.BorderWidth;
            LegendTitle     = Legend.Title;
            TitleFont       = Legend.TitleFont;
            NumberOfColumns = Legend.NumberOfColumns;
            ItemFont        = Legend.ItemFont;

            Layers = new List <LegendItemDescriptorViewModel>();
            foreach (LegendItemDescriptor desc in legend.GetLayerDescriptors().Values)
            {
                var model = new LegendItemDescriptor {
                    IsVisible = desc.IsVisible, LayerName = desc.LayerName, Title = desc.Title, TitleColor = desc.TitleColor
                };
                var viewModel = new LegendItemDescriptorViewModel(model);
                Layers.Add(viewModel);
                viewModel.DataChanged += viewModel_DataChanged;
            }

            Layers.Sort((a, b) => String.CompareOrdinal(a.LayerName, b.LayerName));

            Loaded += (sender, e) => { if (lstLayers.Items.Count > 0)
                                       {
                                           lstLayers.SelectedIndex = 0;
                                       }
            };


            GraphicsUtils.ApplyLegacyFont(lblTitleFont, TitleFont);
            GraphicsUtils.ApplyLegacyFont(lblItemFont, ItemFont);

            btnApply.IsEnabled = false;

            PropertyChanged += LegendOptionsWindow_PropertyChanged;
        }
        private void DrawLayerItem(Graphics g, ILayer layer, int row, int col, LegendItemDescriptor desc, SizeF titleSize, Image dest)
        {
            // var itemFont = GraphicsUtils.ScaleFont(ItemFont, dest);

            int rowHeight = (int)ItemFont.GetHeight() + 6;
            int colWidth  = Width / NumberOfColumns;
            int top       = (int)(titleSize.Height + 10 + BorderWidth) + (rowHeight * row) + Top;
            int left      = col * colWidth + Left + BorderWidth;

            Image icon = null;

            if (layer is VectorLayer)
            {
                var vectorLayer = layer as VectorLayer;
                icon = vectorLayer.Style.Symbol;
                if (icon == null)
                {
                    icon = new Bitmap(12, 12);
                    var gg = Graphics.FromImage(icon);
                    gg.FillRectangle(vectorLayer.Style.Fill, 0, 0, 11, 11);
                    gg.DrawRectangle(Pens.Black, 0, 0, 11, 11);
                }
            }

            var iconWidth = icon != null ? icon.Width : 12;

            var labelRect = new RectangleF(left + iconWidth + 10, top, colWidth - (iconWidth + 10), rowHeight);

            if (icon != null)
            {
                var iconLeft = left + 5;
                var iconTop  = (top + rowHeight / 2) - (icon.Height / 2);
                g.DrawImage(icon, iconLeft, iconTop);
            }

            var format = new StringFormat();

            format.LineAlignment = StringAlignment.Center;
            g.DrawString(desc.Title, ItemFont, new SolidBrush(desc.TitleColor), labelRect, format);
        }