Esempio n. 1
0
        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.Filter           = "Shapefile文件|*.shp";
            openFileDialog.RestoreDirectory = true;
            openFileDialog.FilterIndex      = 1;
            openFileDialog.Multiselect      = false;
            if (openFileDialog.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            layer = GISShapefile.ReadShapefile(openFileDialog.FileName);
            layer.DrawAttributeOrNot = false;
            MessageBox.Show("read " + layer.FeatureCount() + "objects");
            view.UpdateExtent(layer.Extent);
            UpdateMap();
        }
Esempio n. 2
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;
            }
        }
Esempio n. 3
0
 private void button2_Click(object sender, EventArgs e)
 {
     view.UpdateExtent(layer.Extent);
     UpdateMap();
 }