예제 #1
0
        /// <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;
        }