none
SetMapView zooms in too far RRS feed

  • Question

  • I am using SetMapView () on a dynamically generated array.  This works great except when the array ends up with one point or many points all very close together, then the map zooms in all the way and I get the no picture screen.

    Is there a way to tell if the map has been zoomed too far or set a maximum zoom level? Anyone run into this problem before?

    • Moved by Ricky_Brundritt Saturday, March 10, 2012 1:17 PM (From:Bing Maps: Map Control and Web services Development)
    Monday, December 11, 2006 12:58 AM

Answers

  • This is how I control panning and zooming on my map (Thanks to a lot of help from people on this forum). It doesn't let the user get more than halfway off the map, and controls how much leeway they have in terms of zooming.

    Pan and Zoom Functions

    function panControl()
            {
                var latlon = map.GetCenter();
                var lat = latlon.Latitude;
                var lon = latlon.Longitude;


    // This gets confusing. The first latitude is a bit beyond the edge of my map. The second one (What it resets it too, is a bit before. If you make them too close, the whole browser freezes up for some reason.


            if(lat > -53.81059781) {
                map.SetCenter(new VELatLong(-53.81135800, lon));
                }
               
            else if(lat < -53.89384442) {
                map.SetCenter(new VELatLong(-53.89269268, lon));
                }
                   
            else if(lon > -146.33952141) {
                map.SetCenter(new VELatLong(lat, -146.34077890));
                }   
           
            else if(lon < -146.51607513) {
                map.SetCenter(new VELatLong(lat, -146.51387350));
                }   
            }
           
       // This should be straight forward...
            function zoomControl()
            {
                 var currentZoom = map.GetZoomLevel();
                 var zoomMax = '17';
                 var zoomMin = '12';
           
             if(currentZoom > zoomMax) {
                    map.SetZoomLevel(zoomMax);
             } else if(currentZoom < zoomMin) {
                    map.SetZoomLevel(zoomMin);
                  }
       
            }


    Saturday, July 7, 2007 12:25 PM

All replies

  • Hi, did you ever find a solution to this problem ? I am experiencing the same.

     

    Thanks,

    Martin

    Friday, July 6, 2007 11:57 AM
  • No I had to hard code in a check for the zoom level and set it to 17 if it was > 17
    Friday, July 6, 2007 10:57 PM
  • This is my custom method of finding the correct zoom (you can set the initial zoom to anything you want).  The first several lines (that find the topMost, leftMost, bottomMost, and rightMost) are executed for every location that needs to be found. 

     

    Code Snippet

    if (topMost < map.GetCenter().Latitude)

    {

    topMost = map.GetCenter().Latitude;

    }

    if (bottomMost > map.GetCenter().Latitude)

    {

    bottomMost = map.GetCenter().Latitude;

    }

    if (leftMost > map.GetCenter().Longitude)

    {

    leftMost = map.GetCenter().Longitude;

    }

    if (rightMost < map.GetCenter().Longitude)

    {

    rightMost = map.GetCenter().Longitude;

    }

     

    function setFinalZoom()

    {

    // Set the center of the map to be the point halfway between the extremes (farthest left, right, top, and bottom points of the map)

    centerX = (leftMost + rightMost) / 2;

    centerY = (topMost + bottomMost) / 2;

    topLeftLatLong = new VELatLong(topMost, leftMost);

    // Set the initial zoom to 14 (the legend length is .7 miles)

    map.SetCenterAndZoom(new VELatLong(centerY, centerX), 14);

    // Determine the all-encompassing zoom

    findZoom();

    }

     

    function findZoom()

    {

    // Custom timeout for 700 milliseconds to make sure there is enough time for the map view to load

    if (!timeout)

    {

    setTimeout("timeoutZoom()", 700);

    }

    else

    {

    timeout = false;

    // Gets the map view (contains the top-left and bottom-right coordinates of the map)

    var view = map.GetMapView();

    // If any pin is not within view, zoom out.

    if (view.TopLeftLatLong.Latitude < topLeftLatLong.Latitude || view.TopLeftLatLong.Longitude > topLeftLatLong.Longitude)

    {

    map.ZoomOut();

    findZoom();

    }

    }

    }

     

    function timeoutZoom()

    {

    timeout = true;

    findZoom();

    }

     

     Hope this helps,

    Robert

    Friday, July 6, 2007 11:50 PM
  • This is how I control panning and zooming on my map (Thanks to a lot of help from people on this forum). It doesn't let the user get more than halfway off the map, and controls how much leeway they have in terms of zooming.

    Pan and Zoom Functions

    function panControl()
            {
                var latlon = map.GetCenter();
                var lat = latlon.Latitude;
                var lon = latlon.Longitude;


    // This gets confusing. The first latitude is a bit beyond the edge of my map. The second one (What it resets it too, is a bit before. If you make them too close, the whole browser freezes up for some reason.


            if(lat > -53.81059781) {
                map.SetCenter(new VELatLong(-53.81135800, lon));
                }
               
            else if(lat < -53.89384442) {
                map.SetCenter(new VELatLong(-53.89269268, lon));
                }
                   
            else if(lon > -146.33952141) {
                map.SetCenter(new VELatLong(lat, -146.34077890));
                }   
           
            else if(lon < -146.51607513) {
                map.SetCenter(new VELatLong(lat, -146.51387350));
                }   
            }
           
       // This should be straight forward...
            function zoomControl()
            {
                 var currentZoom = map.GetZoomLevel();
                 var zoomMax = '17';
                 var zoomMin = '12';
           
             if(currentZoom > zoomMax) {
                    map.SetZoomLevel(zoomMax);
             } else if(currentZoom < zoomMin) {
                    map.SetZoomLevel(zoomMin);
                  }
       
            }


    Saturday, July 7, 2007 12:25 PM
  • As of early 2012, version 7 of the Bing Maps control, this is still an issue.  The code above is fundamentally a workaround for a bug in Bing, that really should be fixed.  Thanks.
    Thursday, February 2, 2012 7:04 PM
  • As of early 2012, version 7 of the Bing Maps control, this is still an issue.


    Can you post repro code? This works fine for me:

    map.setView({ bounds: Microsoft.Maps.LocationRect.fromLocations([
      new Microsoft.Maps.Location(52.62, 1.26),
      new Microsoft.Maps.Location(52.62000001, 1.26000001)
    ]
    )});


    twitter: @alastaira blog: http://alastaira.wordpress.com/
    Thursday, February 2, 2012 7:26 PM
    Moderator