我有一个使用Virtual Earth V6.3控件的应用程序,使用纯javascript添加折线,如下面嵌入单个HTML5网页的示例代码段所示:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>VE Map with Polyline</title>
<script type="text/javascript" src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.3"></script>
<script type="text/javascript">
function MapLoad() {
// load map
var _map = new VEMap('Map');
_map.LoadMap();
// center point in NY City
var _center = new VELatLong(40.75, -73.99);
// zoom level
_map.SetCenterAndZoom(_center, 14);
// set Map style
_map.SetMapStyle(VEMapStyle.Shaded);
// polyline layer
var _layerPolyline = new VEShapeLayer();
// sample polyline array of coordinates
var _arrPoints = [];
_arrPoints.push(new VELatLong(40.78, -73.984));
_arrPoints.push(new VELatLong(40.76, -73.989));
_arrPoints.push(new VELatLong(40.75, -73.99));
_arrPoints.push(new VELatLong(40.74, -73.991));
_arrPoints.push(new VELatLong(40.73, -73.992));
_arrPoints.push(new VELatLong(40.72, -73.993));
_arrPoints.push(new VELatLong(40.72, -73.994));
_arrPoints.push(new VELatLong(40.73, -73.995));
_arrPoints.push(new VELatLong(40.73, -73.996));
_arrPoints.push(new VELatLong(40.74, -73.997));
// polyline object properties
var _polyLine= new VEShape(VEShapeType.Polyline, _arrPoints);
_polyLine.HideIcon();
_polyLine.SetLineColor(new VEColor(0, 0, 255, 1));
_polyLine.SetFillColor(new VEColor(0, 0, 255, 0));
_polyLine.SetLineWidth(4);
// add polyline to layer
_layerPolyline.AddShape(_polyLine);
// add layer to map
_map.AddShapeLayer(_layerPolyline);
}
</script>
</head>
<body onload="MapLoad();">
<div id="Map" style="position:absolute; height:98%; width:98%;"></div>
</body>
</html>
在任何缩放级别都可以正常工作。但是,在使用ASP.NET 4.5 Web表单时,实际的应用程序中基本上相同的代码会产生奇怪的结果,即:折线在高缩放级别(大约15以上)时消失。
问:有关问题的根本原因以及如何解决问题的任何想法? THX。
更新:已解决问题升级到Bing Maps AJAX Control V7.0(正常工作: DEMO :公交路线折线在任何缩放级别都可见。感谢Ricky Brundritt(@rbrundritt)。
答案 0 :(得分:1)
可能的问题与丢失的UTF-9元标记或doctype有关。 V6.3非常陈旧,需要指定以下metatag和doctype:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
另一个可能的问题是您在加载地图时指定了任何凭据。这违反了Bing Maps的使用期限。
_map = new VEMap('MapNYC');
_map.SetCredentials("YOUR_BING_MAPS_KEY");
_map.LoadMap();
您可以在此处找到有关如何创建Bing地图帐户和密钥的文档:
https://msdn.microsoft.com/en-us/library/gg650598.aspx
https://msdn.microsoft.com/en-us/library/ff428642.aspx
我建议创建一个&#34; basic&#34; &#34;公共网站&#34;的关键。这将允许您每年125,000次免费交易。
所有这一切,你不应该使用v6.3。它在5年前被V7取代,很快就会接近尾声。 v6.3的文档在一年前脱机,作为结束该版本生命的一部分。