我可以用少量的调整我的兵地图的查看/ LocationRect /包围盒? [英] Can I adjust my Bing Map's View/LocationRect/Bounding Box by a small amount?

查看:340
本文介绍了我可以用少量的调整我的兵地图的查看/ LocationRect /包围盒?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用这个代码:

  photraxMap.SetView(新LocationRect(App.photosetLocationCollection)); 



...放大地图,以显示包含在photosetLocationCollection位置列表。



photraxMap 的是BingMap。 的setView()的是Bing地图的方法,而不是我自己的自定义方法。



问题是,它的好 - 它显示的所有标记/图钉,但只是勉强 - 极端的位置被裁剪,你可以在这里看到:





在screamshot,你可以看到,图钉北圣安地列斯以及一个在哥伦比亚,在地图的东南边缘,被部分遮蔽(一个在帕迪也是部分遮蔽,由地图类型框,但我认为不能帮助)。



我希望他们有一个小的回旋余地,因为它是。这不只是一个表面问题 - 直到你拖动地图向上或向下或左或右一点点的局外人图钉是不可选择的。



有没有办法来调整缩放级别只是一个teensy-weensy位(不是一个完整的缩放级别更高)?



更新



根据在下面的答案的想法,我想我会尝试这样的事:

  //从Brundritt和Boonaert改编:http://stackoverflow.com/questions/26937358/can-i-adjust-my-bing-maps-view-locationrect-bounding-box-by-a-small-amount 
//传递前的位置设置来看,两次调用该方法,添加将伸展
//地图的可视区域了一下,像这样伪造的NW和SE地点:$ b​​ $ b //位置nwShim = GetAShimLocation(LOCS,真);
//位置seShim = GetAShimLocation(LOCS,FALSE);
// locs.Add(nwShim); locs.Add(seShim);
公共静态位置GetAShimLocation(IList的<地点>的位置,布尔IsForNorthwestCorner)
{
const int的MAP_CUSHION = 1; //是1足够舒适坐垫?
//我不知道为什么拉特是85而不是90
双maxLat = -85;
双minL​​at = 85;
双maxLon = -180;
双MINLON = 180;

的foreach(在位置位置LOC)
{
如果(loc.Latitude> maxLat)
{
maxLat = loc.Latitude;
}

如果(loc.Latitude< minLat)
{
minLat = loc.Latitude;
}

如果(loc.Longitude> maxLon)
{
maxLon = loc.Longitude;
}

如果(loc.Longitude< MINLON)
{
MINLON = loc.Longitude;
}
}

位置retLoc =新位置();
//我不知道这个逻辑/数学是正确的 - 测试后
如果(IsForNorthwestCorner)
{
retLoc.Latitude = maxLat - MAP_CUSHION;
retLoc.Longitude = maxLon - MAP_CUSHION;
}
,否则//东南角 - 舒展了一下两个方向
{
retLoc.Latitude = minLat + MAP_CUSHION;
retLoc.Longitude = MINLON + MAP_CUSHION;
}
}


解决方案

在。为了做到这一点,你有我想至少有两个选项




  • 第一种选择:使用假的位置



您选择(经度和纬度增量)任意填充,你将在最大/最小位置添加或检索然后你用的setView()来设置你的图钉视图以及其他添加的位置,将允许超过你的缩放级别或正确设置视图来显示所有你的项目。



要改善这种技术,就可以计算出地图的分辨率和根据您的图钉和地图的分辨率的像素大小的纬度和增量为东经相应的三角洲。




  • 第二个选项:手动计算最佳观赏



对于这个第二个,我建议你在什么瑞奇回来了共享的,而读,看看自己:的 http://rbrundritt.wordpress.com/2009/07/21/determining-best-map-view-for-an-array-的-位置/



您将需要调整的代码是在这里(因为链接的答案是不利于计算器):

  ///<总结> 
///计算为一个地图
///<位置的列表最好的地图视图; /总结>
///< PARAM NAME =位置>位置对象<名单; /参数>
///&下; PARAM NAME =mapWidth>在像素与所述地图宽度; /参数>
///< PARAM NAME =mapHeight>地图的高度以像素为单位和LT; /参数>
///< PARAM NAME =缓冲>宽度像素用于创建地图周围的缓冲区。这是保持图钉被切断的边缘< /参数>
///<退货和GT;返回最佳的地图中心点和缩放级别组给定的地点℃的MapViewSpecification; /回报>
公共静态MapViewSpecification BestMapView(IList的<地点>的位置,双mapWidth,双mapHeight,INT缓存)
{
MapViewSpecification图形页面;
位置中心=新位置();
双个zoomLevel = 0;

双maxLat = -85;
双minL​​at = 85;
双maxLon = -180;
双MINLON = 180;

//计算矩形边界
的for(int i = 0; I< locations.Count;我++)
{
如果(位置[I] .Latitude > maxLat)
{
maxLat =位置[I] .Latitude;
}

如果(位置[I] .Latitude< minLat)
{
minLat =位置[I] .Latitude;
}

如果(位置[I] .Longitude> maxLon)
{
maxLon =位置[I] .Longitude;
}

如果(位置[I] .Longitude< MINLON)
{
MINLON =位置[I] .Longitude;
}
}

center.Latitude =(maxLat + minLat)/ 2;
center.Longitude =(maxLon + MINLON)/ 2;

双击放大1 = 0,放大2 = 0;

//判断基于地图的比例尺和边界坐标信息
的最佳缩放级别,如果(maxLon = MINLON和放大器;!&安培;!maxLat = minLat)
{
//最佳变焦级别基于地图宽度
缩放1 =将Math.log(360.0 / 256.0 *(mapWidth - 2 *缓冲液)/(maxLon - MINLON))/将Math.log(2);
//最佳缩放级别基于地图的高度
放大2 =将Math.log(180.0 / 256.0 *(mapHeight - 2 *缓冲区)/(maxLat - minLat))/将Math.log(2);
}

//使用最缩小两个缩放级别
=个zoomLevel的(缩放1<缩放2)?缩放1:缩放2;

图形页面=新MapViewSpecification(中心,个zoomLevel);

返回图形页面;
}

如果您发现任何的困难,让我们知道,我肯定我们' 。将能够帮助你一点点




  • 另一个帮助:



另外,我发现一个旧的代码,我写了关于与填充最佳图形页面,我不能送你整个环境,但你会得到的想法:

  //判断基于地图的比例尺最好的缩放级别和边界坐标信息
如果((mapView.Bounds !.SouthEast.Longitude = mapView.Bounds.NorthWest.Longitude)及和放大器;!
(mapView.Bounds.NorthWest.Latitude = mapView.Bounds.SouthEast.Latitude))
{
填充填充= mapView.Padding;基于地图的宽度
放大1

//最佳缩放级别=(将Math.log(360.0 / 256.0 *(mapView.MapSize.Width - (padding.Left + padding.Right))/ (mapView.Bounds.SouthEast.Longitude - mapView.Bounds.NorthWest.Longitude))/将Math.log(2));
//最佳缩放级别基于地图的高度
放大2 =将Math.log(180.0 / 256.0 *(mapView.MapSize.Height - (padding.Top + padding.Bottom))/(mapView.Bounds。 NorthWest.Latitude - mapView.Bounds.SouthEast.Latitude))/将Math.log(2);
}

//使用最多缩小两个缩放级别
mapView.ZoomLevel的=(INT)Math.Floor((缩放1<放大2)放大1:缩放2 );


I am using this code:

photraxMap.SetView(new LocationRect(App.photosetLocationCollection));

...to zoom a map to show the List of Locations contained in photosetLocationCollection.

photraxMap is a BingMap. SetView() is a Bing Maps method, not my own custom method.

The problem is that it works too well - it shows all the markers/pushpins, but just barely - the extreme locations are "clipped" as you can see here:

In the screamshot, you can see that the pushpin north of San Andreas as well as the one at Columbia, at the southeast edge of the map, are partially obscured (the one at Pardee is also partially obscured, by the Map Type box, but I reckon that can't be helped).

I want them to have a little "wiggle room" as it were. This is not simply a cosmetic issue - the "outlier" pushpins are not selectable until you drag the map up or down or left or right a tad.

Is there a way to tweak the zoom level just a teensy-weensy bit (not a full zoom level higher)?

UPDATE

Based on the ideas in the answer below, I think I will try something like this:

// Adapted from Brundritt and Boonaert: http://stackoverflow.com/questions/26937358/can-i-adjust-my-bing-maps-view-locationrect-bounding-box-by-a-small-amount
// Before passing the locations to set view, call this twice, to add bogus NW and SE locations that will stretch 
// the viewable area of the map a little, like so:
// Location nwShim = GetAShimLocation(locs, true);
// Location seShim = GetAShimLocation(locs, false);
// locs.Add(nwShim); locs.Add(seShim);
public static Location GetAShimLocation(IList<Location> locations, bool IsForNorthwestCorner)
{
    const int MAP_CUSHION = 1; // Is 1 a comfortable enough cushion?
    // I don't know why the Lats are 85 instead of 90
    double maxLat = -85;
    double minLat = 85;
    double maxLon = -180;
    double minLon = 180;

    foreach (Location loc in locations)
    {
        if (loc.Latitude > maxLat)
        {
            maxLat = loc.Latitude;
        }

        if (loc.Latitude < minLat)
        {
            minLat = loc.Latitude;
        }

        if (loc.Longitude > maxLon)
        {
            maxLon = loc.Longitude;
        }

        if (loc.Longitude < minLon)
        {
            minLon = loc.Longitude;
        }
    }

    Location retLoc = new Location();
    // I'm not sure this logic/math is right - test it later
    if (IsForNorthwestCorner)
    {
        retLoc.Latitude = maxLat - MAP_CUSHION;
        retLoc.Longitude = maxLon - MAP_CUSHION;
    }
    else // SouthEast corner - stretch a little both directions
    {
        retLoc.Latitude = minLat + MAP_CUSHION;
        retLoc.Longitude = minLon + MAP_CUSHION;
    }
}

解决方案

In order to do this, you have at least two options that I'm thinking about.

  • First option: using fake locations

You choose an arbitrary padding (delta in latitude and longitude) that you will add or retrieve on the maximum/minimum location then you use SetView() to set the view on your pushpins as well as the other added locations that will permit to exceed your zoom level or set the view correctly to display all of you items.

To improve this technique, you can calculate the map's resolution and the corresponding delta for latitude and delta for longitude based on the size in pixel of your pushpins and the map's resolution.

  • Second option: manually calculating the best view

For this second one, I suggest you take a read at what Ricky shared a while back now, see for yourself: http://rbrundritt.wordpress.com/2009/07/21/determining-best-map-view-for-an-array-of-locations/

The code you will need to adapt is here (because answer with links are not good for StackOverflow):

   /// <summary>
/// Calculates the best map view for a list of locations for a map
/// </summary>
/// <param name="locations">List of location objects</param>
/// <param name="mapWidth">Map width in pixels</param>
/// <param name="mapHeight">Map height in pixels</param>
/// <param name="buffer">Width in pixels to use to create a buffer around the map. This is to keep pushpins from being cut off on the edge</param>
/// <returns>Returns a MapViewSpecification with the best map center point and zoom level for the given set of locations</returns>
public static MapViewSpecification BestMapView(IList<Location> locations, double mapWidth, double mapHeight, int buffer)
{
    MapViewSpecification mapView;
    Location center = new Location();
    double zoomLevel = 0;

    double maxLat = -85;
    double minLat = 85;
    double maxLon = -180;
    double minLon = 180;

    //calculate bounding rectangle
    for (int i = 0; i < locations.Count; i++)
    {
        if (locations[i].Latitude > maxLat)
        {
            maxLat = locations[i].Latitude;
        }

        if (locations[i].Latitude < minLat)
        {
            minLat = locations[i].Latitude;
        }

        if (locations[i].Longitude > maxLon)
        {
            maxLon = locations[i].Longitude;
        }

        if (locations[i].Longitude < minLon)
        {
            minLon = locations[i].Longitude;
        }
    }

    center.Latitude = (maxLat + minLat) / 2;
    center.Longitude = (maxLon + minLon) / 2;

    double zoom1=0, zoom2=0;

    //Determine the best zoom level based on the map scale and bounding coordinate information
    if (maxLon != minLon && maxLat != minLat)
    {
        //best zoom level based on map width
        zoom1 = Math.Log(360.0 / 256.0 * (mapWidth – 2*buffer) / (maxLon – minLon)) / Math.Log(2);
        //best zoom level based on map height
        zoom2 = Math.Log(180.0 / 256.0 * (mapHeight – 2*buffer) / (maxLat – minLat)) / Math.Log(2);
    }

    //use the most zoomed out of the two zoom levels
    zoomLevel = (zoom1 < zoom2) ? zoom1 : zoom2;

    mapView = new MapViewSpecification(center, zoomLevel);

    return mapView;
}

If you find any difficulty, let us know, I'm sure we'll be able to help you a little bit.

  • Yet another help:

Also, I found an old code that I wrote regarding the best mapview with padding, I can't send you the whole context but you'll get the idea:

//Determine the best zoom level based on the map scale and bounding coordinate information
if ((mapView.Bounds.SouthEast.Longitude != mapView.Bounds.NorthWest.Longitude) &&
    (mapView.Bounds.NorthWest.Latitude != mapView.Bounds.SouthEast.Latitude))
{
    Padding padding = mapView.Padding;

    //best zoom level based on map width
    zoom1 = (Math.Log(360.0 / 256.0 * (mapView.MapSize.Width - (padding.Left + padding.Right)) / (mapView.Bounds.SouthEast.Longitude - mapView.Bounds.NorthWest.Longitude)) / Math.Log(2));
    //best zoom level based on map height
    zoom2 = Math.Log(180.0 / 256.0 * (mapView.MapSize.Height - (padding.Top + padding.Bottom)) / (mapView.Bounds.NorthWest.Latitude - mapView.Bounds.SouthEast.Latitude)) / Math.Log(2);
}

//use the most zoomed out of the two zoom levels
mapView.ZoomLevel = (int)Math.Floor((zoom1 < zoom2) ? zoom1 : zoom2);

这篇关于我可以用少量的调整我的兵地图的查看/ LocationRect /包围盒?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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