【发布时间】:2015-01-12 06:42:14
【问题描述】:
我正在使用此代码:
photraxMap.SetView(new LocationRect(App.photosetLocationCollection));
...缩放地图以显示包含在 photosetLocationCollection 中的位置列表。
photraxMap 是一个 BingMap。 SetView() 是 Bing Maps 方法,不是我自己的自定义方法。
问题在于它也很好地工作 - 它显示了所有标记/图钉,但只是勉强 - 正如您在此处看到的那样,极端位置被“剪裁”了:
在尖叫声中,您可以看到圣安地列斯以北的图钉以及位于地图东南边缘的哥伦比亚的图钉被部分遮挡(Pardee 的图钉也被地图类型部分遮挡)框,但我认为这无济于事)。
我希望他们有一点“回旋余地”。这不仅仅是一个表面问题——“异常值”图钉在您向上或向下或向左或向右拖动一点点之前是无法选择的。
有没有办法将缩放级别调整到只有很小的一点(而不是更高的完整缩放级别)?
更新
根据下面答案中的想法,我想我会尝试这样的事情:
// 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;
}
}
【问题讨论】: