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

Mihai Varga mihai.varga at collabora.com
Fri Jul 17 02:59:26 PDT 2015


 loleaflet/src/layer/tile/GridLayer.js |   54 +++++++++++++++++++++++++++-------
 loleaflet/src/layer/tile/TileLayer.js |   10 +++++-
 2 files changed, 53 insertions(+), 11 deletions(-)

New commits:
commit f0f88381ca6fcd4ab413931a1f21f52cb574698f
Author: Mihai Varga <mihai.varga at collabora.com>
Date:   Fri Jul 17 12:42:54 2015 +0300

    loleaflet: prefetching from other parts causes too much invalidation

diff --git a/loleaflet/src/layer/tile/TileLayer.js b/loleaflet/src/layer/tile/TileLayer.js
index 371c5ef..ba76534 100644
--- a/loleaflet/src/layer/tile/TileLayer.js
+++ b/loleaflet/src/layer/tile/TileLayer.js
@@ -24,7 +24,8 @@ L.TileLayer = L.GridLayer.extend({
 		tms: false,
 		zoomReverse: false,
 		detectRetina: false,
-		crossOrigin: false
+		crossOrigin: false,
+		preFetchOtherParts: false
 	},
 
 	initialize: function (url, options) {
commit 5aff27e3ce1cd3137178eb9a44681022bf489b3a
Author: Mihai Varga <mihai.varga at collabora.com>
Date:   Fri Jul 17 12:42:14 2015 +0300

    loleaflet: code to prefetch tiles from other parts

diff --git a/loleaflet/src/layer/tile/GridLayer.js b/loleaflet/src/layer/tile/GridLayer.js
index b8f6f5c..96b510c 100644
--- a/loleaflet/src/layer/tile/GridLayer.js
+++ b/loleaflet/src/layer/tile/GridLayer.js
@@ -245,8 +245,8 @@ L.GridLayer = L.Layer.extend({
 			tile = this._tiles[key];
 			if (tile.current && !tile.active) {
 				var coords = tile.coords;
-				if (!this._retainParent(coords.x, coords.y, coords.z, coords.z - 5)) {
-					this._retainChildren(coords.x, coords.y, coords.z, coords.z + 2);
+				if (!this._retainParent(coords.x, coords.y, coords.z, coords.part, coords.z - 5)) {
+					this._retainChildren(coords.x, coords.y, coords.z, coords.part, coords.z + 2);
 				}
 			}
 		}
@@ -264,12 +264,12 @@ L.GridLayer = L.Layer.extend({
 		}
 	},
 
-	_retainParent: function (x, y, z, minZoom) {
+	_retainParent: function (x, y, z, part, minZoom) {
 		var x2 = Math.floor(x / 1.2),
 			y2 = Math.floor(y / 1.2),
 			z2 = z - 1;
 
-		var key = x2 + ':' + y2 + ':' + z2 + ':' + this._currentPart,
+		var key = x2 + ':' + y2 + ':' + z2 + ':' + part,
 			tile = this._tiles[key];
 
 		if (tile && tile.active) {
@@ -281,19 +281,19 @@ L.GridLayer = L.Layer.extend({
 		}
 
 		if (z2 > minZoom) {
-			return this._retainParent(x2, y2, z2, minZoom);
+			return this._retainParent(x2, y2, z2, part, minZoom);
 		}
 
 		return false;
 	},
 
-	_retainChildren: function (x, y, z, maxZoom) {
+	_retainChildren: function (x, y, z, part, maxZoom) {
 
 		for (var i = 1.2 * x; i < 1.2 * x + 2; i++) {
 			for (var j = 1.2 * y; j < 1.2 * y + 2; j++) {
 
 				var key = Math.floor(i) + ':' + Math.floor(j) + ':' +
-					(z + 1) + ':' + this._currentPart,
+					(z + 1) + ':' + part,
 					tile = this._tiles[key];
 
 				if (tile && tile.active) {
@@ -305,7 +305,7 @@ L.GridLayer = L.Layer.extend({
 				}
 
 				if (z + 1 < maxZoom) {
-					this._retainChildren(i, j, z + 1, maxZoom);
+					this._retainChildren(i, j, z + 1, part, maxZoom);
 				}
 			}
 		}
@@ -664,7 +664,7 @@ L.GridLayer = L.Layer.extend({
 				var twips = this._coordsToTwips(coords);
 				this._pendingTilesCount += 1;
 				this.sendMessage('tile ' +
-								'part=' + this._currentPart + ' ' +
+								'part=' + coords.part + ' ' +
 								'width=' + this._tileSize + ' ' +
 								'height=' + this._tileSize + ' ' +
 								'tileposx=' + twips.x + ' '	+
@@ -846,7 +846,7 @@ L.GridLayer = L.Layer.extend({
 			for (i = 0; i < queue.length && tilesToFetch > 0; i++) {
 				coords = queue[i];
 				coords.z = zoom;
-				coords.part = this._currentPart;
+				coords.part = this._preFetchPart;
 				var key = this._tileCoordsToKey(coords);
 
 				if (!this._isValidTile(coords) ||
@@ -878,6 +878,40 @@ L.GridLayer = L.Layer.extend({
 				tileBorder.max.y += 1;
 			}
 			borderWidth += 1;
+			if (!(tileBorder.min.x >= 0 || tileBorder.min.y >= 0 ||
+					tileBorder.max.x * this._tileWidthTwips < this._docWidthTwips ||
+					 tileBorder.max.y * this._tileHeightTwips < this._docHeightTwips) &&
+					this.options.preFetchOtherParts) {
+				var diff = this._preFetchPart - this._currentPart;
+				if (diff === 0 && this._currentPart < this._parts - 1) {
+					this._preFetchPart += 1;
+					this._preFetchBorder = null;
+				}
+				else if (diff > 0) {
+					if (this._currentPart - diff >= 0) {
+						// lower part number
+						this._preFetchPart = this._currentPart - diff;
+						this._preFetchBorder = null;
+					}
+					else if (this._currentPart + diff + 1 < this._parts) {
+						// higher part number
+						this._preFetchPart = this._currentPart + diff + 1;
+						this._preFetchBorder = null;
+					}
+				}
+				else if (diff < 0) {
+					if (this._currentPart - diff + 1 < this._parts) {
+						// higher part number
+						this._preFetchPart = this._currentPart - diff + 1;
+						this._preFetchBorder = null;
+					}
+					else if (this._currentPart + diff - 1 >= 0) {
+						// lower part number
+						this._preFetchPart = this._currentPart + diff - 1;
+						this._preFetchBorder = null;
+					}
+				}
+			}
 		}
 
 		if (finalQueue.length > 0) {
commit 369993b6ca3957a6cef709dc8e63860883c2e6cf
Author: Mihai Varga <mihai.varga at collabora.com>
Date:   Fri Jul 17 12:36:00 2015 +0300

    loleaflet: don't invalidate tiles from other parts

diff --git a/loleaflet/src/layer/tile/TileLayer.js b/loleaflet/src/layer/tile/TileLayer.js
index 7efd7ce..371c5ef 100644
--- a/loleaflet/src/layer/tile/TileLayer.js
+++ b/loleaflet/src/layer/tile/TileLayer.js
@@ -280,6 +280,9 @@ L.TileLayer = L.GridLayer.extend({
 				// compute the rectangle that each tile covers in the document based
 				// on the zoom level
 				coords = this._keyToTileCoords(key);
+				if (coords.part !== this._currentPart) {
+					continue;
+				}
 				var scale = this._map.getZoomScale(coords.z);
 				topLeftTwips = new L.Point(
 						this.options.tileWidthTwips / scale * coords.x,
@@ -320,6 +323,10 @@ L.TileLayer = L.GridLayer.extend({
 					partNames: partNames
 				});
 				this._update();
+				if (this._preFetchPart !== this._currentPart) {
+					this._preFetchPart = this._currentPart;
+					this._preFetchBorder = null;
+				}
 				if (!this._tilesPreFetcher) {
 					this._tilesPreFetcher = setInterval(L.bind(this._preFetchTiles, this), 2000);
 				}


More information about the Libreoffice-commits mailing list