わかりました、私はこの setTimeout 全体が完璧だと思っていましたが、ひどく間違っているようです。
Excanvas と JavaScript を使用して自宅の州の地図を描画していますが、描画手順がブラウザーを詰まらせます。現在、私は大きな組織に所属しているため、IE6 に甘んじることを余儀なくされています。
だから私がやろうと思ったのは、distributedDrawPolys と呼ばれる手順を構築することです (おそらく間違った単語を使用しているので、distributed という単語には注目しないでください)。一度にそれらの。
これは、ポリゴンをグローバル配列にプッシュし、setTimeout を実行するメソッドです。
for (var x = 0; x < polygon.length; x++) {
coordsObject.push(polygon[x]);
fifty++;
if (fifty > 49) {
timeOutID = setTimeout(distributedDrawPolys, 5000);
fifty = 0;
}
}
そのメソッドの最後にアラートを配置しました。実際には 1 秒で実行されます。
分散メソッドは次のようになります。
function distributedDrawPolys()
{
if (coordsObject.length > 0) {
for (x = 0; x < 50; x++) { //Only do 50 polygons
var polygon = coordsObject.pop();
var coordinate = polygon.selectNodes("Coordinates/point");
var zip = polygon.selectNodes("ZipCode");
var rating = polygon.selectNodes("Score");
if (zip[0].text.indexOf("HH") == -1) {
var lastOriginCoord = [];
for (var y = 0; y < coordinate.length; y++) {
var point = coordinate[y];
latitude = shiftLat(point.getAttribute("lat"));
longitude = shiftLong(point.getAttribute("long"));
if (y == 0) {
lastOriginCoord[0] = point.getAttribute("long");
lastOriginCoord[1] = point.getAttribute("lat");
}
if (y == 1) {
beginPoly(longitude, latitude);
}
if (y > 0) {
if (translateLongToX(longitude) > 0 && translateLongToX(longitude) < 800 && translateLatToY(latitude) > 0 && translateLatToY(latitude) < 600) {
drawPolyPoint(longitude, latitude);
}
}
}
y = 0;
if (zip[0].text != targetZipCode) {
if (rating[0] != null) {
if (rating[0].text == "Excellent") {
endPoly("rgb(0,153,0)");
}
else if (rating[0].text == "Good") {
endPoly("rgb(153,204,102)");
}
else if (rating[0].text == "Average") {
endPoly("rgb(255,255,153)");
}
}
else { endPoly("rgb(255,255,255)"); }
}
else {
endPoly("rgb(255,0,0)");
}
}
}
}
}
編集:フォーマットを修正
そのため、setTimeout メソッドを使用すると、サイトがポリゴンをグループで描画できるようになり、ユーザーはページがまだ描画されている間にページを操作できるようになると考えました。ここで何が間違っていますか?