示例#1
0
 /// <summary>
 /// Navigate to a resolution, so such the map uses the fill method
 /// </summary>
 /// <param name="scaleMethod">Scale method to use to determine resolution</param>
 /// <param name="duration">Duration for animation in milliseconds.</param>
 /// <param name="easing">The type of easing function used to transform from begin tot end state</param>
 public void NavigateToFullEnvelope(ScaleMethod scaleMethod = ScaleMethod.Fill, long duration = -1, Easing?easing = default)
 {
     if (_map.Extent != null)
     {
         NavigateTo(_map.Extent, scaleMethod, duration, easing);
     }
 }
示例#2
0
        /// <summary>
        /// Scales an image size, preserving aspect ratio.
        /// </summary>
        /// <param name="sourceSize"></param>
        /// <param name="width">Min or max allowed width. Min/Max controlled by the method parameter</param>
        /// <param name="height">Min or max allowed height. Min/Max controlled by the method parameter</param>
        /// <param name="method"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        public static Size Scale(this Size sourceSize, int width, int height, ScaleMethod method, ScaleType type)
        {
            if (type == ScaleType.Expand && sourceSize.Height > height && sourceSize.Width > width)
            {
                return(sourceSize);
            }

            if (type == ScaleType.Shrink && sourceSize.Height < height && sourceSize.Width < width)
            {
                return(sourceSize);
            }

            if (height == 0)
            {
                height = sourceSize.Height;
            }

            if (width == 0)
            {
                width = sourceSize.Width;
            }

            // calculate the two possible scaling factors
            var wAr = (float)width / sourceSize.Width;
            var hAr = (float)height / sourceSize.Height;

            // pick the scaling factor based on the scale method
            var ar = method == ScaleMethod.ToFit ? Math.Min(wAr, hAr) : Math.Max(wAr, hAr);

            return(sourceSize.Scale(ar));
        }
示例#3
0
 /// <summary>
 /// Navigate center of viewport to center of extent and change resolution
 /// </summary>
 /// <param name="extent">New extent for viewport to show</param>
 /// <param name="scaleMethod">Scale method to use to determin resolution</param>
 public void NavigateTo(BoundingBox extent, ScaleMethod scaleMethod = ScaleMethod.Fit)
 {
     Viewport.Resolution = ZoomHelper.DetermineResolution(
         extent.Width, extent.Height, Viewport.Width, Viewport.Height, scaleMethod);
     Viewport.Center = extent.Centroid;
     OnRefreshGraphics();
     RefreshData(true);
 }
示例#4
0
 /// <summary>
 /// Navigate center of viewport to center of extent and change resolution
 /// </summary>
 /// <param name="extent">New extent for viewport to show</param>
 /// <param name="scaleMethod">Scale method to use to determin resolution</param>
 public void NavigateTo(BoundingBox extent, ScaleMethod scaleMethod = ScaleMethod.Fit)
 {
     if (extent == null)
     {
         return;
     }
     _viewport.SetResolution(ZoomHelper.DetermineResolution(
                                 extent.Width, extent.Height, _viewport.Width, _viewport.Height, scaleMethod));
     _viewport.SetCenter(extent.Centroid);
     _map.RefreshData(_viewport.Extent, _viewport.Resolution, true);
 }
示例#5
0
        public static void ZoomToBoudingbox(Viewport viewport,
                                            double x1, double y1, double x2, double y2,
                                            double screenWidth, double screenHeight,
                                            ScaleMethod scaleMethod = ScaleMethod.Fit)
        {
            ZoomToBoudingbox(x1, y1, x2, y2, screenWidth, screenHeight,
                             out var centerX, out var centerY, out var resolution, scaleMethod);

            viewport.SetCenter(centerX, centerY);

            viewport.Resolution = resolution;
        }
示例#6
0
        /// <summary>
        /// Navigate center of viewport to center of extent and change resolution
        /// </summary>
        /// <param name="extent">New extent for viewport to show</param>
        /// <param name="scaleMethod">Scale method to use to determine resolution</param>
        /// <param name="duration">Duration of animation in millisecondsScale method to use to determine resolution</param>
        public void NavigateTo(BoundingBox extent, ScaleMethod scaleMethod = ScaleMethod.Fit, long duration = 300)
        {
            if (extent == null)
            {
                return;
            }

            var resolution = ZoomHelper.DetermineResolution(
                extent.Width, extent.Height, _viewport.Width, _viewport.Height, scaleMethod);

            NavigateTo(extent.Centroid, resolution, duration);
        }
示例#7
0
        /// <summary>
        /// Navigate center of viewport to center of extent and change resolution
        /// </summary>
        /// <param name="extent">New extent for viewport to show</param>
        /// <param name="scaleMethod">Scale method to use to determine resolution</param>
        /// <param name="duration">Duration for animation in milliseconds.</param>
        /// <param name="easing">The type of easing function used to transform from begin tot end state</param>
        public void NavigateTo(MRect?extent, ScaleMethod scaleMethod = ScaleMethod.Fit, long duration = -1, Easing?easing = default)
        {
            if (extent == null)
            {
                return;
            }

            var resolution = ZoomHelper.DetermineResolution(
                extent.Width, extent.Height, _viewport.Width, _viewport.Height, scaleMethod);

            NavigateTo(extent.Centroid, resolution, duration, easing);
        }
示例#8
0
        /// <summary>
        /// Navigate center of viewport to center of extent and change resolution
        /// </summary>
        /// <param name="extent">New extent for viewport to show</param>
        /// <param name="scaleMethod">Scale method to use to determine resolution</param>
        public void NavigateTo(BoundingBox extent, ScaleMethod scaleMethod = ScaleMethod.Fit)
        {
            if (extent == null)
            {
                return;
            }

            var resolution = ZoomHelper.DetermineResolution(
                extent.Width, extent.Height, _viewport.Width, _viewport.Height, scaleMethod);

            _viewport.SetResolution(resolution);

            _viewport.SetCenter(extent.Centroid);

            Navigated?.Invoke(this, EventArgs.Empty);
        }
示例#9
0
        public static void ZoomToBoudingbox(Viewport viewport,
                                            double x1, double y1, double x2, double y2,
                                            double screenWidth, double screenHeight,
                                            ScaleMethod scaleMethod = ScaleMethod.Fit)
        {
            double centerX;
            double centerY;
            double resolution;

            ZoomToBoudingbox(x1, y1, x2, y2, screenWidth, screenHeight,
                             out centerX, out centerY, out resolution, scaleMethod);

            viewport.Center.X = centerX;
            viewport.Center.Y = centerY;

            viewport.Resolution = resolution;
        }
示例#10
0
    public Vector3 RandomScale(Vector3 scale, float min, float max, ScaleMethod method = ScaleMethod.None)
    {
        switch (method)
        {
        case ScaleMethod.None:
            return(scale);

        case ScaleMethod.Equal:
            var equalScale = Random.Range(min, max);
            return(new Vector3(equalScale, equalScale, equalScale));

        case ScaleMethod.Random:
            return(RandomVector(min, max));

        default:
            return(scale);
        }
    }
示例#11
0
        public static double DetermineResolution(double worldWidth, double worldHeight, double screenWidth, double screenHeight, ScaleMethod scaleMethod = ScaleMethod.Fit)
        {
            double widthResolution = worldWidth / screenWidth;
            double heightResolution = worldHeight/screenHeight;

            switch (scaleMethod)
            {
                case ScaleMethod.FitHeight:
                    return heightResolution;
                case ScaleMethod.FitWidth:
                    return widthResolution;
                case ScaleMethod.Fill:
                    return Math.Min(widthResolution, heightResolution);
                case ScaleMethod.Fit:
                    return Math.Max(widthResolution, heightResolution);
                default:
                    throw new Exception("ScaleMethod not supported");
            }
        }
示例#12
0
        public static void ZoomToBoudingbox(double x1, double y1, double x2, double y2,
                                            double screenWidth, double screenHeight,
                                            out double x, out double y, out double resolution,
                                            ScaleMethod scaleMethod = ScaleMethod.Fit)
        {
            if (x1 > x2)
            {
                Swap(ref x1, ref x2);
            }
            if (y1 > y2)
            {
                Swap(ref y1, ref y2);
            }

            x = (x2 + x1) / 2;
            y = (y2 + y1) / 2;

            if (scaleMethod == ScaleMethod.Fit)
            {
                resolution = Math.Max((x2 - x1) / screenWidth, (y2 - y1) / screenHeight);
            }
            else if (scaleMethod == ScaleMethod.Fill)
            {
                resolution = Math.Min((x2 - x1) / screenWidth, (y2 - y1) / screenHeight);
            }
            else if (scaleMethod == ScaleMethod.FitWidth)
            {
                resolution = (x2 - x1) / screenWidth;
            }
            else if (scaleMethod == ScaleMethod.FitHeight)
            {
                resolution = (y2 - y1) / screenHeight;
            }
            else
            {
                throw new Exception("FillMethod not found");
            }
        }
示例#13
0
        public ProcessImage(ProcessImage original, int width, int height, ScaleMethod scaleMethod = ScaleMethod.Nearest)
            : this(width, height)
        {
            switch (scaleMethod)
            {
            case ScaleMethod.Nearest:
            {
                float widthRatio  = ( float )original.Width / Width;
                float heightRatio = ( float )original.Height / Height;
                Parallel.For(0, Height, (y) =>
                    {
                        for (int x = 0; x < Width; ++x)
                        {
                            colorMap [x, y] = original [( int )(x * widthRatio), ( int )(y * heightRatio)];
                        }
                    });
            }
            break;

            case ScaleMethod.Bilinear:
                throw new NotImplementedException();
            }
        }
示例#14
0
        /// <summary>
        /// Scales an image size, preserving aspect ratio.
        /// </summary>
        /// <param name="sourceSize"></param>
        /// <param name="width">Min or max allowed width. Min/Max controlled by the method parameter</param>
        /// <param name="height">Min or max allowed height. Min/Max controlled by the method parameter</param>
        /// <param name="method"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        public static Size Scale(this Size sourceSize, int width, int height, ScaleMethod method, ScaleType type)
        {
            if (type == ScaleType.Expand && sourceSize.Height > height && sourceSize.Width > width)
                return sourceSize;

            if (type == ScaleType.Shrink && sourceSize.Height < height && sourceSize.Width < width)
                return sourceSize;

            if (height == 0)
                height = sourceSize.Height;

            if (width == 0)
                width = sourceSize.Width;

            // calculate the two possible scaling factors
            var wAr = (float)width / sourceSize.Width;
            var hAr = (float)height / sourceSize.Height;

            // pick the scaling factor based on the scale method
            var ar = method == ScaleMethod.ToFit ? Math.Min(wAr, hAr) : Math.Max(wAr, hAr);

            return sourceSize.Scale(ar);
        }
示例#15
0
        public static double DetermineResolution(double worldWidth, double worldHeight, double screenWidth,
                                                 double screenHeight, ScaleMethod scaleMethod = ScaleMethod.Fit)
        {
            var widthResolution  = worldWidth / screenWidth;
            var heightResolution = worldHeight / screenHeight;

            switch (scaleMethod)
            {
            case ScaleMethod.FitHeight:
                return(heightResolution);

            case ScaleMethod.FitWidth:
                return(widthResolution);

            case ScaleMethod.Fill:
                return(Math.Min(widthResolution, heightResolution));

            case ScaleMethod.Fit:
                return(Math.Max(widthResolution, heightResolution));

            default:
                throw new Exception("ScaleMethod not supported");
            }
        }
示例#16
0
 /// <summary>
 /// Navigate to a resolution, so such the map uses the fill method
 /// </summary>
 /// <param name="scaleMethod"></param>
 /// <param name="duration">Duration of animation in millisecondsScale method to use to determine resolution</param>
 public void NavigateToFullEnvelope(ScaleMethod scaleMethod = ScaleMethod.Fill, long duration = 300)
 {
     NavigateTo(_map.Envelope, scaleMethod, duration);
 }
示例#17
0
 /// <inheritdoc />
 public void NavigateToFullEnvelope(ScaleMethod scaleMethod = ScaleMethod.Fill)
 {
     NavigateTo(_map.Envelope, scaleMethod, 300);
 }
示例#18
0
        public static void ZoomToBoudingbox(double x1, double y1, double x2, double y2,
            double screenWidth, double screenHeight,
            out double x, out double y, out double resolution,
            ScaleMethod scaleMethod = ScaleMethod.Fit)
        {
            if (x1 > x2) Swap(ref x1, ref x2);
            if (y1 > y2) Swap(ref y1, ref y2);

            x = (x2 + x1)/2;
            y = (y2 + y1)/2;

            if (scaleMethod == ScaleMethod.Fit)
                resolution = Math.Max((x2 - x1) / screenWidth, (y2 - y1) / screenHeight);
            else if (scaleMethod == ScaleMethod.Fill)
                resolution = Math.Min((x2 - x1) / screenWidth, (y2 - y1) / screenHeight);
            else if (scaleMethod == ScaleMethod.FitWidth)
                resolution = (x2 - x1) / screenWidth;
            else if (scaleMethod == ScaleMethod.FitHeight)
                resolution = (y2 - y1) / screenHeight;
            else
                throw new Exception("FillMethod not found");
        }
示例#19
0
 /// <inheritdoc />
 public void NavigateTo(BoundingBox extent, ScaleMethod scaleMethod = ScaleMethod.Fit)
 {
     NavigateTo(extent, scaleMethod, 300);
 }
示例#20
0
        public static void ZoomToBoudingbox(Viewport viewport,
            double x1, double y1, double x2, double y2,
            double screenWidth, double screenHeight,
            ScaleMethod scaleMethod = ScaleMethod.Fit)
        {
            double centerX;
            double centerY;
            double resolution;

            ZoomToBoudingbox(x1, y1, x2, y2, screenWidth, screenHeight,
                out centerX, out centerY, out resolution, scaleMethod);

            viewport.Center.X = centerX;
            viewport.Center.Y = centerY;

            viewport.Resolution = resolution;
        }
示例#21
0
        public void NavigateToFullEnvelope(ScaleMethod scaleMethod = ScaleMethod.Fill)
        {
            NavigateTo(_map.Envelope, scaleMethod);

            Navigated?.Invoke(this, EventArgs.Empty);
        }
示例#22
0
        public void NavigateToFullEnvelope(ScaleMethod scaleMethod = ScaleMethod.Fill)
        {
            NavigateTo(_map.Envelope, scaleMethod);

            _map.RefreshData(_viewport.Extent, _viewport.Resolution, true);
        }
    public static Vector2 getSize(float width, float height, float containerWidth, float containerHeight, ScaleMethod method = ScaleMethod.fill, float zoom = 1)
    {
        Vector2 result = new Vector2();

        float newwidth  = 0;
        float newheight = 0;

        if (method == ScaleMethod.fill)
        {
            var factor1 = containerWidth / containerHeight;
            var factor2 = width / height;
            if (factor1 > factor2)
            {
                newwidth  = (containerWidth) * zoom;
                newheight = ((containerWidth / width) * height) * zoom;
            }
            else
            {
                newwidth  = ((containerHeight / height) * width) * zoom;
                newheight = (containerHeight) * zoom;
            }
            result[0] = newwidth;
            result[1] = newheight;
        }

        return(result);
    }
示例#24
0
 /// <summary>
 /// Scales an image <see cref="Size"/>, but only up
 /// </summary>
 /// <param name="sourceSize"></param>
 /// <param name="width"></param>
 /// <param name="height"></param>
 /// <param name="method"></param>
 /// <returns></returns>
 public static Size Expand(this Size sourceSize, int width, int height, ScaleMethod method)
 {
     return sourceSize.Scale(width, height, method, ScaleType.Expand);
 }
示例#25
0
 /// <summary>
 /// Scales an image <see cref="Size"/>, but only down
 /// </summary>
 /// <param name="sourceSize"></param>
 /// <param name="width"></param>
 /// <param name="height"></param>
 /// <param name="method"></param>
 /// <returns></returns>
 public static Size Shrink(this Size sourceSize, int width, int height, ScaleMethod method)
 {
     return sourceSize.Scale(width, height, method, ScaleType.Shrink);
 }
示例#26
0
 /// <summary>
 /// Scales an image <see cref="Size"/>, but only up
 /// </summary>
 /// <param name="sourceSize"></param>
 /// <param name="width"></param>
 /// <param name="height"></param>
 /// <param name="method"></param>
 /// <returns></returns>
 public static Size Expand(this Size sourceSize, int width, int height, ScaleMethod method)
 {
     return(sourceSize.Scale(width, height, method, ScaleType.Expand));
 }
示例#27
0
 /// <summary>
 /// Scales an image <see cref="Size"/>, but only down
 /// </summary>
 /// <param name="sourceSize"></param>
 /// <param name="width"></param>
 /// <param name="height"></param>
 /// <param name="method"></param>
 /// <returns></returns>
 public static Size Shrink(this Size sourceSize, int width, int height, ScaleMethod method)
 {
     return(sourceSize.Scale(width, height, method, ScaleType.Shrink));
 }
示例#28
0
文件: Map.cs 项目: pauldendulk/Mapsui
        public void NavigateTo(BoundingBox extent, ScaleMethod scaleMethod = ScaleMethod.Fit)
        {
            Viewport.Resolution = ZoomHelper.DetermineResolution(
                extent.Width, extent.Height, Viewport.Width, Viewport.Height, scaleMethod);
            Viewport.Center = extent.GetCentroid();

            OnRefreshGraphics();
            ViewChanged(true);
        }