获取地图的视图范围 [英] Get view bounds of a Map

查看:127
本文介绍了获取地图的视图范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发可与Bing Maps一起使用的Windows Phone 8.1应用程序. 在渲染此地图的过程中,我使用TrySetViewBoundsAsync正确设置了我的自定义视图.但是,现在我想获取此信息(在用户通过缩放/移动地图更改视图之后),但是我找不到任何对我有帮助的方法.

I'm developing a Windows Phone 8.1 app that works with Bing Maps. During the rendering of this map I use the TrySetViewBoundsAsync to set correctly my custom view. But now I want to get this information (after the user changes the view by zooming/moving the map) but I don't find any method that helps me.

如何获取视图范围?

推荐答案

虽然没有内置方法,但是可以很容易地完成.这是我从 Microsoft Maps Spatial Toolbox项目中提取的一些代码:

There isn't a built in method for this, however it can be done fairly easily. Here is a bit of code for this which I pulled from the Microsoft Maps Spatial Toolbox project:

public static GeoboundingBox GetBounds(this MapControl map)
{
    Geopoint topLeft = null;

    try
    {
        map.GetLocationFromOffset(new Windows.Foundation.Point(0, 0), out topLeft);
    }
    catch
    {
        var topOfMap = new Geopoint(new BasicGeoposition()
        {
            Latitude = 85,
            Longitude = 0
        });

        Windows.Foundation.Point topPoint;
        map.GetOffsetFromLocation(topOfMap, out topPoint);
        map.GetLocationFromOffset(new Windows.Foundation.Point(0, topPoint.Y), out topLeft);
    }

    Geopoint bottomRight = null;
    try
    {
        map.GetLocationFromOffset(new Windows.Foundation.Point(map.ActualWidth, map.ActualHeight), out bottomRight);
    }
    catch
    {
        var bottomOfMap = new Geopoint(new BasicGeoposition()
        {
            Latitude = -85,
            Longitude = 0
        });

        Windows.Foundation.Point bottomPoint;
        map.GetOffsetFromLocation(bottomOfMap, out bottomPoint);
        map.GetLocationFromOffset(new Windows.Foundation.Point(0, bottomPoint.Y), out bottomRight);
    }

    if (topLeft != null && bottomRight != null)
    {
        return new GeoboundingBox(topLeft.Position, bottomRight.Position);
    }

    return null;
}

这篇关于获取地图的视图范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆