如何显示完整地图并防止在Bing Maps API中滚动 [英] How to show the full map and prevent scrolling in Bing Maps API

查看:156
本文介绍了如何显示完整地图并防止在Bing Maps API中滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I had a small and quick question concerning the Bing Maps API. When you load the API into the application it loads the world and scrolls infinitely repeating the tiles over and over again. What I would like to know is if there was a way to set it to only show the full map without it repeating and possibly setting the view of that as the maximum that anyone can zoom out to.

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

In other words I don't want to see any repeating tiles and just have it showing the full map. Once the full map is visible I then want to lock the scrolling features so nothing gets repeated as well as lock the zoom out functionality.

如果有什么不同,我尝试使用WPF进行.

If it makes any difference I am trying to do this using WPF.

推荐答案

以下是用于限制地图视图的自定义地图模式.您可以调整字段和方法来获取它,以限制地图的显示方式.

Below is a custom map mode for limiting the view of the map. You can adjust the fields and methods to get it to limit the map how you would like it to.

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;
    }
}

这篇关于如何显示完整地图并防止在Bing Maps API中滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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