Example #1
0
 void panel1_MouseWheel(object sender, MouseEventArgs e)
 {
     try
     {
         if (layer != null && panel1.Bounds.Contains(e.Location))
         {
             if (e.Delta > 0)
             {
                 FVertex mouselocation = view.ToMapVertex(new Point(e.X, e.Y));
                 double  ZoomInfactor  = 0.85;
                 double  newwidth      = view.MyMapExtent.width * ZoomInfactor;
                 double  newheight     = view.MyMapExtent.height * ZoomInfactor;
                 double  newminx       = mouselocation.getX() - (mouselocation.getX() - view.MyMapExtent.minX) * ZoomInfactor;
                 double  newminy       = mouselocation.getY() - (mouselocation.getY() - view.MyMapExtent.minY) * ZoomInfactor;
                 view.MyMapExtent.setValue(new FVertex(newminx + newwidth, newminy + newheight), new FVertex(newminx, newminy));
                 DrawMap();
             }
             else if (e.Delta < 0)
             {
                 FVertex mouselocation = view.ToMapVertex(new Point(e.X, e.Y));
                 double  ZoomInfactor  = 0.85;
                 double  newwidth      = view.MyMapExtent.width / ZoomInfactor;
                 double  newheight     = view.MyMapExtent.height / ZoomInfactor;
                 double  newminx       = mouselocation.getX() - (mouselocation.getX() - view.MyMapExtent.minX) / ZoomInfactor;
                 double  newminy       = mouselocation.getY() - (mouselocation.getY() - view.MyMapExtent.minY) / ZoomInfactor;
                 view.MyMapExtent.setValue(new FVertex(newminx + newwidth, newminy + newheight), new FVertex(newminx, newminy));
                 DrawMap();
             }
         }
     }
     catch
     {
         MessageBox.Show("Error");
     }
 }
Example #2
0
        private void panel1_MouseUp(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                switch (MouseCommand)
                {
                case MOUSECOMMAND.Select:
                {
                    if (layer == null)
                    {
                        break;
                    }
                    layer.ClearSelection();
                    if (e.X == MouseStartX && e.Y == MouseStartY)        //点选
                    {
                        FFeature feature = layer.SelectByClick(new Point(e.X, e.Y), view);
                        if (feature != null)
                        {
                            feature.selected = true;
                        }
                    }
                    else        //框选
                    {
                        FExtent extent = view.RectToExtent(new Rectangle(
                                                               Math.Min(e.X, MouseStartX), Math.Min(e.Y, MouseStartY),
                                                               Math.Abs(e.X - MouseStartX), Math.Abs(e.Y - MouseStartY)));
                        List <FFeature> features = layer.SelectByExtent(extent);
                        for (int j = 0; j < features.Count; j++)
                        {
                            features[j].selected = true;
                        }
                    }
                    DrawMap();
                    if (attributeDialog != null)
                    {
                        attributeDialog.UpdataSelection();
                    }
                    break;
                }

                case MOUSECOMMAND.ZoomIn:
                {
                    if (e.X == MouseStartX && e.Y == MouseStartY)
                    {
                        FVertex mouselocation = view.ToMapVertex(new Point(e.X, e.Y));
                        double  ZoomInfactor  = 0.9;
                        double  newwidth      = view.MyMapExtent.width * ZoomInfactor;
                        double  newheight     = view.MyMapExtent.height * ZoomInfactor;
                        double  newminx       = mouselocation.getX() - (mouselocation.getX() - view.MyMapExtent.minX) * ZoomInfactor;
                        double  newminy       = mouselocation.getY() - (mouselocation.getY() - view.MyMapExtent.minY) * ZoomInfactor;
                        view.MyMapExtent.setValue(new FVertex(newminx + newwidth, newminy + newheight), new FVertex(newminx, newminy));
                    }
                    else
                    {
                        view.MyMapExtent = view.RectToExtent(new Rectangle(
                                                                 Math.Min(e.X, MouseStartX), Math.Min(e.Y, MouseStartY),
                                                                 Math.Abs(e.X - MouseStartX), Math.Abs(e.Y - MouseStartY)));
                    }
                    DrawMap();
                    break;
                }

                case MOUSECOMMAND.ZoomOut:
                {
                    if (e.X == MouseStartX && e.Y == MouseStartY)
                    {
                        FVertex mouselocation = view.ToMapVertex(new Point(e.X, e.Y));
                        double  ZoomInfactor  = 0.9;
                        double  newwidth      = view.MyMapExtent.width / ZoomInfactor;
                        double  newheight     = view.MyMapExtent.height / ZoomInfactor;
                        double  newminx       = mouselocation.getX() - (mouselocation.getX() - view.MyMapExtent.minX) / ZoomInfactor;
                        double  newminy       = mouselocation.getY() - (mouselocation.getY() - view.MyMapExtent.minY) / ZoomInfactor;
                        view.MyMapExtent.setValue(new FVertex(newminx + newwidth, newminy + newheight), new FVertex(newminx, newminy));
                    }
                    else
                    {
                        FExtent extent = view.RectToExtent(new Rectangle(
                                                               Math.Min(e.X, MouseStartX), Math.Min(e.Y, MouseStartY),
                                                               Math.Abs(e.X - MouseStartX), Math.Abs(e.Y - MouseStartY)));
                        //新的地图范围
                        double newwidth  = view.MyMapExtent.width * view.MyMapExtent.width / extent.width;
                        double newheight = view.MyMapExtent.height * view.MyMapExtent.height / extent.height;
                        double newminx   = extent.minX - (extent.minX - view.MyMapExtent.minX) * newwidth / view.MyMapExtent.width;
                        double newminy   = extent.minY - (extent.minY - view.MyMapExtent.minY) * newheight / view.MyMapExtent.height;
                        view.MyMapExtent.setValue(new FVertex(newminx + newwidth, newminy + newheight), new FVertex(newminx, newminy));
                    }
                    DrawMap();
                    break;
                }

                case MOUSECOMMAND.Pan:
                {
                    FVertex C1 = view.MyMapExtent.mapcenter;
                    FVertex M1 = view.ToMapVertex(new Point(MouseStartX, MouseStartY));
                    FVertex M2 = view.ToMapVertex(new Point(e.X, e.Y));
                    FVertex C2 = new FVertex(C1.getX() - (M2.getX() - M1.getX()), C1.getY() - (M2.getY() - M1.getY()));
                    view.MyMapExtent.SetMapCenter(C2);
                    DrawMap();
                    break;
                }
                }
            }
        }