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