Esempio n. 1
0
        public void Refresh(FeatureLayer displayLayer, WinformsMap map)
        {
            FeatureLayer = displayLayer;
            Draw(map.CurrentScale);

            Controls.Clear();

            Label LegendTitleLabel = new Label();

            LegendTitleLabel.AutoSize  = true;
            LegendTitleLabel.TextAlign = ContentAlignment.MiddleLeft;
            LegendTitleLabel.Location  = new Point(5, 15);
            LegendTitleLabel.Text      = Title;
            LegendTitleLabel.Font      = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point, ((byte)(0)));
            Size textSize      = TextRenderer.MeasureText(LegendTitleLabel.Text, LegendTitleLabel.Font);
            int  maxPanelWidth = LegendTitleLabel.Location.X + textSize.Width;

            Controls.Add(LegendTitleLabel);

            int legendItemHeight = 55;

            foreach (var item in LegendItems.Where(i => i.Image != null && !string.IsNullOrEmpty(i.Title)))
            {
                PictureBox ItemImagePicture = new PictureBox();
                ItemImagePicture.Location = new Point(10, legendItemHeight);
                ItemImagePicture.Size     = item.Image.Size;
                ItemImagePicture.Image    = item.Image;

                Label TextLabel = new Label();
                TextLabel.AutoSize = true;
                TextLabel.Text     = item.Title;
                TextLabel.Location = new Point(ItemImagePicture.Location.X + ItemImagePicture.Width + 10, legendItemHeight + ItemImagePicture.Height / 2 - 6);

                textSize          = TextRenderer.MeasureText(TextLabel.Text, TextLabel.Font);
                maxPanelWidth     = maxPanelWidth < TextLabel.Location.X + textSize.Width ? TextLabel.Location.X + textSize.Width : maxPanelWidth;
                legendItemHeight += ItemImagePicture.Height + 5;

                Controls.Add(ItemImagePicture);
                Controls.Add(TextLabel);
            }

            Location = new Point(Location.X, map.Height + map.Top - legendItemHeight - 9);
            Height   = legendItemHeight + 10;
            Width    = maxPanelWidth + 20;
        }
        protected void ItemOnItemSelected(object sender, EventArgs e)
        {
            ItemViewModel viewModel = (ItemViewModel)sender;

            SelectedLegendItem = null;

            if (viewModel.IsSelected == false)
            {
                return;
            }

            SelectedLegendItem = viewModel;

            foreach (ItemViewModel itemViewModel in LegendItems.Where(x => !ReferenceEquals(x, viewModel)))
            {
                itemViewModel.IsSelected = false;
            }
        }