private void msView_MouseUp(object sender, MouseEventArgs e) { if (m_RubberBand != null) { if (_Map != null) { Rectangle myRect = m_RubberBand.Bounds(); bool selected = true; if (myRect.Width < 10 && myRect.Height < 10) selected = false; if (m_pActivetool == Tools.ZoomIn) { if (selected) { Extent zoomGeoExt = pixcelToGeo(myRect); zoomToExtents(zoomGeoExt.Left, zoomGeoExt.Right, zoomGeoExt.Bottom, zoomGeoExt.Top); } else { //Ĭ��Ϊ�Ŵ�һ�� zoomIn(); } } else if (m_pActivetool == Tools.ZoomOut) { if (selected) { double rectW = myRect.Width; double rectH = myRect.Height; //��С��ͼ������ѡ���͵�ǰ��ͼ�ı��ʣ�ȡ��С���� double dFactor = ((rectW / m_viewWidth) > (rectH / m_viewHeight)) ? (rectW / m_viewWidth) : (rectH / m_viewHeight); dFactor = 1 / dFactor; double pCenterX = (myRect.Right + myRect.Left) / 2; double pCenterY = (myRect.Top + myRect.Bottom) / 2; double dNewW = (m_viewWidth * dFactor) / 2; double dNewH = (m_viewHeight * dFactor) / 2; Rectangle newRect = Rectangle.FromLTRB((int)(pCenterX - dNewW), (int)(pCenterY + dNewH), (int)(pCenterX + dNewW), (int)(pCenterY - dNewH)); Extent zoomGeoExt = pixcelToGeo(newRect); zoomToExtents(zoomGeoExt.Left, zoomGeoExt.Right, zoomGeoExt.Bottom, zoomGeoExt.Top); } else { //Ĭ��Ϊ�Ŵ�һ�� zoomOut(); } } } m_RubberBand.End(); m_RubberBand = null; } else if (m_pActivetool == Tools.Pan) { if (_Map == null) return; if (m_blnOnPan) { m_blnOnPan = false; //this is the only mode we care about for this event m_bitbltClickDown.X = 0; m_bitbltClickMove.Y = 0; //m_pResizeExtent = m_Curextents; double xAmount = (pictureBoxPan.Left) * m_inversePixelPerProjectionX; double yAmount = (pictureBoxPan.Top) * m_inversePixelPerProjectionY; _Map.extent.maxx -= xAmount; _Map.extent.minx -= xAmount; _Map.extent.miny += yAmount; _Map.extent.maxy += yAmount; LogPrevExtent(); refreshMap(false); pictureBoxPan.Visible = false; if (pictureBoxPan.BackgroundImage != null) { pictureBoxPan.BackgroundImage.Dispose(); pictureBoxPan.BackgroundImage = null; } this.Capture = false; this.Refresh(); } } //if (_Map != null) //{ // if (MouseUp != null) // MouseUp(this._Map.ImageToWorld(new System.Drawing.Point(e.X, e.Y)), e); // if (e.Button == MouseButtons.Left) // { // if (this.ActiveTool == Tools.ZoomOut) // { // double scale = 0.5; // if (!mousedragging) // { // _Map.Center = this._Map.ImageToWorld(new System.Drawing.Point(e.X, e.Y)); // if (MapCenterChanged != null) // MapCenterChanged(_Map.Center); // } // else // { // if (e.Y - mousedrag.Y < 0) //Zoom out // scale = (float)Math.Pow(1 / (float)(mousedrag.Y - e.Y), 0.5); // else //Zoom in // scale = 1 + (e.Y - mousedrag.Y) * 0.1; // } // _Map.Zoom *= 1 / scale; // if (MapZoomChanged != null) // MapZoomChanged(_Map.Zoom); // Refresh(); // } // else if (this.ActiveTool == Tools.ZoomIn) // { // double scale = 2; // if (!mousedragging) // { // _Map.Center = this._Map.ImageToWorld(new System.Drawing.Point(e.X, e.Y)); // if (MapCenterChanged != null) // MapCenterChanged(_Map.Center); // } // else // { // if (e.Y - mousedrag.Y < 0) //Zoom out // scale = (float)Math.Pow(1 / (float)(mousedrag.Y - e.Y), 0.5); // else //Zoom in // scale = 1 + (e.Y - mousedrag.Y) * 0.1; // } // _Map.Zoom *= 1 / scale; // if (MapZoomChanged != null) // MapZoomChanged(_Map.Zoom); // Refresh(); // } // else if (this.ActiveTool == Tools.Pan) // { // if (mousedragging) // { // System.Drawing.Point pnt = new System.Drawing.Point(this.Width / 2 + (mousedrag.X - e.Location.X), this.Height / 2 + (mousedrag.Y - e.Location.Y)); // _Map.Center = this._Map.ImageToWorld(pnt); // if (MapCenterChanged != null) // MapCenterChanged(_Map.Center); // } // else // { // _Map.Center = this._Map.ImageToWorld(new System.Drawing.Point(e.X, e.Y)); // if (MapCenterChanged != null) // MapCenterChanged(_Map.Center); // } // Refresh(); // } // else if (this.ActiveTool == Tools.Query) // { // if (_Map.Layers.Count > _queryLayerIndex && _queryLayerIndex > -1) // { // if (_Map.Layers[_queryLayerIndex].GetType() == typeof(SharpMap.Layers.VectorLayer)) // { // SharpMap.Layers.VectorLayer layer = _Map.Layers[_queryLayerIndex] as SharpMap.Layers.VectorLayer; // SharpMap.Geometries.BoundingBox bbox = this._Map.ImageToWorld(new System.Drawing.Point(e.X, e.Y)).GetBoundingBox().Grow(_Map.PixelSize * 5); // SharpMap.Data.FeatureDataSet ds = new SharpMap.Data.FeatureDataSet(); // layer.DataSource.Open(); // layer.DataSource.ExecuteIntersectionQuery(bbox, ds); // layer.DataSource.Close(); // if (ds.Tables.Count > 0) // if (MapQueried != null) MapQueried(ds.Tables[0]); // else // if (MapQueried != null) MapQueried(new SharpMap.Data.FeatureDataTable()); // } // } // else // MessageBox.Show("No active layer to query"); // } // } // if (mousedragImg != null) // { // mousedragImg.Dispose(); // mousedragImg = null; // } // mousedragging = false; }
private void msView_MouseDown(object sender, MouseEventArgs e) { m_clickDown.X = e.X; m_clickDown.Y = e.Y; if(e.Button == MouseButtons.Left) { if(m_pActivetool == Tools.Pan) { m_blnOnPan = true; m_bitbltClickDown.X = e.X; m_bitbltClickDown.Y = e.Y; if (pictureBoxPan.BackgroundImage != null) { pictureBoxPan.BackgroundImage.Dispose(); pictureBoxPan.BackgroundImage = null; } if (this.BackgroundImage != null) { Bitmap pNewImage = new Bitmap(this.BackgroundImage); pictureBoxPan.BackgroundImage = pNewImage; this.BackgroundImage.Dispose(); this.BackgroundImage = null; } pictureBoxPan.Left = 0; pictureBoxPan.Top = 0; pictureBoxPan.Width = this.Width; pictureBoxPan.Height = this.Height; pictureBoxPan.Visible = true; this.Capture = true; } else if (m_pActivetool == Tools.ZoomIn) { this.m_RubberBand = new Rubberband(this, new Point(e.X, e.Y)); } else if (m_pActivetool == Tools.ZoomOut) { this.m_RubberBand = new Rubberband(this, new Point(e.X, e.Y)); } } //if (_Map != null) //{ // if (e.Button == MouseButtons.Left) //dragging // mousedrag = e.Location; // if (MouseDown != null) // MouseDown(this._Map.ImageToWorld(new System.Drawing.Point(e.X, e.Y)), e); //} }