示例#1
0
        private void Form1_MouseClick(object sender, MouseEventArgs e)
        {//点击空间对象显示属性信息
            //根据鼠标的点击创建节点信息
            if (features.Count == 0)
            {
                return;
            }
            GISVertex mouselocation = view.ToMapVertex(e.Location);
            double    mindistance   = Double.MaxValue;
            int       id            = -1;

            //通过遍历找出features数组中元素的中心点与点击位置最近的点
            for (int i = 0; i < features.Count; i++)
            {
                double onedistance = features[i].spatialpart.centroid.Distance(mouselocation);
                if (onedistance < mindistance)
                {
                    mindistance = onedistance;
                    id          = i;
                }
            }
            //判断是否存在空间对象
            if (id == -1)
            {
                MessageBox.Show("没有任何空间对象!!");
                return;//结束了
            }

            Point nearestpoint = view.ToScreenPoint(features[id].spatialpart.centroid);

            if (ScreenDistance(e.Location, nearestpoint) < 5)
            {
                MessageBox.Show(features[id].getAttribute(0).ToString());
            }
        }
示例#2
0
        private void Form1_MouseClick(object sender, MouseEventArgs e)
        {
            if (layer == null)
            {
                return;
            }
            GISVertex v = view.ToMapVertex(e.Location);

            Console.WriteLine("mapvertex @" + v.x.ToString() + "|" + v.y.ToString()); //此处鼠标点到地图点的转换???
            //创建点选粗选矩形
            GISSelect s = new GISSelect();
            GISExtent MinSelectExtent = s.BuildExtent(v, view);
            Point     bottomleft      = view.ToScreenPoint(MinSelectExtent.bottomleft);
            Point     upleft          = view.ToScreenPoint(new GISVertex(MinSelectExtent.bottomleft.x, MinSelectExtent.upright.y));
            Point     upright         = view.ToScreenPoint(MinSelectExtent.upright);
            Point     bottomright     = view.ToScreenPoint(new GISVertex(MinSelectExtent.upright.x, MinSelectExtent.bottomleft.y));

            Point[]  points   = new Point[] { bottomleft, upleft, upright, bottomright };
            Graphics graphics = this.CreateGraphics();

            graphics.DrawPolygon(new Pen(GISConst.PolygonBoundaryColor, GISConst.PolygonBoundaryWidth), points);

            SelectResult sr = layer.Select(v, view);

            if (sr == SelectResult.OK)
            {
                UpdateMap();
                //toolStripStatusLabel1.Text = layer.Selection.Count.ToString();
                toolStripStatusLabel2.Text = "click @" + v.x.ToString() + "|" + v.y.ToString();
                UpdateAttributeWindow();
                //statusStrip1.Text = layer.Selection.Count.ToString();
            }
        }
示例#3
0
        private void Form1_MouseClick(object sender, MouseEventArgs e)
        {
            GISVertex mouselocation = view.ToMapVertex(new Point(e.X, e.Y));

            double mindistance = Double.MaxValue;
            int    id          = -1;

            for (int i = 0; i < features.Count; i++)
            {
                double onedistance = features[i].getSpatial().getCentroid().Distance(mouselocation);
                if (onedistance < mindistance)
                {
                    id          = i;
                    mindistance = onedistance;
                }
            }

            if (id == -1)
            {
                MessageBox.Show("points is an empty set!");
                return;
            }
            int screendistance = view.ToScreenPoint(new GISVertex(mindistance, 0)).X -
                                 view.ToScreenPoint(new GISVertex(0, 0)).X;

            if (screendistance > 5)
            {
                MessageBox.Show("please click one point closely!");
                return;
            }

            MessageBox.Show("attribute is " + features[id].getAttributeValue(0));
        }
示例#4
0
        private void Form1_MouseClick(object sender, MouseEventArgs e)
        {
            if (layer == null)
            {
                return;
            }
            GISVertex v = view.ToMapVertex(e.Location);

            Console.WriteLine("mapvertex @" + v.x.ToString() + "|" + v.y.ToString()); //此处鼠标点到地图点的转换???
            SelectResult sr = layer.Select(v, view);

            if (sr == SelectResult.OK)
            {
                UpdateMap();
                //toolStripStatusLabel1.Text = layer.Selection.Count.ToString();
                //toolStripStatusLabel2.Text = "click @" + v.x.ToString() + "|" + v.y.ToString();
                UpdateAttributeWindow();
                //statusStrip1.Text = layer.Selection.Count.ToString();
            }
        }
示例#5
0
 void pictureBox1_MouseWheel(object sender, MouseEventArgs e)
 {
     try
     {
         if (e.Location.X > 0 && e.Location.X < pictureBox1.Width && e.Location.Y > 0 && e.Location.Y < pictureBox1.Height)
         {
             if (e.Delta > 0)
             {
                 GISVertex MouseLocation = view.ToMapVertex(new Point(e.X, e.Y));
                 double    ZoomInfactor  = 0.8;
                 double    newwidth      = view.CurrentMapExtent.Width * ZoomInfactor;
                 double    newheight     = view.CurrentMapExtent.Height * ZoomInfactor;
                 double    newminx       = MouseLocation.x - (MouseLocation.x - view.CurrentMapExtent.MinX) * ZoomInfactor;
                 double    newminy       = MouseLocation.y - (MouseLocation.y - view.CurrentMapExtent.MinY) * ZoomInfactor;
                 view.CurrentMapExtent.SetValue(new GISVertex(newminx, newminy), new GISVertex(newminx + newwidth, newminy + newheight));
             }
             if (e.Delta < 0)
             {
                 GISVertex MouseLocation = view.ToMapVertex(new Point(e.X, e.Y));
                 double    ZoomOutfactor = 0.8;
                 double    newwidth      = view.CurrentMapExtent.Width / ZoomOutfactor;
                 double    newheight     = view.CurrentMapExtent.Height / ZoomOutfactor;
                 double    newminx       = MouseLocation.x - (MouseLocation.x - view.CurrentMapExtent.MinX) / ZoomOutfactor;
                 double    newminy       = MouseLocation.y - (MouseLocation.y - view.CurrentMapExtent.MinY) / ZoomOutfactor;
                 view.CurrentMapExtent.SetValue(new GISVertex(newminx, newminy), new GISVertex(newminx + newwidth, newminy + newheight));
             }
             if (Delaunay.Checked || Tyson.Checked)
             {
                 updateview2();
             }
             else
             {
                 updateview();
             }
         }
     }
     catch
     {
         MessageBox.Show("操作错误");
     }
 }
示例#6
0
        private void Form1_MouseClick(object sender, MouseEventArgs e)
        {
            if (layer == null)
            {
                return;
            }
            GISVertex v = view.ToMapVertex(e.Location);

            Console.WriteLine("mapvertex @" + v.x.ToString() + "|" + v.y.ToString()); //此处鼠标点到地图点的转换???
            GISSelect gs = new GISSelect();

            if (gs.Select(v, layer.GetAllFeatures(), layer.ShapeType, view)
                == SelectResult.OK)
            {
                Console.WriteLine(gs.SelectedFeature.getAttribute(0).ToString());
                MessageBox.Show(gs.SelectedFeature.getAttribute(0).ToString());
            }
        }
示例#7
0
        private void Form1_MouseUp(object sender, MouseEventArgs e)
        {
            if (document.IsEmpty())
            {
                return;
            }
            if (MouseOnMap == false)
            {
                return;
            }
            MouseOnMap = false;
            switch (MouseCommand)
            {
            case MOUSECOMMAND.Select:
                //如果CTRL没被按住,就清空选择集 按住CTRL键表示选择多个 即向选择集中新增空间对象
                if (Control.ModifierKeys != Keys.Control)
                {
                    document.ClearSelection();
                }
                //初始化选择结果
                SelectResult sr = SelectResult.UnknownType;
                if (e.X == MouseStartX && e.Y == MouseStartY)
                {
                    //点选
                    GISVertex v = view.ToMapVertex(e.Location);
                    sr = document.Select(v, view);
                }
                else
                {
                    //框选
                    GISExtent extent = view.Rect2Extent(e.X, MouseStartX, e.Y, MouseStartY);
                    sr = document.Select(extent);
                }
                if (sr == SelectResult.OK || Control.ModifierKeys != Keys.Control)
                {
                    UpdateMap();
                    UpdateAttributeWindow();
                }
                break;

            case MOUSECOMMAND.Zoomin:
                if (e.X == MouseStartX && e.Y == MouseStartY)
                {
                    //单点放大
                    GISVertex MouseLocation = view.ToMapVertex(e.Location);
                    GISExtent E1            = view.getRealExtent();
                    double    newwidth      = E1.getWidth() * GISConst.ZoominFactor;
                    double    newheight     = E1.getHeight() * GISConst.ZoominFactor;
                    double    newminx       = MouseLocation.x - (MouseLocation.x - E1.getMinX()) * GISConst.ZoominFactor;
                    double    newminy       = MouseLocation.y - (MouseLocation.y - E1.getMinY()) * GISConst.ZoominFactor;
                    view.UpdateExtent(new GISExtent(newminx, newminx + newwidth, newminy, newminy + newheight));
                }
                else
                {
                    //拉框放大
                    view.UpdateExtent(view.Rect2Extent(e.X, MouseStartX, e.Y, MouseStartY));
                }
                UpdateMap();
                break;

            case MOUSECOMMAND.Zoomout:
                if (e.X == MouseStartX && e.Y == MouseStartY)
                {
                    //单点缩小
                    GISExtent e1            = view.getRealExtent();
                    GISVertex mouselocation = view.ToMapVertex(e.Location);
                    double    newwidth      = e1.getWidth() / GISConst.ZoomoutFactor;
                    double    newheight     = e1.getHeight() / GISConst.ZoomoutFactor;
                    double    newminx       = mouselocation.x - (mouselocation.x - e1.getMinX()) / GISConst.ZoomoutFactor;
                    double    newminy       = mouselocation.y - (mouselocation.y - e1.getMinY()) / GISConst.ZoomoutFactor;
                    view.UpdateExtent(new GISExtent(newminx, newminx + newwidth, newminy, newminy + newheight));
                }
                else
                {
                    //拉框缩小
                    GISExtent e3        = view.Rect2Extent(e.X, MouseStartX, e.Y, MouseStartY);
                    GISExtent e1        = view.getRealExtent();
                    double    newwidth  = e1.getWidth() * e1.getWidth() / e3.getWidth();
                    double    newheight = e1.getHeight() * e1.getHeight() / e3.getHeight();
                    double    newminx   = e3.getMinX() - (e3.getMinX() - e1.getMinX()) * newwidth / e1.getWidth();
                    double    newminy   = e3.getMinY() - (e3.getMinY() - e1.getMinY()) * newheight / e1.getHeight();
                    view.UpdateExtent(new GISExtent(newminx, newminx + newwidth, newminy, newminy + newheight));
                }
                UpdateMap();
                break;

            case MOUSECOMMAND.Pan:
                if (e.X != MouseStartX && e.Y != MouseStartY)
                {
                    GISExtent e1        = view.getRealExtent();
                    GISVertex m1        = view.ToMapVertex(new Point(MouseStartX, MouseStartY));
                    GISVertex m2        = view.ToMapVertex(e.Location);
                    double    newwidth  = e1.getWidth();
                    double    newheight = e1.getHeight();
                    double    newminx   = e1.getMinX() - (m2.x - m1.x);
                    double    newminy   = e1.getMinY() - (m2.y - m1.y);
                    view.UpdateExtent(new GISExtent(newminx, newminx + newwidth, newminy, newminy + newheight));
                    UpdateMap();
                }
                break;
            }
        }