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