【问题标题】:How to set bing traffic maps to show traffic by default?如何设置 bing 流量地图默认显示流量?
【发布时间】:2012-06-18 17:07:13
【问题描述】:

我正在尝试为我的网站编写一个 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>

【问题讨论】:

    标签: html bing-maps traffic


    【解决方案1】:

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

    <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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-09-13
      • 1970-01-01
      • 2011-07-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-02-06
      相关资源
      最近更新 更多