예제 #1
0
        /// <summary>
        /// Rotate the specified rotation.
        /// </summary>
        /// <param name="rotation">Rotation.</param>
        private void Rotate(UIRotationGestureRecognizer rotation)
        {
            RectangleF rect = this.Frame;

            if (this.MapAllowTilt &&
                rect.Width > 0)
            {
                this.StopCurrentAnimation();
                if (rotation.State == UIGestureRecognizerState.Ended)
                {
                    this.NotifyMovementByInvoke();;

                    _mapViewBefore = null;
                }
                else if (rotation.State == UIGestureRecognizerState.Began)
                {
                    _mapViewBefore = this.CreateView(rect);
                }
                else
                {
                    //_mapViewBefore = this.CreateView (_rect);
                    View2D rotatedView = _mapViewBefore.RotateAroundCenter((Radian)rotation.Rotation);
                    _mapTilt = (float)((Degree)rotatedView.Rectangle.Angle).Value;
                    PointF2D sceneCenter = rotatedView.Rectangle.Center;
                    _mapCenter = this.Map.Projection.ToGeoCoordinates(
                        sceneCenter[0], sceneCenter[1]);

                    this.NotifyMovementByInvoke();
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Raises the touch event.
        /// </summary>
        /// <param name="v">V.</param>
        /// <param name="e">E.</param>
        public bool OnTouch(global::Android.Views.View v, MotionEvent e)
        {
            _tagGestureDetector.OnTouchEvent(e);
            _scaleGestureDetector.OnTouchEvent(e);
            _rotateGestureDetector.OnTouchEvent(e);
            _moveGestureDetector.OnTouchEvent(e);

            if (_deltaX != 0 || _deltaY != 0 ||       // was there movement?
                _deltaScale != 1.0 ||                 // was there scale?
                _deltaDegrees != 0)                   // was there rotation?
            {
                if (_deltaScale != 1.0)
                {
                    // calculate the scale.
                    double zoomFactor = this.Map.Projection.ToZoomFactor(this.MapZoom);
                    zoomFactor   = zoomFactor * _deltaScale;
                    this.MapZoom = (float)this.Map.Projection.ToZoomLevel(zoomFactor);
                }

                // stop the animation.
                this.StopCurrentAnimation();

                //OsmSharp.Logging.Log.TraceEvent("OsmSharp.Android.UI.MapView", System.Diagnostics.TraceEventType.Information,
                //    string.Format("OnTouch:[{0},{1}] {2}s {3}d", _deltaX, _deltaY, _deltaScale, _deltaDegrees));

                // recreate the view.
                View2D view = this.CreateView();

                // calculate the new center in pixels.
                double centerXPixels = this.Width / 2.0f - _deltaX;
                double centerYPixles = this.Height / 2.0f - _deltaY;

                // calculate the new center from the view.
                double[] sceneCenter = view.FromViewPort(this.Width, this.Height,
                                                         centerXPixels, centerYPixles);

                // convert to the projected center.
                this.MapCenter = this.Map.Projection.ToGeoCoordinates(sceneCenter [0], sceneCenter [1]);

                // do the rotation stuff around the new center.
                if (_deltaDegrees != 0)
                {
                    View2D rotatedView = view.RotateAroundCenter((Degree)(-_deltaDegrees));
                    _mapTilt = (float)((Degree)rotatedView.Rectangle.Angle).Value;
                }

                _deltaScale   = 1;
                _deltaDegrees = 0;
                _deltaX       = 0;
                _deltaY       = 0;

                // notify touch.
                _mapView.RaiseMapTouched();

                this.NotifyMovement();
            }
            return(true);
        }
예제 #3
0
파일: MapView.cs 프로젝트: jboneng/OsmSharp
        /// <summary>
        /// Rotate the specified rotation.
        /// </summary>
        /// <param name="rotation">Rotation.</param>
        private void Rotate(UIRotationGestureRecognizer rotation)
        {
            //RectangleF2D rect = _rect;
            RectangleF rect = this.Frame;

            if (rect.Width > 0)
            {
                this.StopCurrentAnimation();
                if (rotation.State == UIGestureRecognizerState.Ended)
                {
                    View2D rotatedView = _mapViewBefore.RotateAroundCenter((Radian)rotation.Rotation);
                    _mapTilt = (float)((Degree)rotatedView.Rectangle.Angle).Value;
                    PointF2D sceneCenter = rotatedView.Rectangle.Center;
                    _mapCenter = this.Map.Projection.ToGeoCoordinates(
                        sceneCenter [0], sceneCenter [1]);
                    this.Change(true);

                    _mapViewBefore = null;
                }
                else if (rotation.State == UIGestureRecognizerState.Began)
                {
                    _mapViewBefore = this.CreateView(rect);
                }
                else
                {
                    //_mapViewBefore = this.CreateView (_rect);
                    View2D rotatedView = _mapViewBefore.RotateAroundCenter((Radian)rotation.Rotation);
                    _mapTilt = (float)((Degree)rotatedView.Rectangle.Angle).Value;
                    PointF2D sceneCenter = rotatedView.Rectangle.Center;
                    _mapCenter = this.Map.Projection.ToGeoCoordinates(
                        sceneCenter [0], sceneCenter [1]);

                    this.InvokeOnMainThread(InvalidateMap);
                }
            }
        }
예제 #4
0
        /// <summary>
        /// Raises the touch event.
        /// </summary>
        /// <param name="v">V.</param>
        /// <param name="e">E.</param>
        public bool OnTouch(global::Android.Views.View v, MotionEvent e)
        {
            try
            {
                if (!_renderingSuspended && this.Map != null && this.Map.Projection != null && this.MapCenter != null)
                {
                    _tagGestureDetector.OnTouchEvent(e);
                    _scaleGestureDetector.OnTouchEvent(e);
                    _rotateGestureDetector.OnTouchEvent(e);
                    _moveGestureDetector.OnTouchEvent(e);

                    if (_deltaX != 0 || _deltaY != 0 || // was there movement?
                        _deltaScale != 1.0 ||           // was there scale?
                        _deltaDegrees != 0)
                    {                                   // was there rotation?
                        bool movement = false;
                        if (this.MapAllowZoom &&
                            _deltaScale != 1.0)
                        {
                            // calculate the scale.
                            double zoomFactor = this.Map.Projection.ToZoomFactor(this.MapZoom);
                            zoomFactor   = zoomFactor * _deltaScale;
                            this.MapZoom = (float)this.Map.Projection.ToZoomLevel(zoomFactor);

                            movement = true;
                        }

                        if (this.MapAllowPan)
                        {
                            // stop the animation.
                            this.StopCurrentAnimation();

                            // recreate the view.
                            View2D view = this.CreateView();

                            // calculate the new center in pixels.
                            double centerXPixels = this.SurfaceWidth / 2.0f - _deltaX;
                            double centerYPixles = this.SurfaceHeight / 2.0f - _deltaY;

                            // calculate the new center from the view.
                            double[] sceneCenter = view.FromViewPort(this.SurfaceWidth, this.SurfaceHeight,
                                                                     centerXPixels, centerYPixles);

                            // convert to the projected center.
                            this.MapCenter = this.Map.Projection.ToGeoCoordinates(sceneCenter[0], sceneCenter[1]);

                            movement = true;
                        }

                        // do the rotation stuff around the new center.
                        if (this.MapAllowTilt &&
                            _deltaDegrees != 0)
                        {
                            // recreate the view.
                            View2D view = this.CreateView();

                            View2D rotatedView = view.RotateAroundCenter((Degree)(-_deltaDegrees));
                            _mapTilt = (float)((Degree)rotatedView.Rectangle.Angle).Value;

                            movement = true;
                        }

                        _deltaScale   = 1;
                        _deltaDegrees = 0;
                        _deltaX       = 0;
                        _deltaY       = 0;

                        // notify touch.
                        if (movement)
                        {
                            _mapView.RaiseMapTouched();

                            this.NotifyMovement();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                OsmSharp.Logging.Log.TraceEvent("MapViewSurface.OnTouch", TraceEventType.Critical,
                                                string.Format("An unhandled exception occured:{0}", ex.ToString()));
            }
            return(true);
        }