|
343 | 343 | var public_tileFor = function(lats, lons, polygonsArray) {
|
344 | 344 | var height = lats.length;
|
345 | 345 | var width = lons.length;
|
| 346 | + var colorCanvas = document.createElement("canvas"); |
| 347 | + colorCanvas.height = 1; |
| 348 | + colorCanvas.width = 1; |
| 349 | + var colorcx = colorCanvas.getContext("2d"); |
346 | 350 | var canvas = document.createElement("canvas");
|
347 | 351 | canvas.height = height;
|
348 | 352 | canvas.width = width;
|
349 | 353 | var cx = canvas.getContext("2d");
|
| 354 | + var id = cx.createImageData(width, height); |
350 | 355 | for (var polygonsIdx in polygonsArray) {
|
351 | 356 | var polygonsObj = polygonsArray[polygonsIdx];
|
352 |
| - cx.fillStyle = polygonsObj.color; |
| 357 | + colorcx.fillStyle = polygonsObj.color; |
| 358 | + colorcx.clearRect(0, 0, 1, 1); |
| 359 | + colorcx.fillRect(0, 0, 1, 1); |
| 360 | + var colorArray = colorcx.getImageData(0, 0, 1, 1).data; |
353 | 361 | for (var column = 0, column_end = width;
|
354 | 362 | column < column_end; ++column) {
|
355 | 363 | var lon = lons[column];
|
|
441 | 449 |
|
442 | 450 | // Now actually fill in the pixels.
|
443 | 451 | var drawing = false;
|
444 |
| - var rectTop = 0; |
445 | 452 | for (var y = 0; y < height; ++y) {
|
446 | 453 | if (pixels[y]) {
|
447 |
| - if (drawing) { |
448 |
| - cx.fillRect(column, rectTop, 1, y - rectTop); |
449 |
| - } else { |
450 |
| - rectTop = y; |
451 |
| - } |
452 | 454 | drawing = !drawing;
|
453 | 455 | }
|
454 |
| - } |
455 |
| - if (drawing) { |
456 |
| - cx.fillRect(column, rectTop, 1, height - rectTop); |
| 456 | + if (drawing) { |
| 457 | + id.data.set(colorArray, (y * width + column) * 4); |
| 458 | + } |
457 | 459 | }
|
458 | 460 | }
|
459 | 461 | }
|
| 462 | + cx.putImageData(id, 0, 0); |
460 | 463 | return canvas;
|
461 | 464 | }
|
462 | 465 |
|
|
0 commit comments