fix: zoom to droped file once loaded

This commit is contained in:
David Larlet 2024-12-23 12:09:16 -05:00
parent 49d1dbf36e
commit 3fff54baab
No known key found for this signature in database
GPG key ID: 3E2953A359E7E7BD
2 changed files with 12 additions and 7 deletions

View file

@ -124,6 +124,11 @@ export default class Importer extends Utils.WithTemplate {
return this.qs('[type=file]').files return this.qs('[type=file]').files
} }
set files(files) {
this.qs('[type=file]').files = files
this.onFileChange()
}
get raw() { get raw() {
return this.qs('textarea').value return this.qs('textarea').value
} }
@ -213,11 +218,11 @@ export default class Importer extends Utils.WithTemplate {
this.qs('[name=submit').toggleAttribute('disabled', !this.canSubmit()) this.qs('[name=submit').toggleAttribute('disabled', !this.canSubmit())
} }
onFileChange(e) { onFileChange() {
let type = '' let type = ''
let newType let newType
for (const file of e.target.files) { for (const file of this.files) {
newType = U.Utils.detectFileType(file) newType = Utils.detectFileType(file)
if (!type && newType) type = newType if (!type && newType) type = newType
if (type && newType !== type) { if (type && newType !== type) {
type = '' type = ''

View file

@ -371,10 +371,10 @@ U.DropControl = L.Class.extend({
this.map.scrollWheelZoom.enable() this.map.scrollWheelZoom.enable()
this.dropzone.classList.remove('umap-dragover') this.dropzone.classList.remove('umap-dragover')
L.DomEvent.stop(event) L.DomEvent.stop(event)
for (const file of event.dataTransfer.files) { const importer = this.map._umap.importer
this.map._umap.processFileToImport(file) importer.build()
} importer.files = event.dataTransfer.files
this.map._umap.onceDataLoaded(this.map._umap.fitDataBounds) importer.submit()
}, },
dragleave: function () { dragleave: function () {