none
How do I start a continuous pan in the V7 AJAX control? RRS feed

Answers

  • Use setTimeOut to make repeat requests to the setView() method, panning the map by a little each time:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html>
      <head>
       <title></title>
       <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    
       <script type="text/javascript" src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0"></script>
    
       <script type="text/javascript">
    
         var map = null;
         var t = null;
         var isPanning = false;
         
         function GetMap()
         {
          // Initialize the map
          map = new Microsoft.Maps.Map(document.getElementById("mapDiv"), {credentials:"Bing Maps Key"}); 
         
         }
    
         function StartPan()
         {
          if (!isPanning)
          {
            PanMap();
            isPanning = true;
          }
         }
    
         function PanMap()
         {
    
          map.setView({center: map.getCenter(), centerOffset: new Microsoft.Maps.Point(-10,0)});
    
          t = setTimeout(PanMap, 200);
    
         }
    
         function EndPan()
         {
          clearTimeout(t);
          isPanning = false;
         }
    
       </script>
      </head>
      <body onload="GetMap();">
       <div id='mapDiv' style="position:relative; width:400px; height:400px;"></div>   
       <input type="button" value="Pan Map" onclick="StartPan()"/> 
       <input type="button" value="Stop Pan" onclick="EndPan()"/>
      </body>
    </html>
    



    twitter: @alastaira blog: http://alastaira.wordpress.com/
    • Marked as answer by AndyJump Friday, September 2, 2011 7:48 AM
    Thursday, September 1, 2011 4:24 PM
    Moderator

All replies

  • Use setTimeOut to make repeat requests to the setView() method, panning the map by a little each time:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html>
      <head>
       <title></title>
       <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    
       <script type="text/javascript" src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0"></script>
    
       <script type="text/javascript">
    
         var map = null;
         var t = null;
         var isPanning = false;
         
         function GetMap()
         {
          // Initialize the map
          map = new Microsoft.Maps.Map(document.getElementById("mapDiv"), {credentials:"Bing Maps Key"}); 
         
         }
    
         function StartPan()
         {
          if (!isPanning)
          {
            PanMap();
            isPanning = true;
          }
         }
    
         function PanMap()
         {
    
          map.setView({center: map.getCenter(), centerOffset: new Microsoft.Maps.Point(-10,0)});
    
          t = setTimeout(PanMap, 200);
    
         }
    
         function EndPan()
         {
          clearTimeout(t);
          isPanning = false;
         }
    
       </script>
      </head>
      <body onload="GetMap();">
       <div id='mapDiv' style="position:relative; width:400px; height:400px;"></div>   
       <input type="button" value="Pan Map" onclick="StartPan()"/> 
       <input type="button" value="Stop Pan" onclick="EndPan()"/>
      </body>
    </html>
    



    twitter: @alastaira blog: http://alastaira.wordpress.com/
    • Marked as answer by AndyJump Friday, September 2, 2011 7:48 AM
    Thursday, September 1, 2011 4:24 PM
    Moderator
  • That's great thanks.
    Friday, September 2, 2011 7:48 AM