예제 #1
0
 /// <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);
 }
예제 #2
0
        /// <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;
                _isDragging = true;
                _dragStart = e.Location;
                _source = e.Map.MapFrame.View;
                Map.CollectAfterDraw = false;

            }
            base.OnMouseDown(e);
        }
        /// <summary>
        /// Overrides the OnMouseUp event to handle the situation where we are tyring to
        /// identify the vector features in the specified area.
        /// </summary>
        /// <param name="e"></param>
        protected override void OnMouseUp(GeoMouseArgs e)
        {
            Coordinate c1 = e.Map.PixelToProj(new System.Drawing.Point(e.X - 8, e.Y - 8));
            Coordinate c2 = e.Map.PixelToProj(new System.Drawing.Point(e.X + 8, e.Y + 8));
            Coordinate s1 = e.Map.PixelToProj(new System.Drawing.Point(e.X - 1, e.Y - 1));
            Coordinate s2 = e.Map.PixelToProj(new System.Drawing.Point(e.X + 1, e.Y + 1));
            Coordinate center = e.Map.PixelToProj(new System.Drawing.Point(e.X, e.Y));
            IEnvelope tolerant = new Envelope(c1, c2);
            IEnvelope strict = new Envelope(s1, s2);

            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);
        }
예제 #4
0
        /// <summary>
        /// Mouse Wheel
        /// </summary>
        /// <param name="e"></param>
        protected override void OnMouseWheel(GeoMouseArgs e)
        {
 
            _zoomTimer.Stop(); // if the timer was already started, stop it.
            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;

            int w = r.Width;
            int h = r.Height;
            if (e.Delta > 0)
            {
                
                r.Inflate(-w / 4, -h / 4);
                // try to keep the mouse cursor in the same geographic position
                r.X += (e.X * w/(2*cw)) - w/4; 
                r.Y += (e.Y * w/(2*cw)) - h/4;
            }
            else
            {
                r.Inflate(w / 2, h / 2);
                r.X += w/2 - (e.X * w / cw);
                r.Y += h/2 - (e.Y * w / cw);

            }

            e.Map.MapFrame.View = r;
            e.Map.Invalidate();
            _zoomTimer.Start();
            _mapFrame = e.Map.MapFrame;
            base.OnMouseWheel(e);
        }
 protected override void OnMouseDown(GeoMouseArgs e)
 {
     _mousePosition = e.Location;
     if(_dragging)
     {
         if(e.Button == MouseButtons.Right)
         {
             _dragging = false;
             Map.Invalidate();
         }
     }
     else
     {
         if(_selectedFeature != null)
         {
             Rectangle mouseRect = new Rectangle(_mousePosition.X - 3, _mousePosition.Y - 3, 6, 6);
             
             IEnvelope env = Map.PixelToProj(mouseRect);
             
             if(CheckForVertexDrag(e)) return;
            
             // No vertex selection has occured.
             if(!_selectedFeature.Intersects(env.ToPolygon()))
             {
                 // We are clicking down outside of the given polygon, so clear our selected feature 
                 UnSelectFeature();
                 return;
             }
            
         }
        
         if(_activeFeature != null)
         {
             
             // Don't start dragging a vertices right away for polygons and lines.  
             // First you select the polygon, which displays the vertices, then they can be moved.
             if(_featureSet.FeatureType == FeatureTypes.Polygon)
             {
                 
                 _selectedFeature = _activeFeature;
                 _activeFeature = null;
                 IPolygonCategory sc = _selectedCategory as IPolygonCategory;
                 if (sc == null)
                 {
                     _selectedCategory = new PolygonCategory(Color.FromArgb(55, 0, 255, 255), Color.Blue, 1);
                     _selectedCategory.LegendItemVisible = false;
                 }
                 
                 _layer.SetCategory(_selectedFeature, _selectedCategory);
             }
             else if (_featureSet.FeatureType == FeatureTypes.Line)
             {
                 
                 _selectedFeature = _activeFeature;
                 _activeFeature = null;
                 ILineCategory sc = _selectedCategory as ILineCategory;
                 if (sc == null)
                 {
                     _selectedCategory = new LineCategory(Color.Cyan, 1);
                     _selectedCategory.LegendItemVisible = false;
                 }
                 _layer.SetCategory(_selectedFeature, _selectedCategory);
             }
             else
             {
                 _dragging = true;
                 _dragCoord = _activeFeature.Coordinates[0];
                 MapPointLayer mpl = _layer as MapPointLayer;
                 if(mpl != null)
                 {
                     mpl.SetVisible(_activeFeature, false);
                 }
                 IPointCategory sc = _selectedCategory as IPointCategory;
                 if(sc == null)
                 {
                     IPointSymbolizer ps = _layer.GetCategory(_activeFeature).Symbolizer.Copy() as IPointSymbolizer;
                     if(ps != null)
                     {
                         ps.SetFillColor(Color.Cyan);
                         _selectedCategory = new PointCategory(ps);
                     }
 
                 }
             }
         }
         Map.MapFrame.Initialize();
         Map.Invalidate();
     }
 }
 /// <summary>
 /// Handles the Mouse-Up situation
 /// </summary>
 /// <param name="e"></param>
 protected override void OnMouseUp(GeoMouseArgs e)
 {
     if (_standBy) return;
     if (_featureSet == null) return;
     // Add the current point to the featureset
     if (_featureSet.FeatureType == FeatureTypes.Point)
     {
         MapWindow.Geometries.Point pt = new MapWindow.Geometries.Point(_coordinateDialog.Coordinate);
         Feature f = new Feature(pt);
         _featureSet.Features.Add(f);
         _featureSet.UpdateEnvelopes();
         _featureSet.InvalidateVertices();
         return;
     }
     
     if (e.Button == MouseButtons.Right)
     {
         _context.Show((Control)Map, e.Location);
     }
     else
     {
         if (_coordinates == null) _coordinates = new List<Coordinate>();
         _coordinates.Add(e.GeographicLocation);
         if (_coordinates.Count > 1)
         {
             System.Drawing.Point p1 = Map.ProjToPixel(_coordinates[_coordinates.Count - 1]);
             System.Drawing.Point p2 = Map.ProjToPixel(_coordinates[_coordinates.Count - 2]);
             Rectangle invalid = Global.GetRectangle(p1, p2);
             invalid.Inflate(20, 20);
             Map.Invalidate(invalid);
         }
            
         
         
        
     }
     
     base.OnMouseUp(e);
 }
예제 #7
0
 /// <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.Values)
     {
         if (tool.Enabled)
         {
             tool.DoMouseWheel(args);
             if (args.Handled) break;
         }
     }
     base.OnMouseWheel(e);
 }
예제 #8
0
 /// <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);
 }
예제 #9
0
 /// <summary>
 /// allows for inheriting tools to control OnMouseMove
 /// </summary>
 /// <param name="e">A GeoMouseArgs parameter</param>
 protected virtual void OnMouseMove(GeoMouseArgs e)
 {
     if (MouseMove == null) return;
     MouseMove(this, e);
 }
예제 #10
0
        /// <summary>
        /// Fires the MouseUP event
        /// </summary>
        /// <param name="e"></param>
        protected virtual void OnMouseUp(GeoMouseArgs e)
        {
            if (MouseUp == null) return;
            MouseUp(this, e);

        }
예제 #11
0
        /// <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 == System.Windows.Forms.MouseButtons.Right)
            {
                _previousDistance = 0;
                _coordinates = new List<Coordinate>();
                Map.Invalidate();
            }
            else
            {
                if (_coordinates == null) _coordinates = new List<Coordinate>();
               
                if (_coordinates.Count > 0)
                {
                    if (_measureDialog.MeasureMode == MeasureModes.Distance)
                    {
                        Coordinate c1 = e.GeographicLocation;
                        Coordinate c2 = _coordinates[_coordinates.Count - 1];
                        double dx = Math.Abs(c2.X - c1.X);
                        double dy = Math.Abs(c2.Y - c1.Y);
                        double dist;
                        if (Map.Projection != null)
                        {
                            if (Map.Projection.IsLatLon)
                            {
                                double y = (c2.Y + c1.Y) / 2;
                                double factor = Math.Cos(y * Math.PI / 180);
                                dx *= factor;
                                dist = Math.Sqrt(dx * dx + dy * dy);
                                dist = dist * 111319.5;
                            }
                            else
                            {
                                dist = Math.Sqrt(dx * dx + dy * dy);
                                dist *= Map.Projection.Unit.Meters;
                            }
                        }
                        else
                        {
                            dist = Math.Sqrt(dx * dx + dy * dy);
                        }
                        _measureDialog.Distance = dist;
                        _measureDialog.TotalDistance = _previousDistance + dist;
                        _previousDistance += dist;
                    }

                    System.Drawing.Point p1 = Map.ProjToPixel(_coordinates[_coordinates.Count - 1]);
                    System.Drawing.Point p2 = e.Location;
                    Rectangle invalid = Global.GetRectangle(p1, p2);
                    invalid.Inflate(20, 20);
                    Map.Invalidate(invalid);
                }
                _coordinates.Add(e.GeographicLocation);
            }
            
            base.OnMouseUp(e);
        }
예제 #12
0
        /// <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 == MeasureModes.Distance)
            {
                Coordinate c2 = _coordinates[_coordinates.Count-1];
                double dx = Math.Abs(c2.X - c1.X);
                double dy = Math.Abs(c2.Y - c1.Y);
                double dist;
                if(Map.Projection != null)
                {
                    if(Map.Projection.IsLatLon)
                    {
                        double y = (c2.Y + c1.Y) / 2;
                        double factor = Math.Cos(y * Math.PI / 180);
                        dx *= factor;
                        dist = Math.Sqrt(dx*dx + dy*dy);
                        dist = dist * 111319.5;
                    }
                    else
                    {
                        dist = Math.Sqrt(dx * dx + dy * dy);
                        dist *= Map.Projection.Unit.Meters;
                    }
                }
                else
                {

                    dist = Math.Sqrt(dx * dx + dy * dy);
                }

                _measureDialog.Distance = dist;
                _measureDialog.TotalDistance = _previousDistance + dist;
            }
            else
            {
                List<Coordinate> tempPolygon = _coordinates.ToList();
                tempPolygon.Add(c1);
                if (tempPolygon.Count < 3)
                {
                    _measureDialog.Area = 0;
                    _measureDialog.TotalArea = 0;
                    if(tempPolygon.Count == 2)
                    {
                        Rectangle r = Map.ProjToPixel(new LineString(tempPolygon).Envelope);
                        r.Inflate(20,20);
                        Map.Invalidate(r);
                    }
                    _mousePosition = e.Location;
                    return;
                }
                Polygon pg = new Polygon(new LinearRing(tempPolygon));
                double area = pg.Area;
                if (Map.Projection != null)
                {
                    if (Map.Projection.IsLatLon)
                    {
                        area = area * 111319.5 * 111319.5;
                    }
                    else
                    {
                        area *= Map.Projection.Unit.Meters * Map.Projection.Unit.Meters;
                    }
                }
                _measureDialog.Area = area;
                _measureDialog.TotalArea = area;
                Rectangle rr = Map.ProjToPixel(pg.Envelope);
                rr.Inflate(20, 20);
                Map.Invalidate(rr);
                _mousePosition = e.Location;
            }

       
            if (_coordinates != null && _coordinates.Count > 0)
            {
                List<System.Drawing.Point> points = new List<System.Drawing.Point>();
                foreach (Coordinate coord in _coordinates)
                {
                    points.Add(Map.ProjToPixel(coord));
                }
                Rectangle oldRect = Global.GetRectangle(_mousePosition, points[points.Count - 1]);
                Rectangle newRect = Global.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"></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);
        }
 /// <summary>
 /// Handles MouseMove
 /// </summary>
 /// <param name="e"></param>
 protected override void OnMouseMove(GeoMouseArgs e)
 {
     _currentPoint = e.Location;
     Map.Invalidate();
     base.OnMouseMove(e);
 }
 protected override void OnMouseUp(GeoMouseArgs e)
 {
     if(e.Button == MouseButtons.Left && _dragging)
     {
         _dragging = false;
         _featureSet.InvalidateVertices();
         
         if (_featureSet.FeatureType == FeatureTypes.Point || _featureSet.FeatureType == FeatureTypes.MultiPoint)
         {
             if (_activeFeature == null) return;
             if (_layer.GetCategory(_activeFeature) != _selectedCategory)
             {
                 _layer.SetCategory(_activeFeature, _selectedCategory);
                 _layer.SetVisible(_activeFeature, true);
             }
         }
         else
         {
             if (_selectedFeature == null) return;
             if(_layer.GetCategory(_selectedFeature) != _selectedCategory)
             {
                 _layer.SetCategory(_selectedFeature, _selectedCategory);
             }
         }
        
     }
     Map.MapFrame.Initialize();
 }
예제 #16
0
 /// <summary>
 /// fires the MouseDown event
 /// </summary>
 /// <param name="e"></param>
 protected virtual void OnMouseDown(GeoMouseArgs e)
 {
     if (MouseDown == null) return;
     MouseDown(this, e);
 }
예제 #17
0
 /// <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);
 }
예제 #18
0
        ///// <summary>
        ///// 
        ///// </summary>
        ///// <param name="e"></param>
        //protected override void OnDraw(MapDrawArgs e)
        //{
        //    if (_isDragging)
        //    {
        //        Rectangle r = Opp.RectangleFromPoints(_startPoint, _currentPoint);
        //        r.Width -= 1;
        //        r.Height -= 1;
        //        e.Graphics.DrawRectangle(Pens.White, r);
        //        e.Graphics.DrawRectangle(_selectionPen, r);
        //    }
        //    base.OnDraw(e);
        //}

        ///// <summary>
        ///// Handles the MouseDown 
        ///// </summary>
        ///// <param name="e"></param>
        //protected override void OnMouseDown(GeoMouseArgs e)
        //{
        //    _startPoint = e.Location;
        //    _geoStartPoint = e.GeographicLocation;
        //    if (e.Button == MouseButtons.Left)
        //    {
        //        _isDragging = true;
        //    }

            
        //    base.OnMouseDown(e);
        //}

        ///// <summary>
        ///// Handles MouseMove
        ///// </summary>
        ///// <param name="e"></param>
        //protected override void OnMouseMove(GeoMouseArgs e)
        //{
        //    _currentPoint = e.Location;
        //    Map.Invalidate();
        //    base.OnMouseMove(e);
        //}

        /// <summary>
        /// Handles the Mouse Up situation
        /// </summary>
        /// <param name="e"></param>
        protected override void OnMouseUp(GeoMouseArgs e)
        {
            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.Extents = env;
            //            handled = true;
            //        }
            //    }
            //} 
            //_isDragging = false;
            
            //if (handled == false)
            //{
                Rectangle r = e.Map.MapFrame.View;
                int w = r.Width;
                int h = r.Height;

                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();

                //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);
        }
예제 #19
0
 /// <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);
 }
예제 #20
0
        /// <summary>
        /// Handles the mouse move event, changing the viewing extents to match the movements
        /// of the mouse if the lef tmouse button is down.
        /// </summary>
        /// <param name="e"></param>
        protected override void OnMouseMove(GeoMouseArgs e)
        {

            if (_isDragging)
            {
                Point diff = new Point();
                diff.X =  _dragStart.X - e.X;
                diff.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);
        }
예제 #21
0
 /// <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);
 }
예제 #22
0
        /// <summary>
        /// Mouse Up
        /// </summary>
        /// <param name="e"></param>
        protected override void OnMouseUp(GeoMouseArgs e)
        {
            if (e.Button == MouseButtons.Left && _isDragging)
            {
                _isDragging = false;
                //PreventBackBuffer = false;
                Point diff = new Point();
                diff.X = _dragStart.X - e.X;
                diff.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();
                Application.DoEvents();
                _preventDrag = true;
                e.Map.CollectAfterDraw = true;
                //e.Map.MapFrame.View = new Rectangle(_source.X + diff.X, _source.Y + diff.Y, _source.Width, _source.Height); 
                e.Map.MapFrame.Pan(new Point(diff.X, diff.Y));
                _preventDrag = false;
                //e.Map.MapFrame.ResetExtents();
            }

            Map.Invalidate();
            base.OnMouseUp(e);
        }
예제 #23
0
 /// <summary>
 /// Fires the OnMouseUp event on the Active Tools
 /// </summary>
 /// <param name="e"></param>
 protected override void OnMouseUp(MouseEventArgs e)
 {
     GeoMouseArgs args = new GeoMouseArgs(e, this);
     if (_resizing && e.Button == MouseButtons.Left)
     {
         _resizing = false;
         OnResized();
     }
     foreach (IMapFunction tool in _mapFunctions.Values)
     {
         if (tool.Enabled)
         {
             tool.DoMouseUp(args);
             if (args.Handled) break;
         }
     }
     base.OnMouseUp(e);
 }
예제 #24
0
 /// <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);
 }
예제 #25
0
 /// <summary>
 /// updates the auto-filling X and Y coordinates
 /// </summary>
 /// <param name="e"></param>
 protected override void OnMouseMove(GeoMouseArgs e)
 {
     
     if (_standBy) return;
     _coordinateDialog.X = e.GeographicLocation.X;
     _coordinateDialog.Y = e.GeographicLocation.Y;
     if (_coordinates != null && _coordinates.Count > 0)
     {
         List<System.Drawing.Point> points = new List<System.Drawing.Point>();
         foreach (Coordinate coord in _coordinates)
         {
             points.Add(Map.ProjToPixel(coord));
         }
         Rectangle oldRect = Global.GetRectangle(_mousePosition, points[points.Count - 1]);
         Rectangle newRect = Global.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);
 }
예제 #26
0
 /// <summary>
 /// Fires the DoubleClick event
 /// </summary>
 /// <param name="e"></param>
 protected virtual void OnMouseDoubleClick(GeoMouseArgs e)
 {
     if (MouseDoubleClick == null) return;
     MouseDoubleClick(this, e);
 }
예제 #27
0
        /// <summary>
        /// Handles the Mouse Up situation
        /// </summary>
        /// <param name="e"></param>
        protected override void OnMouseUp(GeoMouseArgs e)
        {
            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.Extents.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 System.Drawing.Point(e.X - 4, e.Y - 4));
                Coordinate c2 = e.Map.PixelToProj(new System.Drawing.Point(e.X + 4, e.Y + 4));
                tolerant = new Envelope(c1, c2);
            }

            Map.MapFrame.SuspendEvents();
            HandleSelection(tolerant, env);
            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);
        }
예제 #28
0
 /// <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);
 }
예제 #29
0
 /// <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>
        /// This function checks to see if the current mouse location is over a vertex.
        /// </summary>
        /// <param name="e"></param>
        private bool CheckForVertexDrag(GeoMouseArgs e)
        {
            Rectangle mouseRect = new Rectangle(_mousePosition.X - 3, _mousePosition.Y - 3, 6, 6);
            IEnvelope env = Map.PixelToProj(mouseRect);
            if (e.Button == MouseButtons.Left)
            {

                if (_layer.DataSet.FeatureType == FeatureTypes.Polygon)
                {
                    for (int prt = 0; prt < _selectedFeature.NumGeometries; prt++)
                    {
                        IBasicGeometry g = _selectedFeature.GetBasicGeometryN(prt);
                        IList<Coordinate> coords = g.Coordinates;
                        for (int ic = 0; ic < coords.Count; ic++)
                        {
                            Coordinate c = coords[ic];
                            if (env.Contains(c))
                            {
                                _dragging = true;
                                _dragCoord = c;
                                if (ic == 0)
                                {
                                    _closedCircleCoord = coords[coords.Count - 1];
                                    _previousPoint = coords[coords.Count - 2];
                                    _nextPoint = coords[1];
                                }
                                else if (ic == coords.Count - 1)
                                {
                                    _closedCircleCoord = coords[0];
                                    _previousPoint = coords[coords.Count - 2];
                                    _nextPoint = coords[1];
                                }
                                else
                                {
                                    _previousPoint = coords[ic - 1];
                                    _nextPoint = coords[ic + 1];
                                    _closedCircleCoord = null;
                                }
                                Map.Invalidate();
                                return true;
                            }
                        }

                    }
                }
                else if (_layer.DataSet.FeatureType == FeatureTypes.Line)
                {
                    for (int prt = 0; prt < _selectedFeature.NumGeometries; prt++)
                    {
                        IBasicGeometry g = _selectedFeature.GetBasicGeometryN(prt);
                        IList<Coordinate> coords = g.Coordinates;
                        for (int ic = 0; ic < coords.Count; ic++)
                        {
                            Coordinate c = coords[ic];
                            if (env.Contains(c))
                            {
                                _dragging = true;
                                _dragCoord = c;


                                if (ic == 0)
                                {
                                    _previousPoint = null;
                                    _nextPoint = coords[1];
                                }
                                else if (ic == coords.Count - 1)
                                {
                                    _previousPoint = coords[coords.Count - 2];
                                    _nextPoint = null;
                                }
                                else
                                {
                                    _previousPoint = coords[ic - 1];
                                    _nextPoint = coords[ic + 1];
                                }
                                Map.Invalidate();
                                return true;
                            }
                        }

                    }
                }
                
                //else foreach (Coordinate c in _selectedFeature.Coordinates)
                //{
                //    if (env.Contains(c))
                //    {
                //        _dragging = true;
                //        _dragCoord = c;
                //        Map.Invalidate();
                //        return;
                //    }
                //}
            }
            return false;
        }