Example #1
0
        // <summary>
        // Handles mouse down event and adds the marker
        // </summary>
        public void AxMap1MouseDownEvent(object sender, _DMapEvents_MouseDownEvent e)
        {
            if (e.button == 1)          // left button
            {
                Shapefile sf = axMap1.get_Shapefile(m_layerHandle);

                Shape shp = new Shape();
                shp.Create(ShpfileType.SHP_POINT);

                Point  pnt = new Point();
                double x   = 0.0;
                double y   = 0.0;
                axMap1.PixelToProj(e.x, e.y, ref x, ref y);
                pnt.x = x;
                pnt.y = y;
                int index = shp.numPoints;
                shp.InsertPoint(pnt, ref index);

                index = sf.NumShapes;
                if (!sf.EditInsertShape(shp, ref index))
                {
                    MessageBox.Show("Failed to insert shape: " + sf.ErrorMsg[sf.LastErrorCode]);
                    return;
                }
                axMap1.Redraw();
            }
        }
Example #2
0
        private void Map_MouseDownEvent(object sender, _DMapEvents_MouseDownEvent e)
        {
            if (e.button == 1)          // left button
            {
                double lat = 0.0;
                double lng = 0.0;
                double height;
                int    column = 0;
                int    row    = 0;

                Map.PixelToProj(e.x, e.y, ref lng, ref lat);

                if (grd.Filename != "")
                {
                    if (!(grd.Extents.PointIsWithin(lng, lat)))
                    {
                        foreach (GridBoundsAndFilenames GrdBndFilename in grdBndFilenames)
                        {
                            if (IsInThisBounds(GrdBndFilename, lng, lat))
                            {
                                grd.Close();
                                grd.Open(GrdBndFilename.GridFileNames);
                                break;
                            }
                        }
                    }
                    grd.ProjToCell(lng, lat, out column, out row);
                    height        = (double)grd.get_Value(column, row);
                    tbHeight.Text = height.ToString();
                }

                tbLat.Text = lat.ToString();
                tbLng.Text = lng.ToString();
            }
        }
Example #3
0
        private void MapMouseDownEvent(object sender, _DMapEvents_MouseDownEvent e)
        {
            var button = MouseEventHelper.ParseMouseButton(e.button);
            var args   = new MouseEventArgs(button, 1, e.x, e.y, 0);

            Invoke(sender, MouseDown, args);
        }
        /// <summary>
        /// Handles mouse down event, removes the shape under cursor
        /// </summary>
        private void AxMap1MouseDownEvent1(object sender, _DMapEvents_MouseDownEvent e)
        {
            // it's assumed here that the layer we want to edit is the first 1 (with 0 index)
            int       layerHandle = axMap1.get_LayerHandle(0);
            Shapefile sf          = axMap1.get_Shapefile(layerHandle);

            if (sf != null)
            {
                double projX = 0.0;
                double projY = 0.0;
                axMap1.PixelToProj(e.x, e.y, ref projX, ref projY);

                object  result = null;
                Extents ext    = new Extents();
                ext.SetBounds(projX, projY, 0.0, projX, projY, 0.0);
                if (sf.SelectShapes(ext, 0.0, SelectMode.INCLUSION, ref result))
                {
                    int[] shapes = result as int[];
                    if (shapes == null)
                    {
                        return;
                    }

                    if (shapes.Length > 1)
                    {
                        string s = "More than one shapes were selected. Shape indices:";
                        for (int i = 0; i < shapes.Length; i++)
                        {
                            s += shapes[i] + Environment.NewLine;
                        }
                        MessageBox.Show(s);
                    }
                    else
                    {
                        if (!sf.EditDeleteShape(shapes[0]))
                        {
                            MessageBox.Show("Failed to delete a shape: " + sf.ErrorMsg[sf.LastErrorCode]);
                        }
                        else
                        {
                            MessageBox.Show("Shape was removed. Index = " + shapes[0]);
                            sf.Labels.Expression = sf.Labels.Expression;
                            for (int i = 0; i < sf.Labels.Count; i++)
                            {
                                sf.Labels.Label[i, 0].Text += "; " + i;
                            }
                            axMap1.Redraw();
                        }
                    }
                }
                else
                {
                    MessageBox.Show("Nothing was selected");
                }
            }

            // Execute this code if you want to save the results.
            // sf.StopEditingShapes(true, true, null);
        }
 // <summary>
 // Handles mouse click event. Shows the context menu with the names.
 // </summary>
 private void AxMap1MouseDownEvent4(object sender, _DMapEvents_MouseDownEvent e)
 {
     if (e.button == 2)          // right button
     {
         System.Drawing.Point pnt = axMap1.PointToScreen(new System.Drawing.Point(e.x, e.y));
         _menu.Show(pnt.X, pnt.Y);
     }
 }
Example #6
0
        private void axMap1_MouseDownEvent(object sender, _DMapEvents_MouseDownEvent e)
        {
            if (sfMouseDown != null)
            {
                foreach (Shapefile sf in sfMouseDown.Values)
                {
                    if (sf != null)
                    {
                        Labels labels = sf.Labels;
                        labels.FontSize     = 15;
                        labels.FontBold     = true;
                        labels.FrameVisible = true;
                        labels.FrameType    = tkLabelFrameType.lfRectangle;
                        labels.AutoOffset   = false;
                        labels.OffsetX      = 40;

                        LabelCategory cat = labels.AddCategory("Red");
                        cat.FontColor = 255;

                        double projX = 0.0;
                        double projY = 0.0;
                        Map.PixelToProj(e.x, e.y, ref projX, ref projY);
                        object result = null;
                        var    ext    = new Extents();
                        ext.SetBounds(projX - 0.0004, projY - 0.0004, 0.0, projX + 0.0004, projY + 0.0004, 0.0);
                        if (sf.SelectShapes(ext, 0.0001, SelectMode.INTERSECTION, ref result))
                        {
                            if (labelFlag_MouseDown == 0)
                            {
                                mouseDownOperate(result, sf, labels, projX, projY);
                                Map.Redraw();
                                labelFlag_MouseDown = 1;
                            }
                        }
                        else
                        {
                            if (labelFlag_MouseDown == 1)
                            {
                                sf.Labels.Clear();
                                Map.Redraw();
                                labelFlag_MouseDown = 0;
                            }
                        }
                    }
                }
            }
        }
 private void OnMapMouseDown(object sender, _DMapEvents_MouseDownEvent e)
 {
     if (EnableMapInteraction)
     {
         if (e.button == 1)
         {
             _selectionFromSelectBox = false;
         }
         else if (e.button == 2 && _selectedShapeIndexes != null && _selectedShapeIndexes.Length == 1 && _dropDownContext.Length > 0)
         {
             if (_currentMapLayer.LayerType == "ShapefileClass")
             {
                 SetUpMapDropDown(_dropDownContext, e.x, e.y);
             }
             else
             {
             }
         }
     }
 }
 private void OnMapMouseDown(object sender, _DMapEvents_MouseDownEvent e)
 {
     throw new NotImplementedException();
 }
Example #9
0
        private void mapControl_MouseDownEvent(object sender, _DMapEvents_MouseDownEvent e)
        {
            if (e.button == 2 && listLabel.Visible)
            {
                ListViewItem   x     = listLabel.Items[listLabel.SelectedIndices[0]];
                string         type  = x.SubItems[1].Text;
                FormEnterLabel enter = new FormEnterLabel(preSelectedShape.ToString(), type);
                enter.ShowDialog();
                string   str_    = enter.label;
                String[] rowData = new String[3];
                rowData[0] = preSelectedShape.ToString();
                rowData[1] = type;
                rowData[2] = str_;

                ListViewItem item = new ListViewItem(rowData);
                listLabel.Items.RemoveAt(preSelectedShape);
                listLabel.Items.Insert(preSelectedShape, item);
            }


            if (!toolGetValues.Checked)
            {
                return;
            }
            Shape shp = new Shape();

            if (e.button == 1)          // left button
            {
                Shapefile sf = mapControl.get_Shapefile(mapControl.NumLayers - 1);

                shp.Create(ShpfileType.SHP_POINT);
                MapWinGIS.Point pnt = new MapWinGIS.Point();
                double          x   = 0.0;
                double          y   = 0.0;
                mapControl.PixelToProj(e.x, e.y, ref x, ref y);
                Console.WriteLine(x.ToString() + "," + y.ToString());
                pnt.x = x;
                pnt.y = y;
                int index = shp.numPoints;
                shp.InsertPoint(pnt, ref index);
                index = sf.NumShapes;
                if (!sf.EditInsertShape(shp, ref index))
                {
                    MessageBox.Show("Failed to insert shape: " + sf.ErrorMsg[sf.LastErrorCode]);
                    return;
                }
                mapControl.Redraw();
            }
            else
            {
                return;
            }


            int row;
            int column;

            double X = 0;
            double Y = 0;

            mapControl.PixelToProj(e.x, e.y, ref X, ref Y);
            MapWinGIS.Image img = mapControl.get_Image(0);
            img.ProjectionToImage(X, Y, out column, out row);
            double[] vals = new double[img.NoBands];
            for (int i = 1; i <= img.NoBands; i++)
            {
                GdalRasterBand rst = img.get_Band(i);
                double         pVal;
                rst.get_Value(row, column, out pVal);
                vals[i - 1] = pVal;
            }

            FormRasterValue uiRasterValues = new FormRasterValue(vals);

            uiRasterValues.ShowDialog();
            shp.Clear();
        }
        // <summary>
        // Handles mouse down event. Creates the editing form on the fly.
        // </summary>
        private void AxMap1MouseDownEvent2(object sender, _DMapEvents_MouseDownEvent e)
        {
            int       layerHandle = axMap1.get_LayerHandle(0); // it's assumed here that the layer we want to edit is the first 1 (with 0 index)
            Shapefile sf          = axMap1.get_Shapefile(layerHandle);

            if (sf != null)
            {
                double projX = 0.0;
                double projY = 0.0;
                axMap1.PixelToProj(e.x, e.y, ref projX, ref projY);

                object  result = null;
                Extents ext    = new Extents();
                ext.SetBounds(projX, projY, 0.0, projX, projY, 0.0);
                if (sf.SelectShapes(ext, 0.0, SelectMode.INCLUSION, ref result))
                {
                    int[] shapes = result as int[];
                    if (shapes == null)
                    {
                        return;
                    }

                    if (shapes.Length > 1)
                    {
                        string s = "More than one shapes were selected. Shape indices:";
                        for (int i = 0; i < shapes.Length; i++)
                        {
                            s += shapes[i] + Environment.NewLine;
                        }
                        MessageBox.Show(s);
                    }
                    else
                    {
                        sf.set_ShapeSelected(shapes[0], true);  // selecting the shape we are about to edit
                        axMap1.Redraw(); Application.DoEvents();

                        Form form = new Form();
                        for (int i = 0; i < sf.NumFields; i++)
                        {
                            System.Windows.Forms.Label label = new System.Windows.Forms.Label();
                            label.Left  = 15;
                            label.Top   = i * 30 + 5;
                            label.Text  = sf.Field[i].Name;
                            label.Width = 60;
                            form.Controls.Add(label);

                            TextBox box = new TextBox();
                            box.Left  = 80;
                            box.Top   = label.Top;
                            box.Width = 80;
                            box.Text  = sf.CellValue[i, shapes[0]].ToString();
                            box.Name  = sf.Field[i].Name;
                            form.Controls.Add(box);
                        }

                        form.Width  = 180;
                        form.Height = sf.NumFields * 30 + 70;

                        Button btn = new Button
                        {
                            Text   = "Ok",
                            Top    = sf.NumFields * 30 + 10,
                            Left   = 20,
                            Width  = 70,
                            Height = 25
                        };
                        btn.Click += BtnClick;
                        form.Controls.Add(btn);

                        btn = new Button
                        {
                            Text   = "Cancel",
                            Top    = sf.NumFields * 30 + 10,
                            Left   = 100,
                            Width  = 70,
                            Height = 25
                        };
                        btn.Click += BtnClick;
                        form.Controls.Add(btn);

                        form.FormClosed     += FormFormClosed;
                        form.Text            = "Shape: " + shapes[0];
                        form.ShowInTaskbar   = false;
                        form.StartPosition   = FormStartPosition.CenterParent;
                        form.FormBorderStyle = FormBorderStyle.FixedDialog;
                        form.MaximizeBox     = false;
                        form.MinimizeBox     = false;
                        form.ShowDialog(axMap1.Parent);
                    }
                }
            }

            // Execute this code if you want to save the results.
            // sf.StopEditingShapes(true, true, null);
        }