1

我有一个关于 Bing Maps API 的小而快的问题。当您将 API 加载到应用程序中时,它会加载世界并无限滚动,一遍又一遍地重复图块。我想知道的是,是否有办法将其设置为仅显示完整地图而不重复,并可能将其视图设置为任何人都可以缩小到的最大值。

换句话说,我不想看到任何重复的瓷砖,只是让它显示完整的地图。一旦完整的地图可见,我就想锁定滚动功能,这样就不会重复任何事情以及锁定缩小功能。

如果它有任何区别,我正在尝试使用 WPF 来做到这一点。

4

1 回答 1

2

以下是用于限制地图视图的自定义地图模式。您可以调整字段和方法以将其限制为您希望的地图。

public class CustomMapMode : MercatorMode {

    // The latitude value range (From = bottom most latitude, To = top most latitude)
    protected static Range<double> validLatitudeRange = new Range<double>(39.479665, 39.486985);
    // The longitude value range (From = left most longitude, To = right most longitude)
    protected static Range<double> validLongitudeRange = new Range<double>(-87.333154, -87.314100);
    // Restricts the map view.

    protected override Range<double> GetZoomRange(Location center) {
        // The allowable zoom levels - 14 to 25.
        return new Range<double>(14, 25);
    }

    // This method is called when the map view changes on Keyboard and Navigation Bar events.
    public override bool ConstrainView(Location center, ref double zoomLevel, ref double heading, ref double pitch) {
        bool isChanged = base.ConstrainView(center, ref zoomLevel, ref heading, ref pitch);

        double newLatitude = center.Latitude;
        double newLongitude = center.Longitude;

        // If the map view is outside the valid longitude range,
        // move the map back within range.
        if(center.Longitude > validLongitudeRange.To) {
            newLongitude = validLongitudeRange.To;
        } else if(center.Longitude < validLongitudeRange.From) {
            newLongitude = validLongitudeRange.From;
        }

        // If the map view is outside the valid latitude range,
        // move the map back within range.
        if(center.Latitude > validLatitudeRange.To) {
            newLatitude = validLatitudeRange.To;
        } else if(center.Latitude < validLatitudeRange.From) {
            newLatitude = validLatitudeRange.From;
        }

        // The new map view location.
        if(newLatitude != center.Latitude || newLongitude != center.Longitude) {
            center.Latitude = newLatitude;
            center.Longitude = newLongitude;
            isChanged = true;
        }

        // The new zoom level.
        Range<double> range = GetZoomRange(center);
        if(zoomLevel > range.To) {
            zoomLevel = range.To;
            isChanged = true;
        } else if(zoomLevel < range.From) {
            zoomLevel = range.From;
            isChanged = true;
        }

        return isChanged;
    }
}
于 2012-06-15T20:33:29.280 回答