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