harmonises iso and point renderers

This commit is contained in:
Francisco Dans 2015-08-20 14:23:21 +02:00
parent 595c254dbe
commit 26653967ac

View File

@ -218,25 +218,26 @@ L.TorqueLayer = L.CanvasLayer.extend({
var ctx = canvas.getContext('2d');
var self = this;
if (Object.keys(this._tiles).length > 0){
var min = {q: Infinity, w: new Set(), h: new Set()};
for(var key in this._tiles){
var coord = this._tiles[key].coord;
if (coord.x + coord.y < min.q){
min.q = coord.x + coord.y;
min.k = key;
if (this.options.renderer === "iso"){
var min = {q: Infinity, w: new Set(), h: new Set()};
for(var key in this._tiles){
var coord = this._tiles[key].coord;
if (coord.x + coord.y < min.q){
min.q = coord.x + coord.y;
min.k = key;
}
min.w.add(coord.x);
min.h.add(coord.y);
}
min.w.add(coord.x);
min.h.add(coord.y);
}
this.renderer.tileDimensions = {w: min.w.size, h: min.h.size};
this.renderer.firstTileCoords = {coord: this._tiles[min.k].coord, pos:this.getTilePos(this._tiles[min.k].coord)};
this.renderer.tileDimensions = {w: min.w.size, h: min.h.size};
this.renderer.firstTileCoords = {coord: this._tiles[min.k].coord, pos:this.getTilePos(this._tiles[min.k].coord)};
var valsPerTile = 256/this.options.resolution;
this.renderer.globalGrid = Array.apply(null, Array(this.renderer.tileDimensions.h * valsPerTile)).map(Number.prototype.valueOf,0);
for (var i = 0; i < this.renderer.globalGrid.length; i++){
this.renderer.globalGrid[i] = Array.apply(null, Array(this.renderer.tileDimensions.w * valsPerTile)).map(Number.prototype.valueOf,0);
var valsPerTile = 256/this.options.resolution;
this.renderer.globalGrid = Array.apply(null, Array(this.renderer.tileDimensions.h * valsPerTile)).map(Number.prototype.valueOf,0);
for (var i = 0; i < this.renderer.globalGrid.length; i++){
this.renderer.globalGrid[i] = Array.apply(null, Array(this.renderer.tileDimensions.w * valsPerTile)).map(Number.prototype.valueOf,0);
}
}
for(t in this._tiles) {
tile = this._tiles[t];
if (tile) {
@ -246,6 +247,9 @@ L.TorqueLayer = L.CanvasLayer.extend({
}
pos = this.getTilePos(tile.coord);
if(this.options.renderer !== "iso"){
ctx.setTransform(1, 0, 0, 1, pos.x, pos.y);
}
if (tile._tileCache) {
// when the tile has a cached image just render it and avoid to render
@ -253,13 +257,15 @@ L.TorqueLayer = L.CanvasLayer.extend({
ctx.setTransform(1, 0, 0, 1, pos.x, pos.y);
this.renderer._ctx.drawImage(tile._tileCache, 0, 0);
} else {
ctx.setTransform(1, 0, 0, 1, this.renderer.firstTileCoords.pos.x, this.renderer.firstTileCoords.pos.y);
if(this.options.renderer === "iso"){
ctx.setTransform(1, 0, 0, 1, this.renderer.firstTileCoords.pos.x, this.renderer.firstTileCoords.pos.y);
}
this.renderer.renderTile(tile, this.key, pos);
}
}
}
if (!tile._tileCache){
this.renderer.applyFilters();
this.renderer.postProcess();
}
}