SuperMap.WindowsPhone.Mapping.Map.beginZoomToTargetBounds C# (CSharp) Method

beginZoomToTargetBounds() private method

private beginZoomToTargetBounds ( Rectangle2D targetBounds, bool skipAnimation ) : void
targetBounds SuperMap.WindowsPhone.Core.Rectangle2D
skipAnimation bool
return void
        private void beginZoomToTargetBounds(Rectangle2D targetBounds, bool skipAnimation)
        {
            if (this.Layers == null)
            {
                return;
            }
            Rectangle2D startBounds = this.ViewBounds;
            if (Rectangle2D.IsNullOrEmpty(this.previousViewBounds))
            {
                this.previousViewBounds = startBounds;
            }

            double startResolution = this.mapResolution;
            if (((targetBounds.Width != 0.0) || (targetBounds.Height != 0.0)) && (!Rectangle2D.IsNullOrEmpty(targetBounds)))
            {
                //this.targetResolution = this.ClipResolution(Math.Max((double)(targetBounds.Width / viewSize.Width), (double)(targetBounds.Height / viewSize.Height)));
                this.targetResolution = Math.Max((double)(targetBounds.Width / currentSize.Width), (double)(targetBounds.Height / currentSize.Height));
                this.targetResolution = MathUtil.MinMaxCheck(targetResolution, MinResolution, MaxResolution);
                Point2D startOrigin = new Point2D(startBounds.Left, startBounds.Top);
                Point2D center = targetBounds.Center;
                if ((base.ActualHeight == 0.0) || (base.ActualWidth == 0.0))
                {
                    skipAnimation = true;
                }

                Point2D targetOrigin = new Point2D(targetBounds.Left, targetBounds.Top);

                this.Popup.IsOpen = false;

                if (this.CurrentZoomAnimationHandler != null)
                {
                    CompositionTarget.Rendering -= this.CurrentZoomAnimationHandler;
                    this.CurrentZoomAnimationHandler = null;
                }

                skipAnimation = skipAnimation || (this.ZoomDuration.Ticks == 0L);
                if (skipAnimation)
                {
                    this.panHelper.ResetTranslate();
                    this.SetOriginAndResolution(this.targetResolution, targetOrigin, true);
                }
                else
                {
                    TimeSpan? startTime = null;
                    bool resetPan = false;
                    this.CurrentZoomAnimationHandler = delegate(object s, EventArgs e)
                    {
                        RenderingEventArgs args = (RenderingEventArgs)e;
                        if (!startTime.HasValue)
                        {
                            startTime = new TimeSpan?(args.RenderingTime);
                        }
                        else
                        {
                            double t = args.RenderingTime.TotalMilliseconds - startTime.Value.TotalMilliseconds;
                            double totalMilliseconds = this.ZoomDuration.TotalMilliseconds;
                            double num3 = QuinticEaseOut(t, 0.0, 1.0, totalMilliseconds);//动画
                            this.mapResolution = ((this.targetResolution - startResolution) * num3) + startResolution;
                            Point2D currentOrigin = new Point2D(((targetOrigin.X - startOrigin.X) * num3) + startOrigin.X, ((targetOrigin.Y - startOrigin.Y) * num3) + startOrigin.Y);
                            if (t >= totalMilliseconds)
                            {
                                CompositionTarget.Rendering -= this.CurrentZoomAnimationHandler;
                                this.CurrentZoomAnimationHandler = null;
                                currentOrigin = targetOrigin;
                                this.mapResolution = this.targetResolution;

                                this.Dispatcher.BeginInvoke(delegate
                                {
                                    this.SetOriginAndResolution(this.mapResolution, currentOrigin, true);
                                    Rectangle2D rect = this.GetFullViewBounds();
                                    if (Rectangle2D.IsNullOrEmpty(rect))
                                    {
                                        this.LoadLayersInView(false, targetBounds);
                                    }
                                    else
                                    {
                                        this.LoadLayersInView(targetBounds.IntersectsWith(rect), rect);
                                    }
                                    this.RaiseViewBoundsChanged();
                                });
                            }
                            else
                            {
                                if (!resetPan)
                                {
                                    this.panHelper.ResetTranslate();
                                    resetPan = true;
                                }
                                this.SetOriginAndResolution(this.mapResolution, currentOrigin, false);
                                if (this.ViewBoundsChanging != null)
                                {
                                    this.ViewBoundsChanging(this, new ViewBoundsEventArgs(startBounds, this.ViewBounds));
                                }
                            }
                        }
                    };

                    CompositionTarget.Rendering += this.CurrentZoomAnimationHandler;
                }
                foreach (Layer layer in this.Layers)
                {
                    if ((layer.Container != null) && !(layer is TiledLayer))
                    {
                        layer.Container.MarkOutdated(!skipAnimation);
                    }
                }

                if (this.mapResizeThrottler != null)
                {
                    this.mapResizeThrottler.Cancel();
                }
                if (skipAnimation)
                {
                    this.LoadLayersInView(false, targetBounds);
                    this.RaiseViewBoundsChanged();
                }
            }
        }