loleaflet/src/layer/tile/CanvasTileLayer.js | 68 +++++++++++++--------------- 1 file changed, 33 insertions(+), 35 deletions(-)
New commits: commit a486bd5bfd98c33f093567edbbe6a88160a38050 Author: Michael Meeks <michael.me...@collabora.com> AuthorDate: Fri Aug 21 15:54:50 2020 +0100 Commit: Michael Meeks <michael.me...@collabora.com> CommitDate: Fri Aug 21 16:06:18 2020 +0100 calc tiles: share code for building bounds and panes. Avoid duplication between tileReady and paint. Change-Id: Ic3d1c22a1dbeffe1abfffd35ea0d7fbcfd5c1ccc diff --git a/loleaflet/src/layer/tile/CanvasTileLayer.js b/loleaflet/src/layer/tile/CanvasTileLayer.js index 5881803c8..244dfe1d4 100644 --- a/loleaflet/src/layer/tile/CanvasTileLayer.js +++ b/loleaflet/src/layer/tile/CanvasTileLayer.js @@ -140,38 +140,43 @@ L.CanvasTilePainter = L.Class.extend({ this._canvasCtx.restore(); }, - paint: function (tile, viewBounds, paneBoundsList) { + // Details of tile areas to render + _paintContext: function() { + var tileSize = new L.Point(this._tileSizeCSSPx, this._tileSizeCSSPx); + + var viewBounds = this._map.getPixelBounds(); + var splitPanesContext = this._layer.getSplitPanesContext(); + var paneBoundsList = splitPanesContext ? + splitPanesContext.getPxBoundList(viewBounds) : + [viewBounds]; + + return { tileSize: tileSize, + viewBounds: viewBounds, + paneBoundsList: paneBoundsList }; + }, + + paint: function (tile, ctx) { - if (this._tileSizeCSSPx === undefined) { + if (this._tileSizeCSSPx === undefined) this._tileSizeCSSPx = this._layer._getTileSize(); - } + + if (!ctx) + ctx = this._paintContext(); var tileTopLeft = tile.coords.getPos(); - var tileSize = new L.Point(this._tileSizeCSSPx, this._tileSizeCSSPx); - var tileBounds = new L.Bounds(tileTopLeft, tileTopLeft.add(tileSize)); + var tileBounds = new L.Bounds(tileTopLeft, tileTopLeft.add(ctx.tileSize)); - viewBounds = viewBounds || this._map.getPixelBounds(); - var splitPanesContext = this._layer.getSplitPanesContext(); - paneBoundsList = paneBoundsList || ( - splitPanesContext ? - splitPanesContext.getPxBoundList(viewBounds) : - [viewBounds] - ); + for (var i = 0; i < ctx.paneBoundsList.length; ++i) { + var paneBounds = ctx.paneBoundsList[i]; - for (var i = 0; i < paneBoundsList.length; ++i) { - var paneBounds = paneBoundsList[i]; - if (!paneBounds.intersects(tileBounds)) { + if (!paneBounds.intersects(tileBounds)) continue; - } var topLeft = paneBounds.getTopLeft(); - if (topLeft.x) { - topLeft.x = viewBounds.min.x; - } - - if (topLeft.y) { - topLeft.y = viewBounds.min.y; - } + if (topLeft.x) + topLeft.x = ctx.viewBounds.min.x; + if (topLeft.y) + topLeft.y = ctx.viewBounds.min.y; this._canvasCtx.save(); this._canvasCtx.scale(this._dpiScale, this._dpiScale); @@ -280,24 +285,17 @@ L.CanvasTilePainter = L.Class.extend({ var zoom = this._lastZoom || Math.round(this._map.getZoom()); var part = this._lastPart || this._layer._selectedPart; - var viewSize = new L.Point(this._width, this._height); - var viewBounds = new L.Bounds(this._topLeft, this._topLeft.add(viewSize)); - - var splitPanesContext = this._layer.getSplitPanesContext(); // Calculate all this here intead of doing it per tile. - var paneBoundsList = splitPanesContext ? - splitPanesContext.getPxBoundList(viewBounds) : [viewBounds]; - var tileRanges = paneBoundsList.map(this._layer._pxBoundsToTileRange, this._layer); - - var tileSize = this._tileSizeCSSPx || this._layer._getTileSize(); + var ctx = this._paintContext(); + var tileRanges = ctx.paneBoundsList.map(this._layer._pxBoundsToTileRange, this._layer); for (var rangeIdx = 0; rangeIdx < tileRanges.length; ++rangeIdx) { var tileRange = tileRanges[rangeIdx]; for (var j = tileRange.min.y; j <= tileRange.max.y; ++j) { for (var i = tileRange.min.x; i <= tileRange.max.x; ++i) { var coords = new L.TileCoordData( - i * tileSize, - j * tileSize, + i * ctx.tileSize, + j * ctx.tileSize, zoom, part); @@ -305,7 +303,7 @@ L.CanvasTilePainter = L.Class.extend({ var tile = this._layer._tiles[key]; var invalid = tile && tile._invalidCount && tile._invalidCount > 0; if (tile && tile.loaded && !invalid) { - this.paint(tile, viewBounds, paneBoundsList); + this.paint(tile, ctx); } } } _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits