From f6ef2c91229e1d09b066de98f187fbb26f2ba9e2 Mon Sep 17 00:00:00 2001 From: Vladimir Mikulic <35997844+VladimirMikulic@users.noreply.github.com> Date: Mon, 13 Jan 2020 13:00:58 -0500 Subject: [PATCH] FEATURE: Make collection export option dynamic (#523) * FEATURE: Make collection export option dynamic Resolves #522 * REFACTOR: Minor changes Changes: - New version 0.11.2 - Rollback Gruntfile changes - .images call from JSON.stringify(opts.collection.images) attached to generateExportJson --- dist/leaflet.distortableimage.js | 20 ++++++++++++++++++-- package-lock.json | 2 +- package.json | 2 +- src/edit/DistortableCollection.Edit.js | 20 ++++++++++++++++++-- 4 files changed, 38 insertions(+), 6 deletions(-) diff --git a/dist/leaflet.distortableimage.js b/dist/leaflet.distortableimage.js index b546b443e..02e374e8a 100644 --- a/dist/leaflet.distortableimage.js +++ b/dist/leaflet.distortableimage.js @@ -3040,6 +3040,10 @@ L.DistortableCollection.Edit = L.Handler.extend({ }, cancelExport: function() { + if (!this.customCollection) { + this._exportOpts.collection = undefined; + } + clearInterval(this.updateInterval); }, @@ -3116,6 +3120,11 @@ L.DistortableCollection.Edit = L.Handler.extend({ if (data.status === 'complete') { clearInterval(self.updateInterval); + + if (!self.customCollection) { + self._exportOpts.collection = undefined; + } + resolve(); if (data.jpg !== null) { alert('Export succeeded. ' + opts.exportUrl + data.jpg); @@ -3150,7 +3159,7 @@ L.DistortableCollection.Edit = L.Handler.extend({ crossDomain: true, type: 'POST', data: { - collection: JSON.stringify(opts.collection.images), + collection: JSON.stringify(opts.collection), scale: opts.scale, upload: true, }, @@ -3158,7 +3167,14 @@ L.DistortableCollection.Edit = L.Handler.extend({ }); } - opts.collection = opts.collection || this._group.generateExportJson(); + // If the user has passed collection property + if (opts.collection) { + self.customCollection = true; + } else { + self.customCollection = false; + opts.collection = this._group.generateExportJson().images; + } + opts.frequency = opts.frequency || 3000; opts.scale = opts.scale || 100; // switch it to _getAvgCmPerPixel ! opts.updater = opts.updater || _defaultUpdater; diff --git a/package-lock.json b/package-lock.json index 9239b55a4..ca356187d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "leaflet-distortableimage", - "version": "0.11.1", + "version": "0.11.2", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index e6f023a19..d42d44f37 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "leaflet-distortableimage", - "version": "0.11.1", + "version": "0.11.2", "description": "Leaflet plugin enabling image overlays to be distorted, stretched, and warped (built for Public Lab's MapKnitter: http://publiclab.org).", "scripts": { "test": "echo \"Error: no test specified\" && exit 1", diff --git a/src/edit/DistortableCollection.Edit.js b/src/edit/DistortableCollection.Edit.js index f346245ff..18917155e 100644 --- a/src/edit/DistortableCollection.Edit.js +++ b/src/edit/DistortableCollection.Edit.js @@ -199,6 +199,10 @@ L.DistortableCollection.Edit = L.Handler.extend({ }, cancelExport: function() { + if (!this.customCollection) { + this._exportOpts.collection = undefined; + } + clearInterval(this.updateInterval); }, @@ -275,6 +279,11 @@ L.DistortableCollection.Edit = L.Handler.extend({ if (data.status === 'complete') { clearInterval(self.updateInterval); + + if (!self.customCollection) { + self._exportOpts.collection = undefined; + } + resolve(); if (data.jpg !== null) { alert('Export succeeded. ' + opts.exportUrl + data.jpg); @@ -309,7 +318,7 @@ L.DistortableCollection.Edit = L.Handler.extend({ crossDomain: true, type: 'POST', data: { - collection: JSON.stringify(opts.collection.images), + collection: JSON.stringify(opts.collection), scale: opts.scale, upload: true, }, @@ -317,7 +326,14 @@ L.DistortableCollection.Edit = L.Handler.extend({ }); } - opts.collection = opts.collection || this._group.generateExportJson(); + // If the user has passed collection property + if (opts.collection) { + self.customCollection = true; + } else { + self.customCollection = false; + opts.collection = this._group.generateExportJson().images; + } + opts.frequency = opts.frequency || 3000; opts.scale = opts.scale || 100; // switch it to _getAvgCmPerPixel ! opts.updater = opts.updater || _defaultUpdater;