Esempio n. 1
0
        /// <summary>
        /// Starts an animation to the given parameters.
        /// </summary>
        /// <param name="center"></param>
        /// <param name="zoomLevel"></param>
        /// <param name="mapTilt"></param>
        /// <param name="time"></param>
        public void Start(GeoCoordinate center, float zoomLevel, Degree mapTilt, TimeSpan time)
        {
            lock (this)
            {
                // stop the previous timer.
                if (_timer != null)
                { // timer exists.
                  //_mapView.Invalidate();

                    _timer.Stop();
                    _timer.Dispose();
                    _timer = null;
                }
                _timer          = new Timer(_minimumTimeSpan.TotalMilliseconds);
                _timer.Elapsed += new ElapsedEventHandler(_timer_Elapsed);

                // set the targets.
                _targetCenter = center;
                _targetTilt   = mapTilt;
                _targetZoom   = zoomLevel;

                // calculate the animation steps.
                _maxSteps    = (int)System.Math.Round((double)time.TotalMilliseconds / (double)_minimumTimeSpan.TotalMilliseconds, 0);
                _currentStep = 0;
                _stepCenter  = new GeoCoordinate(
                    (_targetCenter.Latitude - _mapView.MapCenter.Latitude) / _maxSteps,
                    (_targetCenter.Longitude - _mapView.MapCenter.Longitude) / _maxSteps);
                _stepZoom = (float)((_targetZoom - _mapView.MapZoom) / _maxSteps);

                // calculate the map tilt, make sure it turns along the smallest corner.
                double diff = _targetTilt.Subtract180(_mapView.MapTilt);
                OsmSharp.Logging.Log.TraceEvent("MapViewAnimator", System.Diagnostics.TraceEventType.Information, diff.ToString());
                _stepTilt = (diff / _maxSteps);

                OsmSharp.Logging.Log.TraceEvent("MapViewAnimator", System.Diagnostics.TraceEventType.Verbose,
                                                string.Format("Started new animation with steps z:{0} t:{1} c:{2} to z:{3} t:{4} c:{5} from z:{6} t:{7} c:{8}.",
                                                              _stepZoom, _stepTilt, _stepCenter.ToString(),
                                                              _targetZoom, _targetTilt, _targetCenter.ToString(),
                                                              _mapView.MapZoom, _mapView.MapTilt, _mapView.MapCenter.ToString()));

                // disable auto invalidate.
                //_mapView.AutoInvalidate = false;
                _mapView.RegisterAnimator(this);

                // start the timer.
                _timer.Enabled = true;
                _timer.Start();
            }
        }