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

Jan Holesovsky kendy at collabora.com
Thu Jan 7 13:56:34 PST 2016


 loleaflet/src/control/Control.Zoom.js         |   11 +++++++++++
 loleaflet/src/layer/tile/TileLayer.js         |   20 +++++++++-----------
 loleaflet/src/map/Map.js                      |   10 +++++-----
 loleaflet/src/map/handler/Map.FileInserter.js |    3 +--
 4 files changed, 26 insertions(+), 18 deletions(-)

New commits:
commit 4c3896c32ea1e92b2306c4c759aeccb809a35d68
Author: Jan Holesovsky <kendy at collabora.com>
Date:   Thu Jan 7 21:52:19 2016 +0100

    loleaflet: No need to use the last zoom in fitWithZoom().
    
    This makes it a stable algorithm.
    
    This reverts commit 749d707c2f2be64424c0f3f9e105f90e22592a41.

diff --git a/loleaflet/src/layer/tile/TileLayer.js b/loleaflet/src/layer/tile/TileLayer.js
index 5e2ded1..bc05cac 100644
--- a/loleaflet/src/layer/tile/TileLayer.js
+++ b/loleaflet/src/layer/tile/TileLayer.js
@@ -934,20 +934,19 @@ L.TileLayer = L.GridLayer.extend({
 
 	_fitWidthZoom: function (e, maxZoom) {
 		var size = e ? e.newSize : this._map.getSize();
+		var widthTwips = size.x * this._map.options.tileWidthTwips / this._tileSize;
 		maxZoom = maxZoom ? maxZoom : this._map.options.zoom;
 		if (this._docType !== 'spreadsheet' || !e) {
 			// If it's not a spreadsheet or the method has been invoked manually
 			var crsScale = this._map.options.crs.scale(1);
-			if (size.x / this._docPixelSize.x > crsScale) {
-				// we could zoom in
-				var ratio = size.x / this._docPixelSize.x;
-				var zoomDelta = Math.ceil(Math.log(ratio) / Math.log(crsScale));
-				this._map.setZoom(Math.min(maxZoom, this._map.getZoom() + zoomDelta), {animate: false});
-			}
-			if (this._docPixelSize.x > size.x) {
-				ratio = this._docPixelSize.x / size.x;
-				zoomDelta = Math.ceil(Math.log(ratio) / Math.log(crsScale));
-				this._map.setZoom(Math.max(1, this._map.getZoom() - zoomDelta), {animate: false});
+			if (this._docWidthTwips > 0)
+			{
+				var ratio = widthTwips / this._docWidthTwips;
+				var zoom = this._map.options.zoom + Math.floor(Math.log(ratio) / Math.log(crsScale));
+
+				zoom = Math.max(1, zoom);
+				zoom = Math.min(maxZoom, zoom);
+				this._map.setZoom(zoom, {animate: false});
 			}
 		}
 	},
commit f3778421b1d5c4695f8ad42d648aa97c310ae3cb
Author: Ozcan Esen <ozcan.esen at collabora.com>
Date:   Wed Jan 6 12:33:51 2016 +0200

    loleaflet: fix fitWidthZoom inconsistency
    
    Change-Id: I511112d05de2b2734d7d2b2f905a3ba797dcca5f

diff --git a/loleaflet/src/layer/tile/TileLayer.js b/loleaflet/src/layer/tile/TileLayer.js
index b22a0df..5e2ded1 100644
--- a/loleaflet/src/layer/tile/TileLayer.js
+++ b/loleaflet/src/layer/tile/TileLayer.js
@@ -938,16 +938,16 @@ L.TileLayer = L.GridLayer.extend({
 		if (this._docType !== 'spreadsheet' || !e) {
 			// If it's not a spreadsheet or the method has been invoked manually
 			var crsScale = this._map.options.crs.scale(1);
-			if (this._docPixelSize.x > size.x) {
-				var ratio = this._docPixelSize.x / size.x;
+			if (size.x / this._docPixelSize.x > crsScale) {
+				// we could zoom in
+				var ratio = size.x / this._docPixelSize.x;
 				var zoomDelta = Math.ceil(Math.log(ratio) / Math.log(crsScale));
-				this._map.setZoom(Math.max(1, this._map.getZoom() - zoomDelta), {animate: false});
+				this._map.setZoom(Math.min(maxZoom, this._map.getZoom() + zoomDelta), {animate: false});
 			}
-			else if (size.x / this._docPixelSize.x > crsScale) {
-				// we could zoom in
-				ratio = size.x / this._docPixelSize.x;
+			if (this._docPixelSize.x > size.x) {
+				ratio = this._docPixelSize.x / size.x;
 				zoomDelta = Math.ceil(Math.log(ratio) / Math.log(crsScale));
-				this._map.setZoom(Math.min(maxZoom, this._map.getZoom() + zoomDelta), {animate: false});
+				this._map.setZoom(Math.max(1, this._map.getZoom() - zoomDelta), {animate: false});
 			}
 		}
 	},
commit 07a3b6994e5143c0a6c5a3df946c6ec456114109
Author: Jan Holesovsky <kendy at collabora.com>
Date:   Thu Jan 7 17:49:52 2016 +0100

    loleaflet: Add a button for testing fitWidthZoom().

diff --git a/loleaflet/src/control/Control.Zoom.js b/loleaflet/src/control/Control.Zoom.js
index 2d550a9..407a25b 100644
--- a/loleaflet/src/control/Control.Zoom.js
+++ b/loleaflet/src/control/Control.Zoom.js
@@ -7,6 +7,8 @@ L.Control.Zoom = L.Control.extend({
 		position: 'topleft',
 		zoomInText: '+',
 		zoomInTitle: 'Zoom in',
+		fitWidthText: '↔',
+		fitWidthTitle: 'Fit Width',
 		zoomOutText: '-',
 		zoomOutTitle: 'Zoom out'
 	},
@@ -18,6 +20,8 @@ L.Control.Zoom = L.Control.extend({
 
 		this._zoomInButton  = this._createButton(options.zoomInText, options.zoomInTitle,
 		        zoomName + '-in',  container, this._zoomIn);
+		this._fitWidthButton  = this._createButton(options.fitWidthText, options.fitWidthTitle,
+		        zoomName + '-fitwidth',  container, this._fitWidth);
 		this._zoomOutButton = this._createButton(options.zoomOutText, options.zoomOutTitle,
 		        zoomName + '-out', container, this._zoomOut);
 
@@ -49,6 +53,12 @@ L.Control.Zoom = L.Control.extend({
 		}
 	},
 
+	_fitWidth: function (e) {
+		if (!this._disabled) {
+			this._map.fitWidthZoom();
+		}
+	},
+
 	_zoomOut: function (e) {
 		if (!this._disabled) {
 			this._map.zoomOut(e.shiftKey ? 3 : 1);
@@ -75,6 +85,7 @@ L.Control.Zoom = L.Control.extend({
 			className = 'leaflet-disabled';
 
 		L.DomUtil.removeClass(this._zoomInButton, className);
+		L.DomUtil.removeClass(this._fitWidthButton, className);
 		L.DomUtil.removeClass(this._zoomOutButton, className);
 
 		if (this._disabled || map._zoom === map.getMinZoom()) {
commit 1d992852941799c7b56279bf53ce9f7517e8d134
Author: Jan Holesovsky <kendy at collabora.com>
Date:   Thu Jan 7 17:56:13 2016 +0100

    loleaflet: One more place that needs options.webserver.

diff --git a/loleaflet/src/layer/tile/TileLayer.js b/loleaflet/src/layer/tile/TileLayer.js
index 8425cad..b22a0df 100644
--- a/loleaflet/src/layer/tile/TileLayer.js
+++ b/loleaflet/src/layer/tile/TileLayer.js
@@ -330,7 +330,6 @@ L.TileLayer = L.GridLayer.extend({
 	_onDownloadAsMsg: function (textMsg) {
 		var command = L.Socket.parseServerCmd(textMsg);
 		var parser = document.createElement('a');
-		var protocol = window.location.protocol === 'file:' ? 'http:' : window.location.protocol;
 		parser.href = this._map.options.server;
 		var url = this._map.options.webserver + '/' +
 			command.jail + '/' + command.dir + '/' + command.name;
diff --git a/loleaflet/src/map/Map.js b/loleaflet/src/map/Map.js
index f7f3664..4a90e4e 100644
--- a/loleaflet/src/map/Map.js
+++ b/loleaflet/src/map/Map.js
@@ -46,6 +46,11 @@ L.Map = L.Evented.extend({
 			this.setView(L.latLng(options.center), options.zoom, {reset: true});
 		}
 
+		if (options.webserver === undefined) {
+			var protocol = window.location.protocol === 'file:' ? 'http:' : window.location.protocol;
+			options.webserver = options.server.replace(/^ws:/i, protocol);
+		}
+
 		this._handlers = [];
 		this._layers = {};
 		this._zoomBoundLayers = {};
@@ -60,11 +65,6 @@ L.Map = L.Evented.extend({
 		this._addLayers(this.options.layers);
 		L.Socket.connect(this);
 
-		if (options.webserver === undefined) {
-			var protocol = window.location.protocol === 'file:' ? 'http:' : window.location.protocol;
-			options.webserver = options.server.replace(/^ws:/i, protocol);
-		}
-
 		// Inhibit the context menu - the browser thinks that the document
 		// is just a bunch of images, hence the context menu is useless (tdf#94599)
 		this.on('contextmenu', function() {});
diff --git a/loleaflet/src/map/handler/Map.FileInserter.js b/loleaflet/src/map/handler/Map.FileInserter.js
index 4748186..e95050d 100644
--- a/loleaflet/src/map/handler/Map.FileInserter.js
+++ b/loleaflet/src/map/handler/Map.FileInserter.js
@@ -13,9 +13,8 @@ L.Map.FileInserter = L.Handler.extend({
 		this._childId = null;
 		this._toInsert = {};
 		var parser = document.createElement('a');
-		var protocol = window.location.protocol === 'file:' ? 'http:' : window.location.protocol;
 		parser.href = map.options.server;
-		this._url = protocol + '//' + parser.hostname + ':' + parser.port + '/insertfile';
+		this._url = map.options.webserver + '/insertfile';
 	},
 
 	addHooks: function () {


More information about the Libreoffice-commits mailing list