예제 #1
0
        public override void TouchesMoved(NSSet touches, UIEvent evt)
        {
            base.TouchesMoved(touches, evt);

            if (touches.Count == 1)
            {
                var touch = touches.AnyObject as UITouch;
                if (touch != null)
                {
                    var currentPos  = touch.LocationInView(this);
                    var previousPos = touch.PreviousLocationInView(this);

                    var cRect = new CGRect(new CGPoint((int)currentPos.X, (int)currentPos.Y), new CGSize(5, 5));
                    var pRect = new CGRect(new CGPoint((int)previousPos.X, (int)previousPos.Y), new CGSize(5, 5));

                    if (!cRect.IntersectsWith(pRect))
                    {
                        if (_previousTouchCount == touches.Count)
                        {
                            _map.Viewport.Transform(currentPos.X, currentPos.Y, previousPos.X, previousPos.Y);
                            RefreshGraphics();
                        }
                    }
                }
            }
            else if (touches.Count == 2)
            {
                nfloat centerX = 0;
                nfloat centerY = 0;

                var locations = touches.Select(t => ((UITouch)t).LocationInView(this)).ToList();

                foreach (var location in locations)
                {
                    centerX += location.X;
                    centerY += location.Y;
                }

                centerX = centerX / touches.Count;
                centerY = centerY / touches.Count;

                var radius   = Algorithms.Distance(centerX, centerY, locations [0].X, locations [0].Y);
                var rotation = Math.Atan2(locations [1].Y - locations [0].Y, locations [1].X - locations [0].X) * 180.0 / Math.PI;

                if (_previousTouchCount == touches.Count)
                {
                    _map.Viewport.Transform(centerX, centerY, _previousX, _previousY, radius / _previousRadius);
                    _map.Viewport.Rotation += rotation - _previousRotation;
                    RefreshGraphics();
                }

                _previousX        = centerX;
                _previousY        = centerY;
                _previousRadius   = radius;
                _previousRotation = rotation;
            }
            _previousTouchCount = touches.Count;
        }
예제 #2
0
 public override void TouchesBegan(NSSet touches, UIEvent evt)
 {
     if (touches.Count == 2)
     {
         var locations = touches.Select(t => ((UITouch)t).LocationInView(this)).ToList();
         _previousRotation = GetRotation(locations);
         _innerRotation    = _map.Viewport.Rotation;
     }
     _touchDown = GetScreenPosition(touches);
     base.TouchesBegan(touches, evt);
 }
예제 #3
0
        public override void TouchesMoved(NSSet touches, UIEvent evt)
        {
            base.TouchesMoved(touches, evt);

            if (touches.Count == 1)
            {
                if (touches.AnyObject is UITouch touch)
                {
                    var currentPos  = touch.LocationInView(this);
                    var previousPos = touch.PreviousLocationInView(this);

                    var cRect = new CGRect(new CGPoint((int)currentPos.X, (int)currentPos.Y), new CGSize(5, 5));
                    var pRect = new CGRect(new CGPoint((int)previousPos.X, (int)previousPos.Y), new CGSize(5, 5));

                    if (!cRect.IntersectsWith(pRect))
                    {
                        if (_previousTouchCount == touches.Count)
                        {
                            _map.Viewport.Transform(currentPos.X, currentPos.Y, previousPos.X, previousPos.Y);
                            RefreshGraphics();
                        }
                    }
                }
            }
            else if (touches.Count == 2)
            {
                nfloat centerX = 0;
                nfloat centerY = 0;

                var locations = touches.Select(t => ((UITouch)t).LocationInView(this)).ToList();

                foreach (var location in locations)
                {
                    centerX += location.X;
                    centerY += location.Y;
                }

                centerX = centerX / touches.Count;
                centerY = centerY / touches.Count;

                var radius = Algorithms.Distance(centerX, centerY, locations[0].X, locations[0].Y);

                if (_previousTouchCount == touches.Count)
                {
                    _map.Viewport.Transform(centerX, centerY, _previousX, _previousY, radius / _previousRadius);

                    if (AllowPinchRotation)
                    {
                        var rotation = GetRotation(locations);

                        _innerRotation += rotation - _previousRotation;
                        _innerRotation %= 360;

                        if (_innerRotation > 180)
                        {
                            _innerRotation -= 360;
                        }
                        else if (_innerRotation < -180)
                        {
                            _innerRotation += 360;
                        }

                        if (_map.Viewport.Rotation == 0 && Math.Abs(_innerRotation) >= Math.Abs(UnSnapRotationDegrees))
                        {
                            _map.Viewport.Rotation = _innerRotation;
                        }
                        else if (_map.Viewport.Rotation != 0)
                        {
                            if (Math.Abs(_innerRotation) <= Math.Abs(ReSnapRotationDegrees))
                            {
                                _map.Viewport.Rotation = 0;
                            }
                            else
                            {
                                _map.Viewport.Rotation = _innerRotation;
                            }
                        }

                        _previousRotation = rotation;
                    }

                    RefreshGraphics();
                }

                _previousX      = centerX;
                _previousY      = centerY;
                _previousRadius = radius;
            }
            _previousTouchCount = touches.Count;
        }