コード例 #1
0
        public static void ZoomMapToRegion(this XamGeographicMap geoMap, GeoRect region, TimeSpan zoomDuration)
        {
            Rect currentWindowRect = geoMap.WindowRect;
            //GeoRegion geodeticGeoRegion = region;
            var winRect = geoMap.GetZoomFromGeographic(region.ToRect());

            //GeoRegion cartesianGeoRegion = ProjectMapRegion(geodeticGeoRegion, map);
            //MapWindowRect = cartesianGeoRegion.ToRect();
            var dTL = geoMap.WindowRect.TopLeft().DistanceVector(winRect.TopLeft());
            var dTR = geoMap.WindowRect.TopRight().DistanceVector(winRect.TopRight());
            var dBR = geoMap.WindowRect.BottomRight().DistanceVector(winRect.BottomRight());
            var dBL = geoMap.WindowRect.BottomLeft().DistanceVector(winRect.BottomLeft());


            var StartTime = DateTime.MinValue;

            //var zoomInterval = zoomDuration.TotalMilliseconds / 2000.0;
            var zoomInterval = zoomDuration.TotalMilliseconds / 2000.0;

            var counter = 0;
            var timer   = new DispatcherTimer {
                Interval = TimeSpan.FromMilliseconds(10)
            };

            timer.Tick += (o, e) =>
            {
                if (StartTime == DateTime.MinValue)
                {
                    StartTime = DateTime.Now;
                }
                double tick     = (DateTime.Now - StartTime).Ticks / TimeSpan.TicksPerMillisecond;
                double duration = zoomDuration.TotalMilliseconds;
                var    factor   = 50.0;
                //TODO add logic for smooth transition between map's window Rect
                //double lin = duration > 1.0 ? MathUtil.Clamp(tick / duration, 0.0, 1.0) : 1.0;
                //var tLog = Math.Log(1.0 + factor * Math.E / (Math.E - 1.0));
                //var trig = 0.5 - 0.5 * Math.Cos(Math.PI * factor);


                //System.Diagnostics.Debug.WriteLine("  log " + tLog + "  tri " + trig);

                var top    = geoMap.WindowRect.Top + (dTL.Y / factor);
                var left   = geoMap.WindowRect.Left + (dTL.X / factor);
                var bottom = geoMap.WindowRect.Bottom + (dBR.Y / factor);
                var right  = geoMap.WindowRect.Right + (dBR.X / factor);

                counter++;
                var rect = new Rect(new Point(left, top), new Point(right, bottom));
                if (counter > factor || winRect.Contains(rect))
                {
                    ((DispatcherTimer)o).Stop();
                }

                geoMap.WindowRect = rect;
            };
            timer.Start();
        }
コード例 #2
0
        public static void ZoomMapToRegion(this XamGeographicMap geoMap, GeoRect region)
        {
            var windowRect = geoMap.GetZoomFromGeographic(region.ToRect());

            geoMap.ZoomMapToWindow(windowRect);
        }