Merge pull request #1669 from umap-project/make-remodata-async

fix: make sure we wait for remote data before sending "dataloaded" event
This commit is contained in:
Yohan Boniface 2024-03-12 09:15:12 +01:00 committed by GitHub
commit d431acd4e3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -688,7 +688,7 @@ U.DataLayer = L.Evented.extend({
} }
// In case of maps pre 1.0 still around // In case of maps pre 1.0 still around
if (geojson._storage) geojson._storage.editMode = this.options.editMode if (geojson._storage) geojson._storage.editMode = this.options.editMode
this.fromUmapGeoJSON(geojson) await this.fromUmapGeoJSON(geojson)
this.backupOptions() this.backupOptions()
this.fire('loaded') this.fire('loaded')
this._loading = false this._loading = false
@ -703,10 +703,10 @@ U.DataLayer = L.Evented.extend({
this.fire('datachanged') this.fire('datachanged')
}, },
fromUmapGeoJSON: function (geojson) { fromUmapGeoJSON: async function (geojson) {
if (geojson._storage) geojson._umap_options = geojson._storage // Retrocompat if (geojson._storage) geojson._umap_options = geojson._storage // Retrocompat
if (geojson._umap_options) this.setOptions(geojson._umap_options) if (geojson._umap_options) this.setOptions(geojson._umap_options)
if (this.isRemoteLayer()) this.fetchRemoteData() if (this.isRemoteLayer()) await this.fetchRemoteData()
else this.fromGeoJSON(geojson) else this.fromGeoJSON(geojson)
this._loaded = true this._loaded = true
}, },