0

我正在尝试为我的网站编写一个 bing 流量地图,一切都很好,除了我必须摆脱的两个烦恼:

  • 使用箭头键通常可以让我上/下我的网页,但现在它只移动地图的中心。我该如何关闭它?

  • 为了让地图显示交通图层,必须有一个按钮,用户需要操作才能打开它?我只想让流量默认开启。

这是我网站上目前的代码:

<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;
      function trafficModuleLoaded()
      {
        setMapView();
      }    
       function loadTrafficModule()
      {
       Microsoft.Maps.loadModule('Microsoft.Maps.Traffic', { callback: trafficModuleLoaded });
      }
      function setMapView()
      {
        map.setView({zoom: 12, center: new Microsoft.Maps.Location(43.64, -79.39)})
      }          
      function getMap()
      {
          map = new Microsoft.Maps.Map(document.getElementById('myMap'), {credentials: 'AmREBa2I8sJ_e4p_G4UA00Y-pFpncDf8jG9J0f75aMZszZyXTfnYCdxWWyTuZSC1'});
          loadTrafficModule();
          trafficLayer.show();
      }    
      function showTrafficLayer()
     {    
            var trafficLayer = new Microsoft.Maps.Traffic.TrafficLayer(map);
        // show the traffic Layer
        trafficLayer.show();
      }

      </script>
4

1 回答 1

0

这对我来说很好,页面加载时流量就在那里:

<script type="text/javascript">          
  var map = null;

  function getMap()
  {
      map = new Microsoft.Maps.Map(document.getElementById('myMap'), 
      {
        credentials: 'key',
        showDashboard: false,
        mapTypeId: Microsoft.Maps.MapTypeId.road,
        center: new Microsoft.Maps.Location(some, place),
        zoom: 12
      });

      getTraffic();

      var pushpin = new Microsoft.Maps.Pushpin(map.getCenter(), null); 
      map.entities.push(pushpin); 
      pushpin.setLocation(new Microsoft.Maps.Location(some, place));           
   }

   function getTraffic()
   {
      Microsoft.Maps.loadModule('Microsoft.Maps.Traffic', { callback: function() { trafficLayer = new Microsoft.Maps.Traffic.TrafficLayer(map); trafficLayer.show();} });  
   }
  </script>
于 2012-08-27T14:47:54.133 回答