2012-06-15 25 views
1

我有一個關於Bing Maps API的小問題和快速問題。當您將API加載到應用程序中時,它會加載世界並無限次重複滾動。我想知道的是,如果有一種方法可以將其設置爲僅顯示完整的地圖而不重複,並且可以將該視圖設置爲任何人都可以縮小的最大值。如何在Bing Maps API中顯示完整的地圖並防止滾動

換句話說,我不想看到任何重複的瓷磚,只是讓它顯示完整的地圖。一旦完整的地圖可見,我就想要鎖定滾動功能,以免重複以及鎖定縮小功能。

如果它有什麼區別,我正在嘗試使用WPF來做到這一點。

回答

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

我該如何初始化bing map API來使用它?關於使用這種地圖模式或其他模式,還有哪些變化? – Seb

+0

您的'Map'有一個'Mode'屬性,這是我需要設置的自定義類。在上面的代碼中,我擴展了'MercatorMode',它允許你指定你自己的tile源。你也許可以使用相同的代碼來擴展'AerialMode',我從來沒有嘗試過。 –

+0

這工作得很好。謝謝 – Seb