mirror of
https://github.com/umap-project/umap.git
synced 2025-04-29 11:52:38 +02:00
wip: make Map.initialize async
We want to be able to await function there. Specifically, we want to await the data creation when it comes from the `data` url param, so when we also consume the `feature` url param, that feature is already on the map so we can open it
This commit is contained in:
parent
49db1f9aaa
commit
cc6ae95371
1 changed files with 23 additions and 19 deletions
|
@ -29,7 +29,7 @@ L.Map.mergeOptions({
|
|||
U.Map = L.Map.extend({
|
||||
includes: [ControlsMixin],
|
||||
|
||||
initialize: function (el, geojson) {
|
||||
initialize: async function (el, geojson) {
|
||||
this.sync_engine = new U.SyncEngine(this)
|
||||
this.sync = this.sync_engine.proxy(this)
|
||||
// Locale name (pt_PT, en_US…)
|
||||
|
@ -176,23 +176,7 @@ U.Map = L.Map.extend({
|
|||
}
|
||||
this._default_extent = true
|
||||
this.options.name = L._('Untitled map')
|
||||
let data = L.Util.queryString('data', null)
|
||||
const url = new URL(window.location.href)
|
||||
const dataUrls = new URLSearchParams(url.search).getAll('dataUrl')
|
||||
const dataFormat = L.Util.queryString('dataFormat', 'geojson')
|
||||
if (dataUrls.length) {
|
||||
for (let dataUrl of dataUrls) {
|
||||
dataUrl = decodeURIComponent(dataUrl)
|
||||
dataUrl = this.localizeUrl(dataUrl)
|
||||
dataUrl = this.proxyUrl(dataUrl)
|
||||
const datalayer = this.createDataLayer()
|
||||
datalayer.importFromUrl(dataUrl, dataFormat)
|
||||
}
|
||||
} else if (data) {
|
||||
data = decodeURIComponent(data)
|
||||
const datalayer = this.createDataLayer()
|
||||
datalayer.importRaw(data, dataFormat)
|
||||
}
|
||||
await this.loadDataFromQueryString()
|
||||
}
|
||||
|
||||
this.slideshow = new U.Slideshow(this, this.options.slideshow)
|
||||
|
@ -297,7 +281,27 @@ U.Map = L.Map.extend({
|
|||
}
|
||||
},
|
||||
|
||||
setViewFromQueryString: function () {
|
||||
loadDataFromQueryString: async function() {
|
||||
let data = L.Util.queryString('data', null)
|
||||
const url = new URL(window.location.href)
|
||||
const dataUrls = new URLSearchParams(url.search).getAll('dataUrl')
|
||||
const dataFormat = L.Util.queryString('dataFormat', 'geojson')
|
||||
if (dataUrls.length) {
|
||||
for (let dataUrl of dataUrls) {
|
||||
dataUrl = decodeURIComponent(dataUrl)
|
||||
dataUrl = this.localizeUrl(dataUrl)
|
||||
dataUrl = this.proxyUrl(dataUrl)
|
||||
const datalayer = this.createDataLayer()
|
||||
await datalayer.importFromUrl(dataUrl, dataFormat)
|
||||
}
|
||||
} else if (data) {
|
||||
data = decodeURIComponent(data)
|
||||
const datalayer = this.createDataLayer()
|
||||
await datalayer.importRaw(data, dataFormat)
|
||||
}
|
||||
},
|
||||
|
||||
setViewFromQueryString: async function () {
|
||||
if (this.options.noControl) return
|
||||
this.initCaptionBar()
|
||||
if (L.Util.queryString('share')) {
|
||||
|
|
Loading…
Reference in a new issue