/// <summary> /// Handles the Mouse Up situation /// </summary> /// <param name="e"></param> protected override void OnMouseUp(GeoMouseArgs e) { Map.Invalidate(); Rectangle r = e.Map.MapFrame.View; int w = r.Width; int h = r.Height; if (e.Button == MouseButtons.Left) { r.Inflate(r.Width / 2, r.Height / 2); r.X += w / 2 - e.X; r.Y += h / 2 - e.Y; e.Map.MapFrame.View = r; e.Map.MapFrame.ResetExtents(); } else { r.Inflate(-r.Width / 4, -r.Height / 4); // The mouse cursor should anchor the geographic location during zoom. r.X += (e.X / 2) - w / 4; r.Y += (e.Y / 2) - h / 4; e.Map.MapFrame.View = r; e.Map.MapFrame.ResetExtents(); } base.OnMouseUp(e); }
/// <summary> /// Overrides the OnMouseUp event to handle the situation where we are trying to /// identify the vector features in the specified area. /// </summary> protected override void OnMouseUp(GeoMouseArgs e) { if (e.Button != MouseButtons.Left) { return; } var rtol = new Rectangle(e.X - 8, e.Y - 8, 16, 16); var rstr = new Rectangle(e.X - 1, e.Y - 1, 2, 2); var tolerant = e.Map.PixelToProj(rtol); var strict = e.Map.PixelToProj(rstr); if (_frmFeatureIdentifier == null || _frmFeatureIdentifier.IsDisposed) { _frmFeatureIdentifier = new FeatureIdentifier(); } _frmFeatureIdentifier.treFeatures.BeginUpdate(); _frmFeatureIdentifier.SuspendLayout(); _frmFeatureIdentifier.Clear(); Identify(e.Map.MapFrame.GetLayers(), strict, tolerant); _frmFeatureIdentifier.ReSelect(); _frmFeatureIdentifier.ResumeLayout(); SetSelectToSelectedNode(e.Map); _frmFeatureIdentifier.treFeatures.EndUpdate(); if (!_frmFeatureIdentifier.Visible) { _frmFeatureIdentifier.Show(Map.MapFrame != null ? Map.MapFrame.Parent : null); } base.OnMouseUp(e); }
/// <summary> /// Occurs when the mouse leaves the glyph /// </summary> /// <param name="e"></param> protected virtual void OnGlyphMouseEnter(GeoMouseArgs e) { HasMouse = true; _previousCursor = Map.Cursor; Map.Invalidate(GlpyhBounds); Map.Cursor = Cursor; }
/// <summary> /// Handles the Mouse Up situation. /// </summary> /// <param name="e">The event args.</param> protected override void OnMouseUp(GeoMouseArgs e) { if (!(e.Map.IsZoomedToMaxExtent && e.Button == MouseButtons.Left)) { e.Map.IsZoomedToMaxExtent = false; Map.Invalidate(); Rectangle r = e.Map.MapFrame.View; int w = r.Width; int h = r.Height; if (e.Button == MouseButtons.Left) { r.Inflate(r.Width / 2, r.Height / 2); r.X += (w / 2) - e.X; r.Y += (h / 2) - e.Y; e.Map.MapFrame.View = r; e.Map.MapFrame.ResetExtents(); } else if (e.Button == MouseButtons.Right) { r.Inflate(-r.Width / 4, -r.Height / 4); // The mouse cursor should anchor the geographic location during zoom. r.X += (e.X / 2) - (w / 4); r.Y += (e.Y / 2) - (h / 4); e.Map.MapFrame.View = r; e.Map.MapFrame.ResetExtents(); } base.OnMouseUp(e); } }
/// <summary> /// Overrides the OnMouseUp event to handle the situation where we are trying to /// identify the vector features in the specified area. /// </summary> protected override void OnMouseUp(GeoMouseArgs e) { if (e.Button != MouseButtons.Left) return; var rtol = new Rectangle(e.X - 8, e.Y - 8, 16, 16); var rstr = new Rectangle(e.X - 1, e.Y - 1, 2, 2); var tolerant = e.Map.PixelToProj(rtol); var strict = e.Map.PixelToProj(rstr); if (_frmFeatureIdentifier == null || _frmFeatureIdentifier.IsDisposed) { _frmFeatureIdentifier = new FeatureIdentifier(); } _frmFeatureIdentifier.treFeatures.BeginUpdate(); _frmFeatureIdentifier.SuspendLayout(); _frmFeatureIdentifier.Clear(); Identify(e.Map.MapFrame.GetLayers(), strict, tolerant); _frmFeatureIdentifier.ReSelect(); _frmFeatureIdentifier.ResumeLayout(); SetSelectToSelectedNode(e.Map); _frmFeatureIdentifier.treFeatures.EndUpdate(); if (!_frmFeatureIdentifier.Visible) { _frmFeatureIdentifier.Show(Map.MapFrame != null ? Map.MapFrame.Parent : null); } base.OnMouseUp(e); }
/// <summary> /// Handles the Mouse Up situation. /// </summary> /// <param name="e">The event args.</param> protected override void OnMouseUp(GeoMouseArgs e) { _currentPoint = e.Location; _isDragging = false; Map.Invalidate(); if (_geoStartPoint != null) { SelectionEnvelope = new Envelope(_geoStartPoint.X, e.GeographicLocation.X, _geoStartPoint.Y, e.GeographicLocation.Y); } // If they are not pressing shift, then first clear the selection before adding new members to it. if ((Control.ModifierKeys & Keys.Shift) != Keys.Shift) { foreach (IMapLayer lyr in Map.MapFrame.Layers) { IMapFeatureLayer fl = lyr as IMapFeatureLayer; fl?.LabelLayer?.ClearSelection(); } } _doSelect = true; e.Map.MapFrame.ResetBuffer(); e.Map.Invalidate(); base.OnMouseUp(e); }
/// <summary> /// Fires the MouseUP event /// </summary> /// <param name="e"></param> protected virtual void OnMouseUp(GeoMouseArgs e) { if (MouseUp == null) { return; } MouseUp(this, e); }
/// <summary> /// Allows for inheriting tools to override the behavior /// </summary> /// <param name="e"></param> protected virtual void OnMouseWheel(GeoMouseArgs e) { if (MouseWheel == null) { return; } MouseWheel(this, e); }
/// <summary> /// Fires the DoubleClick event /// </summary> /// <param name="e"></param> protected virtual void OnMouseDoubleClick(GeoMouseArgs e) { if (MouseDoubleClick == null) { return; } MouseDoubleClick(this, e); }
/// <inheritdoc/> protected override void OnGlpyhClick(GeoMouseArgs e) { using (var form = new ExtensionManagerForm()) { form.App = Manager; form.ShowDialog(); } }
/// <summary> /// Mouse Wheel /// </summary> /// <param name="e"></param> protected override void OnMouseWheel(GeoMouseArgs e) //Fix this { _zoomTimer.Stop(); // if the timer was already started, stop it. Extent MaxExtent = e.Map.GetMaxExtent(); if ((e.Map.IsZoomedToMaxExtent == true) && (_direction * e.Delta < 0)) { } else { e.Map.IsZoomedToMaxExtent = false; Rectangle r = e.Map.MapFrame.View; // For multiple zoom steps before redrawing, we actually // want the x coordinate relative to the screen, not // the x coordinate relative to the previously modified view. if (_client == Rectangle.Empty) { _client = r; } int cw = _client.Width; int ch = _client.Height; double w = r.Width; double h = r.Height; if (_direction * e.Delta > 0) { double inFactor = 2.0 * _sensitivity; r.Inflate(Convert.ToInt32(-w / inFactor), Convert.ToInt32(-h / inFactor)); // try to keep the mouse cursor in the same geographic position r.X += Convert.ToInt32((e.X * w / (_sensitivity * cw)) - w / inFactor); r.Y += Convert.ToInt32((e.Y * h / (_sensitivity * ch)) - h / inFactor); } else { double outFactor = 0.5 * _sensitivity; r.Inflate(Convert.ToInt32(w / _sensitivity), Convert.ToInt32(h / _sensitivity)); r.X += Convert.ToInt32(w / _sensitivity - (e.X * w / (outFactor * cw))); r.Y += Convert.ToInt32(h / _sensitivity - (e.Y * h / (outFactor * ch))); } int mapHeight = e.Map.MapFrame.View.Height; int mapWidth = e.Map.MapFrame.View.Width; e.Map.MapFrame.View = r; e.Map.Invalidate(); _zoomTimer.Start(); _mapFrame = e.Map.MapFrame; if (!BusySet) { Map.IsBusy = true; BusySet = true; } base.OnMouseWheel(e); } }
/// <summary> /// Allows for inheriting tools to control OnMouseDoubleClick. /// </summary> /// <param name="e">A GeoMouseArgs parameter</param> protected virtual void OnMouseDoubleClick(GeoMouseArgs e) { var h = MouseDoubleClick; if (h != null) { h(this, e); } }
/// <summary> /// Allows for inheriting tools to control OnMouseMove. /// </summary> /// <param name="e">A GeoMouseArgs parameter</param> protected virtual void OnMouseMove(GeoMouseArgs e) { var h = MouseMove; if (h != null) { h(this, e); } }
/// <summary> /// Allows for inheriting tools to control OnMouseWheel. /// </summary> /// <param name="e">A GeoMouseArgs parameter</param> protected virtual void OnMouseWheel(GeoMouseArgs e) { var h = MouseWheel; if (h != null) { h(this, e); } }
/// <summary> /// Occurs when the mouse enters the glyph /// </summary> /// <param name="e"></param> protected virtual void OnGlyphMouseLeave(GeoMouseArgs e) { HasMouse = false; Map.Invalidate(GlpyhBounds); if (_previousCursor != null) { Map.Cursor = _previousCursor; } }
/// <summary> /// Handles the actions that the tool controls during the OnMouseDown event /// </summary> /// <param name="e"></param> protected override void OnMouseDown(GeoMouseArgs e) { if (e.Button == MouseButtons.Middle && !_preventDrag) { _dragStart = e.Location; _source = e.Map.MapFrame.View; } base.OnMouseDown(e); }
/// <summary> /// Handles the Mouse Up situation /// </summary> /// <param name="e">The event args.</param> protected override void OnMouseUp(GeoMouseArgs e) { if (!(e.Map.IsZoomedToMaxExtent && e.Button == MouseButtons.Left)) { e.Map.IsZoomedToMaxExtent = false; Map.Invalidate(); // CGX int iTemp = Convert.ToInt32(e.Map.MapFrame.CurrentScale); if (iTemp > 1) { int[] array = new int[83] { 500000000, 400000000, 300000000, 250000000, 200000000, 150000000, 125000000, 100000000, 80000000, 60000000, 40000000, 30000000, 25000000, 20000000, 15000000, 12500000, 10000000, 8000000, 6000000, 5000000, 4000000, 3000000, 2500000, 2000000, 1500000, 1250000, 1000000, 800000, 700000, 600000, 500000, 400000, 300000, 250000, 200000, 150000, 125000, 100000, 80000, 70000, 60000, 50000, 40000, 30000, 25000, 20000, 15000, 12500, 10000, 8000, 6000, 5000, 4000, 3000, 2500, 2000, 1500, 1250, 1000, 800, 600, 500, 400, 300, 250, 200, 150, 125, 100, 80, 60, 50, 40, 30, 25, 20, 15, 10, 5, 4, 3, 2, 1 }; var closest = array.Aggregate((current, next) => Math.Abs((long)current - iTemp) < Math.Abs((long)next - iTemp) ? current : next);// array.OrderBy(v => Math.Abs((long)v - lTemp)).First(); int iTemp2 = Convert.ToInt32(closest); while (iTemp2 <= iTemp) { array = array.Where(val => val != iTemp2).ToArray(); closest = Convert.ToInt32(array.Aggregate((current, next) => Math.Abs((long)current - iTemp) < Math.Abs((long)next - iTemp) ? current : next));// array.OrderBy(v => Math.Abs((long)v - lTemp)).First()); iTemp2 = Convert.ToInt32(closest); } e.Map.MapFrame.ComputeExtentFromScale(Convert.ToDouble(closest), e.Location); } // Fin CGX /*Rectangle r = e.Map.MapFrame.View; * int w = r.Width; * int h = r.Height; * * if (e.Button == MouseButtons.Left) * { * r.Inflate(r.Width / 2, r.Height / 2); * r.X += (w / 2) - e.X; * r.Y += (h / 2) - e.Y; * e.Map.MapFrame.View = r; * e.Map.MapFrame.ResetExtents(); * } * else if (e.Button == MouseButtons.Right) * { * r.Inflate(-r.Width / 4, -r.Height / 4); * * // The mouse cursor should anchor the geographic location during zoom. * r.X += (e.X / 2) - (w / 4); * r.Y += (e.Y / 2) - (h / 4); * e.Map.MapFrame.View = r; * e.Map.MapFrame.ResetExtents(); * }*/ base.OnMouseUp(e); } }
/// <summary> /// Handles the actions that the tool controls during the OnMouseDown event /// </summary> /// <param name="e"></param> protected override void OnMouseDown(GeoMouseArgs e) { if (e.Button == MouseButtons.Left && _preventDrag == false) { //PreventBackBuffer = true; _dragStart = e.Location; _source = e.Map.MapFrame.View; } base.OnMouseDown(e); }
/// <summary> /// Handles the MouseDown /// </summary> /// <param name="e"></param> protected override void OnMouseDown(GeoMouseArgs e) { if (e.Button == MouseButtons.Left) { _startPoint = e.Location; _geoStartPoint = e.GeographicLocation; _isDragging = true; } base.OnMouseDown(e); }
/// <summary> /// Even though we don't take action here, we need to indicate that we handled the event so that the other /// functions that my be active don't do anything for this part. /// </summary> /// <param name="e"></param> protected override void OnMouseDown(GeoMouseArgs e) { Rectangle glyph = GlpyhBounds; if (glyph.Contains(e.Location)) { // whether they do anything or not, the glyph is the only thing that should happen in this window. e.Handled = true; } }
/// <summary> /// Handles the MouseDown /// </summary> /// <param name="e"></param> protected override void OnMouseDown(GeoMouseArgs e) { if (e.Button == MouseButtons.Left) { _startPoint = e.Location; _geoStartPoint = e.GeographicLocation; _isDragging = true; Map.IsBusy = true; } base.OnMouseDown(e); }
/// <summary> /// Handles the Mouse Up situation /// </summary> /// <param name="e">The event args.</param> protected override void OnMouseUp(GeoMouseArgs e) { if (!(e.Map.IsZoomedToMaxExtent && e.Button == MouseButtons.Right)) { e.Map.IsZoomedToMaxExtent = false; bool handled = false; _currentPoint = e.Location; Map.Invalidate(); if (_isDragging) { if (_geoStartPoint != null && _startPoint != e.Location) { Envelope env = new Envelope(_geoStartPoint.X, e.GeographicLocation.X, _geoStartPoint.Y, e.GeographicLocation.Y); if (Math.Abs(e.X - _startPoint.X) > 1 && Math.Abs(e.Y - _startPoint.Y) > 1) { e.Map.ViewExtents = env.ToExtent(); handled = true; } } } _isDragging = false; if (handled == false) { Rectangle r = e.Map.MapFrame.View; int w = r.Width; int h = r.Height; if (e.Button == MouseButtons.Left) { r.Inflate(-r.Width / 4, -r.Height / 4); // The mouse cursor should anchor the geographic location during zoom. r.X += (e.X / 2) - (w / 4); r.Y += (e.Y / 2) - (h / 4); } else if (e.Button == MouseButtons.Right) { r.Inflate(r.Width / 2, r.Height / 2); r.X += (w / 2) - e.X; r.Y += (h / 2) - e.Y; } e.Map.MapFrame.View = r; e.Map.MapFrame.ResetExtents(); } } base.OnMouseUp(e); Map.IsBusy = false; }
/// <summary> /// Handles MouseMove /// </summary> /// <param name="e"></param> protected override void OnMouseMove(GeoMouseArgs e) { if (_isDragging) { int x = Math.Min(Math.Min(_startPoint.X, _currentPoint.X), e.X); int y = Math.Min(Math.Min(_startPoint.Y, _currentPoint.Y), e.Y); int mx = Math.Max(Math.Max(_startPoint.X, _currentPoint.X), e.X); int my = Math.Max(Math.Max(_startPoint.Y, _currentPoint.Y), e.Y); _currentPoint = e.Location; Map.Invalidate(new Rectangle(x, y, mx - x, my - y)); } base.OnMouseMove(e); }
/// <summary> /// Handles the mouse move event, changing the viewing extents to match the movements /// of the mouse if the left mouse button is down. /// </summary> /// <param name="e"></param> protected override void OnMouseMove(GeoMouseArgs e) { if (_isDragging) { Point diff = new Point { X = _dragStart.X - e.X, Y = _dragStart.Y - e.Y }; e.Map.MapFrame.View = new Rectangle(_source.X + diff.X, _source.Y + diff.Y, _source.Width, _source.Height); Map.Invalidate(); } base.OnMouseMove(e); }
/// <summary> /// Mouse Up /// </summary> /// <param name="e"></param> protected override void OnMouseUp(GeoMouseArgs e) { if (e.Button == MouseButtons.Middle && _isDragging) { _isDragging = false; _preventDrag = true; e.Map.MapFrame.ResetExtents(); _preventDrag = false; Map.IsBusy = false; BusySet = false; } _dragStart = Point.Empty; base.OnMouseUp(e); }
/// <summary> /// Mouse Up /// </summary> /// <param name="e"></param> protected override void OnMouseUp(GeoMouseArgs e) { if (e.Button == MouseButtons.Left && _isDragging) { _isDragging = false; _preventDrag = true; e.Map.MapFrame.ResetExtents(); _preventDrag = false; Map.IsBusy = false; } //Map.Invalidate(); base.OnMouseUp(e); }
/// <summary> /// Handles the Mouse Up situation. /// </summary> /// <param name="e">The event args.</param> protected override void OnMouseUp(GeoMouseArgs e) { if (Map == null) { Map = e.Map; } if (_isDragging == false) { return; } #if DEBUG var sw = new Stopwatch(); sw.Start(); #endif _currentPoint = e.Location; _isDragging = false; Envelope env = new Envelope(_geoStartPoint.X, e.GeographicLocation.X, _geoStartPoint.Y, e.GeographicLocation.Y); Envelope tolerant = env; if (_startPoint.X == e.X && _startPoint.Y == e.Y) { // click selection doesn't work quite right without some tiny tolerance. double tol = Map.MapFrame.ViewExtents.Width / 10000; env.ExpandBy(tol); } if (Math.Abs(_startPoint.X - e.X) < 8 && Math.Abs(_startPoint.Y - e.Y) < 8) { Coordinate c1 = e.Map.PixelToProj(new Point(e.X - 4, e.Y - 4)); Coordinate c2 = e.Map.PixelToProj(new Point(e.X + 4, e.Y + 4)); tolerant = new Envelope(c1, c2); } HandleSelection(tolerant, env); Map.MapFrame.ResumeEvents(); // Force an invalidate to clear the dotted lines, even if we haven't changed anything. e.Map.Invalidate(); #if DEBUG sw.Stop(); Debug.WriteLine("Initialize: " + sw.ElapsedMilliseconds); #endif base.OnMouseUp(e); Map.IsBusy = false; }
/// <summary> /// Mouse Wheel /// </summary> /// <param name="e">The event args.</param> protected override void OnMouseWheel(GeoMouseArgs e) { _zoomTimer.Stop(); // if the timer was already started, stop it. if (!(e.Map.IsZoomedToMaxExtent && (_direction * e.Delta < 0))) { e.Map.IsZoomedToMaxExtent = false; double dCurrentScale = e.Map.MapFrame.CurrentScale; int iCurrentScale = (int)dCurrentScale; int iScalesCount = scaleArray.Length; int iClosestCurrentIndex = 0; for (int iIndex = scaleArray[iScalesCount / 2] > iCurrentScale ? iScalesCount / 2 : 0; iIndex < iScalesCount; iIndex++) { if (scaleArray[iIndex] <= iCurrentScale) { iClosestCurrentIndex = iIndex; break; } } if (iClosestCurrentIndex > 0) { double dDiffLowerFromCurrent = dCurrentScale - (double)scaleArray[iClosestCurrentIndex]; double dDiffUpperFromCurrent = (double)scaleArray[iClosestCurrentIndex - 1] - dCurrentScale; if (dDiffUpperFromCurrent < dDiffLowerFromCurrent) { iClosestCurrentIndex--; } } int iIndexNow = iClosestCurrentIndex + (e.Delta * _direction) / SystemInformation.MouseWheelScrollDelta; if (iIndexNow < 0) { iIndexNow = 0; } else if (iIndexNow > iScalesCount - 2) { iIndexNow = iScalesCount - 2; // last of array is 'zero' } if (!BusySet) { Map.IsBusy = true; BusySet = true; } e.Map.MapFrame.ComputeExtentFromScale((double)scaleArray[iIndexNow], e.Location); base.OnMouseWheel(e); } }
/// <summary> /// Handles the mouse move event, changing the viewing extents to match the movements /// of the mouse if the left mouse button is down. /// </summary> /// <param name="e"></param> protected override void OnMouseMove(GeoMouseArgs e) { if (_dragStart != Point.Empty && !_preventDrag) { if (!BusySet) { Map.IsBusy = true; BusySet = true; } _isDragging = true; Point diff = new Point { X = _dragStart.X - e.X, Y = _dragStart.Y - e.Y }; e.Map.MapFrame.View = new Rectangle(_source.X + diff.X, _source.Y + diff.Y, _source.Width, _source.Height); Map.Invalidate(); } base.OnMouseMove(e); }
/// <summary> /// Overrides the OnMouseUp event to handle the situation where we are trying to /// identify the vector features in the specified area. /// </summary> /// <param name="e"></param> protected override void OnMouseUp(GeoMouseArgs e) { if (e.Button != MouseButtons.Left) return; Rectangle rtol = new Rectangle(e.X - 8, e.Y - 8, 16, 16); Rectangle rstr = new Rectangle(e.X - 1, e.Y - 1, 2, 2); Extent tolerant = e.Map.PixelToProj(rtol); Extent strict = e.Map.PixelToProj(rstr); if (_frmFeatureIdentifier == null) { _frmFeatureIdentifier = new FeatureIdentifier(); } _frmFeatureIdentifier.SuspendLayout(); _frmFeatureIdentifier.Clear(); Identify(e.Map.MapFrame.GetLayers(), strict, tolerant); _frmFeatureIdentifier.ReSelect(); _frmFeatureIdentifier.ResumeLayout(); _frmFeatureIdentifier.Show(Map.MapFrame != null? Map.MapFrame.Parent : null); base.OnMouseUp(e); }
/// <inheritdoc/> protected override void OnMouseMove(GeoMouseArgs e) { Rectangle glyph = GlpyhBounds; if (glyph.Contains(e.Location)) { if (!HasMouse) { HasMouse = true; OnGlyphMouseEnter(e); } e.Handled = true; } else { if (HasMouse) { HasMouse = false; OnGlyphMouseLeave(e); } } }
/// <summary> /// Overrides the OnMouseUp event to handle the situation where we are trying to /// identify the vector features in the specified area. /// </summary> /// <param name="e"></param> protected override void OnMouseUp(GeoMouseArgs e) { if (e.Button != MouseButtons.Left) { return; } Rectangle rtol = new Rectangle(e.X - 8, e.Y - 8, 16, 16); Rectangle rstr = new Rectangle(e.X - 1, e.Y - 1, 2, 2); Extent tolerant = e.Map.PixelToProj(rtol); Extent strict = e.Map.PixelToProj(rstr); if (_frmFeatureIdentifier == null) { _frmFeatureIdentifier = new FeatureIdentifier(); } _frmFeatureIdentifier.SuspendLayout(); _frmFeatureIdentifier.Clear(); Identify(e.Map.MapFrame.GetLayers(), strict, tolerant); _frmFeatureIdentifier.ReSelect(); _frmFeatureIdentifier.ResumeLayout(); _frmFeatureIdentifier.Show(); base.OnMouseUp(e); }
/// <summary> /// This method occurs as the mouse moves. /// </summary> /// <param name="e">The GeoMouseArcs class describes the mouse condition along with geographic coordinates.</param> protected override void OnMouseMove(GeoMouseArgs e) { if (_standBy) { return; } // Begin snapping changes Coordinate snappedCoord = e.GeographicLocation; bool prevWasSnapped = this.isSnapped; this.isSnapped = ComputeSnappedLocation(e, ref snappedCoord); _coordinateDialog.X = snappedCoord.X; _coordinateDialog.Y = snappedCoord.Y; // End snapping changes if (_coordinates != null && _coordinates.Count > 0) { List<Point> points = _coordinates.Select(coord => Map.ProjToPixel(coord)).ToList(); Rectangle oldRect = SymbologyGlobal.GetRectangle(_mousePosition, points[points.Count - 1]); Rectangle newRect = SymbologyGlobal.GetRectangle(e.Location, points[points.Count - 1]); Rectangle invalid = Rectangle.Union(newRect, oldRect); invalid.Inflate(20, 20); Map.Invalidate(invalid); } // Begin snapping changes _mousePosition = this.isSnapped ? Map.ProjToPixel(snappedCoord) : e.Location; DoMouseMoveForSnapDrawing(prevWasSnapped, _mousePosition); // End snapping changes base.OnMouseMove(e); }
/// <summary> /// Fires the OnMouseMove event on the Active Tools /// </summary> /// <param name="e"></param> protected override void OnMouseMove(MouseEventArgs e) { GeoMouseArgs args = new GeoMouseArgs(e, this); foreach (IMapFunction tool in MapFunctions) { if (tool.Enabled) { tool.DoMouseMove(args); if (args.Handled) break; } } if (GeoMouseMove != null) { GeoMouseMove(this, new GeoMouseArgs(e, this)); } base.OnMouseMove(e); }
/// <summary> /// Handles the Mouse Up situation /// </summary> /// <param name="e"></param> protected override void OnMouseUp(GeoMouseArgs e) { if (Map == null) Map = e.Map; Stopwatch sw = new Stopwatch(); sw.Start(); if (_isDragging == false) return; _currentPoint = e.Location; _isDragging = false; //Map.Invalidate(); // Get rid of the selection box //Application.DoEvents(); IEnvelope env = new Envelope(_geoStartPoint.X, e.GeographicLocation.X, _geoStartPoint.Y, e.GeographicLocation.Y); IEnvelope tolerant = env; if (_startPoint.X == e.X && _startPoint.Y == e.Y) { // click selection doesn't work quite right without some tiny tolerance. double tol = Map.MapFrame.ViewExtents.Width / 10000; env.ExpandBy(tol); } if (Math.Abs(_startPoint.X - e.X) < 8 && Math.Abs(_startPoint.Y - e.Y) < 8) { Coordinate c1 = e.Map.PixelToProj(new Point(e.X - 4, e.Y - 4)); Coordinate c2 = e.Map.PixelToProj(new Point(e.X + 4, e.Y + 4)); tolerant = new Envelope(c1, c2); } former = null; foreach (var l in Map.MapFrame.GetAllLayers()) { if (l.IsSelected) { former = l; l.IsSelected = false; } } if (former == null && Map.MapFrame.IsSelected) { former = Map.MapFrame; } Map.MapFrame.IsSelected = true; Map.MapFrame.SuspendEvents(); HandleSelection(tolerant, env); Map.MapFrame.IsSelected = false; if (former != null) { former.IsSelected = true; } Map.MapFrame.ResumeEvents(); // Force an invalidate to clear the dotted lines, even if we haven't changed anything. e.Map.Invalidate(); //e.Map.MapFrame.Initialize(); sw.Stop(); Debug.WriteLine("Initialize: " + sw.ElapsedMilliseconds); base.OnMouseUp(e); Map.IsBusy = false; }
/// <inheritdoc/> protected override void OnMouseUp(GeoMouseArgs e) { Rectangle glyph = GlpyhBounds; if (glyph.Contains(e.Location)) { OnGlpyhClick(e); // whether they do anything or not, the glyph is the only thing that should happen in this window. e.Handled = true; } }
/// <summary> /// Computes a snapped coordinate. If the mouse is near a snappable object, the output /// location of the mouse will be the coordinates of the object rather than the actual /// mouse coords. /// </summary> /// <param name="e"></param> /// <param name="snappedCoord">set if a coordinate is found</param> /// <returns>true if snap found</returns> protected bool ComputeSnappedLocation(GeoMouseArgs e, ref Coordinate snappedCoord) { if (this.snapLayers == null || e == null || Map == null) return false; Rectangle mouseRect = new Rectangle(e.X - this.snapTol, e.Y - this.snapTol, this.snapTol * 2, this.snapTol * 2); Extent pix = Map.PixelToProj(mouseRect); if (pix == null) return false; IEnvelope env = pix.ToEnvelope(); foreach (IFeatureLayer layer in this.snapLayers) { foreach (IFeature feat in layer.DataSet.Features) { foreach (Coordinate c in feat.Coordinates) { // If the mouse envelope contains the current coordinate, we found a // snap location. if (env.Contains(c)) { snappedCoord = c; return true; } } } } return false; }
/// <summary> /// Forces this tool to execute whatever behavior should occur during a double click even on the panel /// </summary> /// <param name="e"></param> public void DoMouseDoubleClick(GeoMouseArgs e) { OnMouseDoubleClick(e); }
/// <summary> /// Handles the Mouse-Up situation /// </summary> /// <param name="e"></param> protected override void OnMouseUp(GeoMouseArgs e) { if (_standBy) { return; } // Add the current point to the featureset if (e.Button == MouseButtons.Right) { if (_coordinates.Count > 1) { _previousParts.Add(_coordinates); if (_areaMode) { _measureDialog.TotalArea = _currentArea; } else { _previousDistance += _currentDistance; _currentDistance = 0; _currentArea = 0; _measureDialog.Distance = 0; _measureDialog.TotalDistance = _previousDistance; } } _coordinates = new List<Coordinate>(); Map.Invalidate(); } else { if (_coordinates == null) { _coordinates = new List<Coordinate>(); } if (_coordinates.Count > 0) { if (_measureDialog.MeasureMode == MeasureMode.Distance) { Coordinate c1 = e.GeographicLocation; double dist = GetDist(c1); _measureDialog.TotalDistance = _previousDistance + dist; _currentDistance += dist; } } _coordinates.Add(e.GeographicLocation); if (_areaMode) { if (_coordinates.Count >= 3) { double area = GetArea(_coordinates); _currentArea = area; } } Map.Invalidate(); } base.OnMouseUp(e); }
/// <summary> /// Handles the Mouse Up situation /// </summary> /// <param name="e"></param> protected override void OnMouseUp(GeoMouseArgs e) { e.Map.IsZoomedToMaxExtent = false; bool handled = false; _currentPoint = e.Location; Map.Invalidate(); if (_isDragging) { if (_geoStartPoint != null && _startPoint != e.Location) { IEnvelope env = new Envelope(_geoStartPoint.X, e.GeographicLocation.X, _geoStartPoint.Y, e.GeographicLocation.Y); if (Math.Abs(e.X - _startPoint.X) > 1 && Math.Abs(e.Y - _startPoint.Y) > 1) { e.Map.ViewExtents = env.ToExtent(); handled = true; } } } _isDragging = false; if (handled == false) { Rectangle r = e.Map.MapFrame.View; int w = r.Width; int h = r.Height; if (e.Button == MouseButtons.Left) { r.Inflate(-r.Width / 4, -r.Height / 4); // The mouse cursor should anchor the geographic location during zoom. r.X += (e.X / 2) - w / 4; r.Y += (e.Y / 2) - h / 4; } else { r.Inflate(r.Width / 2, r.Height / 2); r.X += w / 2 - e.X; r.Y += h / 2 - e.Y; } e.Map.MapFrame.View = r; e.Map.MapFrame.ResetExtents(); } base.OnMouseUp(e); Map.IsBusy = false; }
/// <summary> /// Mouse Wheel /// </summary> /// <param name="e"></param> protected override void OnMouseWheel(GeoMouseArgs e) //Fix this { _zoomTimer.Stop(); // if the timer was already started, stop it. Extent MaxExtent = e.Map.GetMaxExtent(); if ((e.Map.IsZoomedToMaxExtent == true) && (_direction * e.Delta < 0)) {} else { e.Map.IsZoomedToMaxExtent = false; Rectangle r = e.Map.MapFrame.View; // For multiple zoom steps before redrawing, we actually // want the x coordinate relative to the screen, not // the x coordinate relative to the previously modified view. if (_client == Rectangle.Empty) { _client = r; } int cw = _client.Width; int ch = _client.Height; double w = r.Width; double h = r.Height; if (_direction * e.Delta > 0) { double inFactor = 2.0 * _sensitivity; r.Inflate(Convert.ToInt32(-w / inFactor), Convert.ToInt32(-h / inFactor)); // try to keep the mouse cursor in the same geographic position r.X += Convert.ToInt32((e.X * w / (_sensitivity * cw)) - w / inFactor); r.Y += Convert.ToInt32((e.Y * h / (_sensitivity * ch)) - h / inFactor); } else { double outFactor = 0.5 * _sensitivity; r.Inflate(Convert.ToInt32(w / _sensitivity), Convert.ToInt32(h / _sensitivity)); r.X += Convert.ToInt32(w / _sensitivity - (e.X * w / (outFactor * cw))); r.Y += Convert.ToInt32(h / _sensitivity - (e.Y * h / (outFactor * ch))); } int mapHeight = e.Map.MapFrame.View.Height; int mapWidth = e.Map.MapFrame.View.Width; e.Map.MapFrame.View = r; e.Map.Invalidate(); _zoomTimer.Start(); _mapFrame = e.Map.MapFrame; if (!BusySet) { Map.IsBusy = true; BusySet = true; } base.OnMouseWheel(e); } }
/// <summary> /// Occurs when the mouse clicks on the glyph /// </summary> /// <param name="e"></param> protected virtual void OnGlpyhClick(GeoMouseArgs e) { }
/// <summary> /// Handles MouseMove /// </summary> /// <param name="e"></param> protected override void OnMouseMove(GeoMouseArgs e) { _currentPoint = e.Location; Map.Invalidate(); base.OnMouseMove(e); }
private void Map_GeoMouseMove(object sender, GeoMouseArgs e) { xPanel.Caption = String.Format("X: {0:.#####}", e.GeographicLocation.X); yPanel.Caption = String.Format("Y: {0:.#####}", e.GeographicLocation.Y); }
/// <summary> /// Instructs this tool to perform any actions that should occur on the MouseDown event /// </summary> /// <param name="e">A MouseEventArgs relative to the drawing panel</param> public void DoMouseDown(GeoMouseArgs e) { OnMouseDown(e); }
/// <summary> /// Instructs this tool to perform any actions that should occur on the MouseMove event /// </summary> /// <param name="e">A MouseEventArgs relative to the drawing panel</param> public void DoMouseMove(GeoMouseArgs e) { OnMouseMove(e); }
/// <summary> /// Instructs this tool to perform any actions that should occur on the MouseUp event /// </summary> /// <param name="e">A MouseEventArgs relative to the drawing panel</param> public void DoMouseUp(GeoMouseArgs e) { OnMouseUp(e); }
/// <summary> /// Handles MouseMove /// </summary> /// <param name="e"></param> protected override void OnMouseMove(GeoMouseArgs e) { int x = Math.Min(Math.Min(_startPoint.X, _currentPoint.X), e.X); int y = Math.Min(Math.Min(_startPoint.Y, _currentPoint.Y), e.Y); int mx = Math.Max(Math.Max(_startPoint.X, _currentPoint.X), e.X); int my = Math.Max(Math.Max(_startPoint.Y, _currentPoint.Y), e.Y); _currentPoint = e.Location; if (_isDragging) { Map.Invalidate(new Rectangle(x, y, mx - x, my - y)); } base.OnMouseMove(e); }
/// <summary> /// Instructs this tool to perform any actions that should occur on the MouseWheel event /// </summary> /// <param name="e">A MouseEventArgs relative to the drawing panel</param> public void DoMouseWheel(GeoMouseArgs e) { OnMouseWheel(e); }
/// <summary> /// Handles the Mouse Up situation /// </summary> /// <param name="e"></param> protected override void OnMouseUp(GeoMouseArgs e) { if (Map == null) { Map = e.Map; } Stopwatch sw = new Stopwatch(); sw.Start(); if (_isDragging == false) { return; } _currentPoint = e.Location; _isDragging = false; //Map.Invalidate(); // Get rid of the selection box //Application.DoEvents(); IEnvelope env = new Envelope(_geoStartPoint.X, e.GeographicLocation.X, _geoStartPoint.Y, e.GeographicLocation.Y); IEnvelope tolerant = env; if (_startPoint.X == e.X && _startPoint.Y == e.Y) { // click selection doesn't work quite right without some tiny tolerance. double tol = Map.MapFrame.ViewExtents.Width / 10000; env.ExpandBy(tol); } if (Math.Abs(_startPoint.X - e.X) < 8 && Math.Abs(_startPoint.Y - e.Y) < 8) { Coordinate c1 = e.Map.PixelToProj(new Point(e.X - 4, e.Y - 4)); Coordinate c2 = e.Map.PixelToProj(new Point(e.X + 4, e.Y + 4)); tolerant = new Envelope(c1, c2); } former = null; foreach (var l in Map.MapFrame.GetAllLayers()) { if (l.IsSelected) { former = l; l.IsSelected = false; } } if (former == null && Map.MapFrame.IsSelected) { former = Map.MapFrame; } Map.MapFrame.IsSelected = true; Map.MapFrame.SuspendEvents(); HandleSelection(tolerant, env); Map.MapFrame.IsSelected = false; if (former != null) { former.IsSelected = true; } Map.MapFrame.ResumeEvents(); // Force an invalidate to clear the dotted lines, even if we haven't changed anything. e.Map.Invalidate(); //e.Map.MapFrame.Initialize(); sw.Stop(); Debug.WriteLine("Initialize: " + sw.ElapsedMilliseconds); base.OnMouseUp(e); Map.IsBusy = false; }
/// <summary> /// Fires the OnMouseWheel event for the active tools /// </summary> /// <param name="e"></param> protected override void OnMouseWheel(MouseEventArgs e) { GeoMouseArgs args = new GeoMouseArgs(e, this); foreach (IMapFunction tool in MapFunctions) { if (tool.Enabled) { tool.DoMouseWheel(args); if (args.Handled) break; } } base.OnMouseWheel(e); }
/// <summary> /// updates the auto-filling X and Y coordinates /// </summary> /// <param name="e"></param> protected override void OnMouseMove(GeoMouseArgs e) { if (_standBy) { return; } if (_coordinates == null || _coordinates.Count == 0) { return; } Coordinate c1 = e.GeographicLocation; if (_measureDialog.MeasureMode == MeasureMode.Distance) { double dist = GetDist(c1); _measureDialog.TotalDistance = _previousDistance + _currentDistance + dist; } else { List<Coordinate> tempPolygon = _coordinates.ToList(); tempPolygon.Add(c1); if (tempPolygon.Count < 3) { if (tempPolygon.Count == 2) { Rectangle r = Map.ProjToPixel(new LineString(tempPolygon).Envelope.ToExtent()); r.Inflate(20, 20); Map.Invalidate(r); } _mousePosition = e.Location; return; } Polygon pg = new Polygon(new LinearRing(tempPolygon)); double area = GetArea(tempPolygon); _measureDialog.TotalArea = area; Rectangle rr = Map.ProjToPixel(pg.Envelope.ToExtent()); rr.Inflate(20, 20); Map.Invalidate(rr); _mousePosition = e.Location; } if (_coordinates.Count > 0) { List<Point> points = _coordinates.Select(coord => Map.ProjToPixel(coord)).ToList(); Rectangle oldRect = SymbologyGlobal.GetRectangle(_mousePosition, points[points.Count - 1]); Rectangle newRect = SymbologyGlobal.GetRectangle(e.Location, points[points.Count - 1]); Rectangle invalid = Rectangle.Union(newRect, oldRect); invalid.Inflate(20, 20); Map.Invalidate(invalid); } _mousePosition = e.Location; base.OnMouseMove(e); }
/// <summary> /// Handles the Mouse-Up situation. /// </summary> /// <param name="e">The GeoMouseArcs class describes the mouse condition along with geographic coordinates.</param> protected override void OnMouseUp(GeoMouseArgs e) { if (_standBy) { return; } if (_featureSet == null || _featureSet.IsDisposed) { return; } // Add the current point to the featureset if (_featureSet.FeatureType == FeatureType.Point) { // Begin snapping changes Coordinate snappedCoord = _coordinateDialog.Coordinate; ComputeSnappedLocation(e, ref snappedCoord); // End snapping changes Topology.Point pt = new Topology.Point(snappedCoord); // Snapping changes Feature f = new Feature(pt); _featureSet.Features.Add(f); _featureSet.UpdateExtent(); _featureSet.InvalidateVertices(); return; } if (e.Button == MouseButtons.Right) { _context.Show((Control)Map, e.Location); } else { if (_coordinates == null) { _coordinates = new List<Coordinate>(); } // Begin snapping changes Coordinate snappedCoord = e.GeographicLocation; ComputeSnappedLocation(e, ref snappedCoord); // End snapping changes _coordinates.Add(snappedCoord); // Snapping changes if (_coordinates.Count > 1) { Point p1 = Map.ProjToPixel(_coordinates[_coordinates.Count - 1]); Point p2 = Map.ProjToPixel(_coordinates[_coordinates.Count - 2]); Rectangle invalid = SymbologyGlobal.GetRectangle(p1, p2); invalid.Inflate(20, 20); Map.Invalidate(invalid); } } base.OnMouseUp(e); }
/// <summary> /// Handles the Mouse Up situation /// </summary> /// <param name="e"></param> protected override void OnMouseUp(GeoMouseArgs e) { _currentPoint = e.Location; _isDragging = false; Map.Invalidate(); if (_geoStartPoint != null) { _selectionEnvelope = new Envelope(_geoStartPoint.X, e.GeographicLocation.X, _geoStartPoint.Y, e.GeographicLocation.Y); } // If they are not pressing shift, then first clear the selection before adding new members to it. if (((Control.ModifierKeys & Keys.Shift) == Keys.Shift) == false) { foreach (IMapLayer lyr in Map.MapFrame.Layers) { IMapFeatureLayer fl = lyr as IMapFeatureLayer; if (fl == null) { continue; } IMapLabelLayer gll = fl.LabelLayer; if (gll != null) { gll.ClearSelection(); } } } _doSelect = true; e.Map.MapFrame.ResetBuffer(); e.Map.Invalidate(); base.OnMouseUp(e); }