[Libreoffice-commits] online.git: loleaflet/src

Dennis Francis (via logerrit) logerrit at kemper.freedesktop.org
Wed Jul 15 12:15:32 UTC 2020


 loleaflet/src/layer/tile/CalcTileLayer.js   |   10 ++--------
 loleaflet/src/layer/tile/CanvasTileLayer.js |    7 +++++++
 loleaflet/src/layer/tile/GridLayer.js       |   22 ++++++++++++++++++++++
 3 files changed, 31 insertions(+), 8 deletions(-)

New commits:
commit 63c4e730e44a0cfc4635da074a4edb454b3b7281
Author:     Dennis Francis <dennis.francis at collabora.com>
AuthorDate: Tue Jul 14 17:55:12 2020 +0530
Commit:     Dennis Francis <dennis.francis at collabora.com>
CommitDate: Wed Jul 15 14:15:12 2020 +0200

    factor out "tile-area for zoom" calculation code...
    
    to coordsToPixBounds() and coordsToTwipsBoundsAtZoom() in GridLayer and
    specialize coordsToPixBounds() for CanvasTileLayer because it stores
    tile position in css pixels instead of grid indices.
    
    Change-Id: I9875a29fe0244717a6f324348ff144c434809ed2
    Reviewed-on: https://gerrit.libreoffice.org/c/online/+/98781
    Tested-by: Jenkins
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice at gmail.com>
    Reviewed-by: Dennis Francis <dennis.francis at collabora.com>

diff --git a/loleaflet/src/layer/tile/CalcTileLayer.js b/loleaflet/src/layer/tile/CalcTileLayer.js
index b9ba2674c..589c94369 100644
--- a/loleaflet/src/layer/tile/CalcTileLayer.js
+++ b/loleaflet/src/layer/tile/CalcTileLayer.js
@@ -426,14 +426,8 @@ L.CalcTileLayer = (L.Browser.mobile ? L.TileLayer : L.CanvasTileLayer).extend({
 			if (coords.part !== command.part) {
 				continue;
 			}
-			var scale = this._map.getZoomScale(coords.z);
-			topLeftTwips = new L.Point(
-					this.options.tileWidthTwips / scale * coords.x,
-					this.options.tileHeightTwips / scale * coords.y);
-			bottomRightTwips = topLeftTwips.add(new L.Point(
-					this.options.tileWidthTwips / scale,
-					this.options.tileHeightTwips / scale));
-			bounds = new L.Bounds(topLeftTwips, bottomRightTwips);
+
+			bounds = this._coordsToTwipsBoundsAtZoom(coords, this._map.getZoom());
 			if (invalidBounds.intersects(bounds)) {
 				delete this._tileCache[key];
 			}
diff --git a/loleaflet/src/layer/tile/CanvasTileLayer.js b/loleaflet/src/layer/tile/CanvasTileLayer.js
index 75750ace2..214dc5b54 100644
--- a/loleaflet/src/layer/tile/CanvasTileLayer.js
+++ b/loleaflet/src/layer/tile/CanvasTileLayer.js
@@ -1333,6 +1333,13 @@ L.CanvasTileLayer = L.TileLayer.extend({
 		this._map._socket.sendMessage('tileprocessed tile=' + tileID);
 	},
 
+	_coordsToPixBounds: function (coords) {
+		// coords.x and coords.y are the pixel coordinates of the top-left corner of the tile.
+		var topLeft = new L.Point(coords.x, coords.y);
+		var bottomRight = topLeft.add(new L.Point(this._tileSize, this._tileSize));
+		return new L.Bounds(topLeft, bottomRight);
+	},
+
 	updateHorizPaneSplitter: function () {
 
 		var map = this._map;
diff --git a/loleaflet/src/layer/tile/GridLayer.js b/loleaflet/src/layer/tile/GridLayer.js
index 6c52eac86..cd4f5eda2 100644
--- a/loleaflet/src/layer/tile/GridLayer.js
+++ b/loleaflet/src/layer/tile/GridLayer.js
@@ -1305,6 +1305,28 @@ L.GridLayer = L.Layer.extend({
 		}, this), idleTime);
 	},
 
+	_coordsToPixBounds: function (coords) {
+		// coords.x and coords.y are the grid indices of the tile.
+		var topLeft = new L.Point(coords.x, coords.y)._multiplyBy(this._tileSize);
+		var bottomRight = topLeft.add(new L.Point(this._tileSize, this._tileSize));
+		return new L.Bounds(topLeft, bottomRight);
+	},
+
+	_coordsToTwipsBoundsAtZoom: function (coords, zoom) {
+		console.assert(typeof zoom === 'number', 'invalid zoom');
+		// FIXME: this is highly inaccurate for tiles near the bottom/right when zoom != coords.z.
+		// Use sheet geometry data instead (but will need to pre-compute tiletwips positions in
+		// L.SheetDimension for at least the recently used zoom levels to avoid a linear scan of its spans.)
+		var scale = this._map.getZoomScale(coords.z, zoom);
+		var pxBounds = this._coordsToPixBounds(coords);
+		pxBounds.min._divideBy(scale);
+		pxBounds.max._divideBy(scale);
+
+		var topLeftTwips = this._pixelsToTwips(pxBounds.min);
+		var bottomRightTwips = this._pixelsToTwips(pxBounds.max);
+		return new L.Bounds(topLeftTwips, bottomRightTwips);
+	},
+
 	getMaxDocSize: function () {
 		return undefined;
 	},


More information about the Libreoffice-commits mailing list