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(); } }
private void Form2_MouseUp(object sender, MouseEventArgs e) { if (MouseOnMap) { MouseOnMap = false; switch (MouseCommand) { case MOUSECOMMAND.Select: for (int i = 0; i < document.layers.Count; i++) { document.layers[i].ClearSelection(); } if (e.X == MouseStartX && e.Y == MouseStartY) { for (int i = 0; i < document.layers.Count; i++) { GISFeature feature = document.layers[i].SelectByClick(new Point(e.X, e.Y), view); if (feature != null) { feature.Selected = true; } } } else { GISExtent 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))); for (int i = 0; i < document.layers.Count; i++) { List <GISFeature> features = document.layers[i].SelectByExtent(extent); for (int j = 0; j < features.Count; j++) { features[j].Selected = true; } } } updateview(); if (layerDialog != null) { layerDialog.UpdateSelection(); } break; case MOUSECOMMAND.ZoomIn: if (e.X == MouseStartX && e.Y == MouseStartY) { 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)); } else { view.CurrentMapExtent = view.RectToExtent(new Rectangle( Math.Min(e.X, MouseStartX), Math.Min(e.Y, MouseStartY), Math.Abs(e.X - MouseStartX), Math.Abs(e.Y - MouseStartY))); } if (delaunayToolStripMenuItem1.Checked || 泰森多边形ToolStripMenuItem.Checked) { updateview2(); } else { updateview(); } break; case MOUSECOMMAND.ZoomOut: if (e.X == MouseStartX && e.Y == MouseStartY) { 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)); } else { GISExtent 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.CurrentMapExtent.Width * view.CurrentMapExtent.Width / extent.Width; double newheight = view.CurrentMapExtent.Height * view.CurrentMapExtent.Height / extent.Height; double newminx = extent.MinX - (extent.MinX - view.CurrentMapExtent.MinX) * newwidth / view.CurrentMapExtent.Width; double newminy = extent.MinY - (extent.MinY - view.CurrentMapExtent.MinY) * newheight / view.CurrentMapExtent.Height; view.CurrentMapExtent.SetValue(new GISVertex(newminx, newminy), new GISVertex(newminx + newwidth, newminy + newheight)); } if (delaunayToolStripMenuItem1.Checked || 泰森多边形ToolStripMenuItem.Checked) { updateview2(); } else { updateview(); } break; case MOUSECOMMAND.Pan: GISVertex C1 = view.CurrentMapExtent.MapCenter; GISVertex M1 = view.ToMapVertex(new Point(MouseStartX, MouseStartY)); GISVertex M2 = view.ToMapVertex(new Point(e.X, e.Y)); GISVertex C2 = new GISVertex(C1.x - (M2.x - M1.x), C1.y - (M2.y - M1.y)); view.CurrentMapExtent.SetMapCenter(C2); updateview(); if (delaunayToolStripMenuItem1.Checked && dlay.Count > 0) { delaunayToolStripMenuItem1.PerformClick(); } if (泰森多边形ToolStripMenuItem.Checked && dlay.Count > 0) { 泰森多边形ToolStripMenuItem.PerformClick(); } break; } } }
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; } }