From 3fff54baab34d7e592902a41bad478d70f9cbe4d Mon Sep 17 00:00:00 2001 From: David Larlet Date: Mon, 23 Dec 2024 12:09:16 -0500 Subject: [PATCH] fix: zoom to droped file once loaded --- umap/static/umap/js/modules/importer.js | 11 ++++++++--- umap/static/umap/js/umap.controls.js | 8 ++++---- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/umap/static/umap/js/modules/importer.js b/umap/static/umap/js/modules/importer.js index 9d1d6180..268b1d15 100644 --- a/umap/static/umap/js/modules/importer.js +++ b/umap/static/umap/js/modules/importer.js @@ -124,6 +124,11 @@ export default class Importer extends Utils.WithTemplate { return this.qs('[type=file]').files } + set files(files) { + this.qs('[type=file]').files = files + this.onFileChange() + } + get raw() { return this.qs('textarea').value } @@ -213,11 +218,11 @@ export default class Importer extends Utils.WithTemplate { this.qs('[name=submit').toggleAttribute('disabled', !this.canSubmit()) } - onFileChange(e) { + onFileChange() { let type = '' let newType - for (const file of e.target.files) { - newType = U.Utils.detectFileType(file) + for (const file of this.files) { + newType = Utils.detectFileType(file) if (!type && newType) type = newType if (type && newType !== type) { type = '' diff --git a/umap/static/umap/js/umap.controls.js b/umap/static/umap/js/umap.controls.js index 4cdcc15c..350207df 100644 --- a/umap/static/umap/js/umap.controls.js +++ b/umap/static/umap/js/umap.controls.js @@ -371,10 +371,10 @@ U.DropControl = L.Class.extend({ this.map.scrollWheelZoom.enable() this.dropzone.classList.remove('umap-dragover') L.DomEvent.stop(event) - for (const file of event.dataTransfer.files) { - this.map._umap.processFileToImport(file) - } - this.map._umap.onceDataLoaded(this.map._umap.fitDataBounds) + const importer = this.map._umap.importer + importer.build() + importer.files = event.dataTransfer.files + importer.submit() }, dragleave: function () {