我试图在Bing地图而不是整个世界中显示一个特定的国家(确切地说是英国),但我不知道如何!
在我的搜索中,我找到了一个博客问题,答案是这是不可能的,但我不认为这是真的,因为我已经在许多其他网站上看到过这样做。
所以如果有人可以就此问题提出建议,我将不胜感激。
我目前的代码是:
<!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, infobox, dataLayer;
function GetMap() {
// Initialize the map
map = new Microsoft.Maps.Map(document.getElementById("myMap"),
{ credentials: "XXXXXXXXXXXXXXXXXXXXXXXXXX"
});
dataLayer = new Microsoft.Maps.EntityCollection();
map.entities.push(dataLayer);
var infoboxLayer = new Microsoft.Maps.EntityCollection();
map.entities.push(infoboxLayer);
infobox = new Microsoft.Maps.Infobox(new Microsoft.Maps.Location(0, 0), { visible: false, offset: new Microsoft.Maps.Point(0, 20) });
infoboxLayer.push(infobox);
AddData();
}
function AddData() {
var pin1 = new Microsoft.Maps.Pushpin(new Microsoft.Maps.Location(51.555076763136704, 0.691519856452919));
pin1.Title = "This is Pin 1";
pin1.Description = "Pin 1 description";
Microsoft.Maps.Events.addHandler(pin1, 'click', displayInfobox);
dataLayer.push(pin1);
}
function displayInfobox(e) {
if (e.targetType == 'pushpin') {
infobox.setLocation(e.target.getLocation());
infobox.setOptions({ visible: true, title: e.target.Title, description: e.target.Description });
}
}
</script>
</head>
<body onload="GetMap();">
<div id='myMap' style="position:relative;width:600px;height:400px;"></div>
</body>
</html>
答案 0 :(得分:3)
您无法明确告诉它缩放到英国。
但是你可以创建一个矩形(边界框)并使用该矩形作为边界来初始化地图。
// create a rectangle around the UK (northwest / southeast corners) manually selected
var ukBox = Microsoft.Maps.LocationRect.fromCorners(new Microsoft.Maps.Location(58.909597, -11.449733), new Microsoft.Maps.Location(50.309499, 2.041477));
map = new Microsoft.Maps.Map(document.getElementById("myMap"), {
credentials: "XXXXXXXXXXXXXXXXXXXXXXXXXX",
bounds: ukBox // use the rectangle as the map bounds (for the initial render)
});
http://jsfiddle.net/gaby/nm1dx07L/
演示请记住,它会选择最适合矩形的缩放级别。所以它取决于容器尺寸。