我正在服务器端开发一个带有 vb.net 的网页,并在 .aspx 页面上为谷歌地图开发一些 javascript。该网页是一个大型的 GIS 事物,它绘制出格鲁吉亚某些县内的所有街区组,因此它是 .js 文件中大约 15MB 的纯 [纬度,经度] 点。在 chrome/firefox 中,地图加载,然后加载脚本,触发回调以绘制它定义的多边形,并将多边形绘制到地图上。在 IE 中,地图被加载,当脚本被加载时,控制台有一个SCRIPT14: error -2147024882
在线 1。除了地图上的多边形之外,一切都正确显示。.js 文件的结构是只有几个变量的声明。
var allPolys = [
[
//poly1 points
[x1,y1],
[x2,y2],
...
],
[
//next poly
[x1,y1],
...
]
]
^^ 是每个多边形在 .js 中的定义方式。这是一个大小问题,因为所有点都在一个数组中吗?
映射代码:
function drawPolys() {
for (var i = 0; i < allTracts.length; i++) {
var tract = "new google.maps.Polygon({ strokeWeight: 0.7, path: [";
for (var j = 0; j < allTracts[i].length; j++)
tract += " new google.maps.LatLng(" + allTracts[i][j][0] + "," + allTracts[i][j][1] + "),";
tract = tract.substring(0, tract.length - 1) + "], map: map });";
eval(tract);
}
//this is all for other 'multipolygons' that are in some maps
var colors = ['red', 'blue', 'green', 'orange', 'yellow', 'white'];
for (var i = 0; i < multiPolys.length; i++) {
for (var j = 0; j < multiPolys[i].length; j++) {
var subTract = "new google.maps.Polygon({ strokeWeight: 1.5, strokeColor: '" + colors[i % colors.length] + "', fillColor: '" + colors[i % colors.length] + "', path: [";
for (var k = 0; k < multiPolys[i][j].length; k++)
subTract += " new google.maps.LatLng(" + multiPolys[i][j][k][0] + "," + multiPolys[i][j][k][1] + "),";
subTract = subTract.substring(0, subTract.length - 1) + "], map: map });";
eval(subTract);
}
}
}
在 Chrome 中,页面加载精美。
编辑:没有 eval() 的新映射函数
function drawPolys() {
for (var i = 0; i < allTracts.length; i++) {
var path = [];
for (var j = 0; j < allTracts[i].length; j++)
path.push(new google.maps.LatLng(allTracts[i][j][0],allTracts[i][j][1]));
new google.maps.Polygon({ strokeWeight: 0.7, path: path, map: map });
}
var colors = ['red', 'blue', 'green', 'orange', 'yellow', 'white'];
for (var i = 0; i < multiPolys.length; i++) {
var path = [];
for (var j = 0; j < multiPolys[i].length; j++) {
path[j] = [];
for (var k = 0; k < multiPolys[i][j].length; k++)
path[j].push(new google.maps.LatLng(multiPolys[i][j][k][0],multiPolys[i][j][k][1]));
}
new google.maps.Polygon({ strokeWeight: 1.5, strokeColor: colors[i % colors.length], fillColor: colors[i % colors.length], paths: path, map: map });
}
}