mirror of
https://github.com/umap-project/umap.git
synced 2025-04-29 11:52:38 +02:00
fix: display a more usefull message when error in remote data (#2443)
fix #2379 
This commit is contained in:
commit
ea2bdba270
1 changed files with 19 additions and 8 deletions
|
@ -302,6 +302,19 @@ export class DataLayer extends ServerStored {
|
||||||
return this.isRemoteLayer() && Boolean(this.options.remoteData?.dynamic)
|
return this.isRemoteLayer() && Boolean(this.options.remoteData?.dynamic)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async getUrl(url) {
|
||||||
|
const response = await this._umap.request.get(url)
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
if (response?.ok) return resolve(response.text())
|
||||||
|
Alert.error(
|
||||||
|
translate('Cannot load remote data for layer "{layer}" with url "{url}"', {
|
||||||
|
layer: this.getName(),
|
||||||
|
url: url,
|
||||||
|
})
|
||||||
|
)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
async fetchRemoteData(force) {
|
async fetchRemoteData(force) {
|
||||||
if (!this.isRemoteLayer()) return
|
if (!this.isRemoteLayer()) return
|
||||||
if (!this.hasDynamicData() && this.hasDataLoaded() && !force) return
|
if (!this.hasDynamicData() && this.hasDataLoaded() && !force) return
|
||||||
|
@ -310,13 +323,12 @@ export class DataLayer extends ServerStored {
|
||||||
if (this.options.remoteData.proxy) {
|
if (this.options.remoteData.proxy) {
|
||||||
url = this._umap.proxyUrl(url, this.options.remoteData.ttl)
|
url = this._umap.proxyUrl(url, this.options.remoteData.ttl)
|
||||||
}
|
}
|
||||||
const response = await this._umap.request.get(url)
|
return await this.getUrl(url).then((raw) => {
|
||||||
if (response?.ok) {
|
|
||||||
this.clear()
|
this.clear()
|
||||||
return this._umap.formatter
|
return this._umap.formatter
|
||||||
.parse(await response.text(), this.options.remoteData.format)
|
.parse(raw, this.options.remoteData.format)
|
||||||
.then((geojson) => this.fromGeoJSON(geojson))
|
.then((geojson) => this.fromGeoJSON(geojson))
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
isLoaded() {
|
isLoaded() {
|
||||||
|
@ -541,10 +553,9 @@ export class DataLayer extends ServerStored {
|
||||||
|
|
||||||
async importFromUrl(uri, type) {
|
async importFromUrl(uri, type) {
|
||||||
uri = this._umap.renderUrl(uri)
|
uri = this._umap.renderUrl(uri)
|
||||||
const response = await this._umap.request.get(uri)
|
return await this.getUrl(uri).then((raw) => {
|
||||||
if (response?.ok) {
|
return this.importRaw(raw, type)
|
||||||
return this.importRaw(await response.text(), type)
|
})
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getColor() {
|
getColor() {
|
||||||
|
|
Loading…
Reference in a new issue