我正在尝试为我的网站编写一张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>
答案 0 :(得分: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>