当前位置: 首页>>代码示例>>C#>>正文


C# View2D.CreateFromViewPort方法代码示例

本文整理汇总了C#中OsmSharp.UI.Renderer.View2D.CreateFromViewPort方法的典型用法代码示例。如果您正苦于以下问题:C# View2D.CreateFromViewPort方法的具体用法?C# View2D.CreateFromViewPort怎么用?C# View2D.CreateFromViewPort使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在OsmSharp.UI.Renderer.View2D的用法示例。


在下文中一共展示了View2D.CreateFromViewPort方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: EnsureViewWithinBoundingBox

        /// <summary>
        /// Utility method for ensuring a view stays within a bounding box of geo coordinated.
        /// </summary>
        /// <param name="center">The map center we want to move to.</param>
        /// <param name="boundingBox">A GeoCoordinateBox defining the bounding box.</param>
        /// <param name="view" The current view.</param>
        /// <returns>Returns a center geo coordinate that is corrected so the view stays within the bounding box.</returns>
        public GeoCoordinate EnsureViewWithinBoundingBox(GeoCoordinate center, GeoCoordinateBox boundingBox, View2D view)
        {
            double[] mapCenterSceneCoords = this.Projection.ToPixel(center);

            var toViewPort = view.CreateToViewPort(view.Width, view.Height);
            double mapCenterPixelsX, mapCenterPixelsY;
            toViewPort.Apply(mapCenterSceneCoords[0], mapCenterSceneCoords[1], out mapCenterPixelsX, out mapCenterPixelsY);

            //double[] mapCenterPixels = view.ToViewPort(view.Width, view.Height, mapCenterSceneCoords[0], mapCenterSceneCoords[1]);

            var fromViewPort = view.CreateFromViewPort(view.Height, view.Width);
            double leftScene, topScene, rightScene, bottomScene;
            fromViewPort.Apply(mapCenterPixelsX - (view.Width) / 2.0, mapCenterPixelsY - (view.Height) / 2.0, out leftScene, out topScene);

            //double[] topLeftSceneCoordinates = view.FromViewPort(view.Width,
            //                                                    view.Height,
            //                                                    mapCenterPixels[0] - (view.Width) / 2.0,
            //                                                    mapCenterPixels[1] - (view.Height) / 2.0);
            GeoCoordinate topLeft = this.Projection.ToGeoCoordinates(leftScene, topScene);
            //GeoCoordinate topLeft = this.Projection.ToGeoCoordinates(topLeftSceneCoordinates[0], topLeftSceneCoordinates[1]);

            fromViewPort.Apply(mapCenterPixelsX + (view.Width) / 2.0, mapCenterPixelsY + (view.Height) / 2.0, out rightScene, out bottomScene);
            //double[] bottomRightSceneCoordinates = view.FromViewPort(view.Width,
            //                                                    view.Height,
            //                                                    mapCenterPixels[0] + (view.Width) / 2.0,
            //                                                    mapCenterPixels[1] + (view.Height) / 2.0);
            GeoCoordinate bottomRight = this.Projection.ToGeoCoordinates(rightScene, bottomScene);

            // Early exit when the view is inside the box.
            if (boundingBox.Contains(topLeft) && boundingBox.Contains(bottomRight))
                return center;

            double viewNorth = topLeft.Latitude;
            double viewEast = bottomRight.Longitude;
            double viewSouth = bottomRight.Latitude;
            double viewWest = topLeft.Longitude;

            double boxNorth = boundingBox.MaxLat;
            double boxEast = boundingBox.MaxLon;
            double boxSouth = boundingBox.MinLat;
            double boxWest = boundingBox.MinLon;

            //TODO: Check if the view acrually fits the bounding box, if not resize the view.

            // Correct all view bounds if neccecary.
            if (viewNorth > boxNorth)
            {
                viewSouth -= viewNorth - boxNorth;
                viewNorth = boxNorth;
            }
            if (viewEast > boxEast)
            {
                viewWest -= viewEast - boxEast;
                viewEast = boxEast;
            }
            if (viewSouth < boxSouth)
            {
                viewNorth += boxSouth - viewSouth;
                viewSouth = boxSouth;
            }
            if (viewWest < boxWest)
            {
                viewEast += boxWest - viewWest;
                viewWest = boxWest;
            }

            // Compute and return corrected map center
            return new GeoCoordinate(viewSouth + (viewNorth - viewSouth) / 2.0f, viewWest + (viewEast - viewWest) / 2.0f);
        }
开发者ID:kochizufan,项目名称:OsmSharp,代码行数:76,代码来源:Map.cs


注:本文中的OsmSharp.UI.Renderer.View2D.CreateFromViewPort方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。