This project is read-only.

Best Practice in creating selection map

Dec 11, 2015 at 7:23 AM
Edited Dec 11, 2015 at 8:04 AM
In my app, I want to create a dialog box where the user can select features in a layer. I am wondering what the best approach to this would be. So far, I have created a splitter control, and assigned the map control to be bound to it (I am doing it via code since I haven't figured out how to do it through the designer)..

VerifyMap = new Api.Map.BoundMapControl();
        VerifyMap.Dock = DockStyle.Fill;
        VerifyMap.AllowDrop = false;
        VerifyMap.Extents = envelope2;
        VerifyMap.Name = "VerifyMap";
        VerifyMap.ResizeBehavior = Api.Enums.ResizeBehavior.Classic;
        VerifyMap.TileProvider = MW5.Api.Enums.TileProvider.OpenStreetMap;
        VerifyMap.ZoomBehavior = MW5.Api.Enums.ZoomBehavior.UseTileLevels;
        VerifyMap.ZoomBoxStyle = MW5.Api.Enums.ZoomBoxStyle.Blue;
        VerifyMap.ZoomPercent = 0.3D;

When I go through this code, and try to access a layer from this map (in this case clearing all layers or adding a layer) , I get an error saying there is no legend. The exact text is : MapControl.Legend property should be set before acceccing layers collection.

I try to add a Api.Legend.LegendControl but it requires a IContainer. Is there a better way to get a map and a selection tool inside a dialog box to allow the user to select in that interface, or can someone suggest how to handle the IContainer parameter?

Dec 11, 2015 at 4:53 PM
I have created a new legend control :
this.components = new System.ComponentModel.Container();
        this.legendControl1 = new MW5.Api.Legend.LegendControl(this.components);
        this.legendControl1.BackColor = System.Drawing.Color.White;
        this.legendControl1.Dock = System.Windows.Forms.DockStyle.Fill;
        this.legendControl1.DrawLines = true;
        this.legendControl1.Font = new System.Drawing.Font("Arial", 8F);
        this.legendControl1.Location = new System.Drawing.Point(0, 0);
        this.legendControl1.Map = null;
        this.legendControl1.Name = "legendContrthisol1";
        this.legendControl1.SelectedGroupHandle = -1;
        this.legendControl1.SelectedLayer = null;
        this.legendControl1.SelectedLayerHandle = -1;
        this.legendControl1.SelectionColor = System.Drawing.Color.FromArgb(((int)(((byte)(240)))), ((int)(((byte)(240)))), ((int)(((byte)(240)))));
        this.legendControl1.ShowGroupIcons = true;
        this.legendControl1.ShowLabels = false;
        this.legendControl1.Size = new System.Drawing.Size(233, 325);
        this.legendControl1.TabIndex = 0;
and this I assigned to the map control using :
        SelectionMap.Legend = legendControl1
I did have to set the map property of the legendcontrol with SelectionMap. It now appear

Dec 14, 2015 at 12:24 AM
The answer is to create a event handler against the SelectionBoxFinal event, and do the following:
double x, y, x2, y2;
        var box = new Envelope(e.ProjectedBounds.MinX, e.ProjectedBounds.MaxX, e.ProjectedBounds.MinY, e.ProjectedBounds.MaxY);
        var r = new Rectangle(e.Bounds.Left, e.Bounds.Top, e.Bounds.Right - e.Bounds.Left, e.Bounds.Bottom - e.Bounds.Top);
        FeatureSet fs = SelectionMap.GetFeatureSet(SelectionMap.Layers[0].Handle) as FeatureSet;

        List<IFeature> fl = fs.SelectShapes(box, 0, Api.Enums.MapSelectionMode.Intersection).ToList<IFeature>();
        foreach(Feature f in fl)
            f.Selected = true; 

That will make the selection set appear on the map
Marked as answer by dalguy72 on 12/13/2015 at 4:24 PM