Basemap Load Failure

2026
6
04-14-2023 08:08 AM
MichaelWen_Timmons
Occasional Contributor

I saw a few, similar threads from a few years back that went unanswered so want to see if there's a solution now.

https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/empty-basemap-not-working/m-p/619...

I am trying to capture when a mapview's default basemap fails to load. If that happens I want to switch to a backup. Right now if the default basemap is down the whole application crashes.

I tried this but nothing is caught. In fact the 'when' never got run when the first basemap fails to load.

this.view.when(    ).catch()

 

This does not work for basemaps. 

  this.view.on("layerview-create-error", function(event) {

    console.error("LayerView failed to create for layer with the id: ", event.layer.id);

  });

Is there anything else that I can try?

 

0 Kudos
6 Replies
ReneRubalcava
Honored Contributor

The Basemap, and other layers,  have a load props you can check.

https://developers.arcgis.com/javascript/latest/api-reference/esri-Basemap.html#loadError

https://developers.arcgis.com/javascript/latest/api-reference/esri-Basemap.html#loadStatus

https://developers.arcgis.com/javascript/latest/api-reference/esri-Basemap.html#loadWarnings

You could do something like this.

 

view.when(() => {
    console.log("Check basemap error status", view.map.basemap.loadError)
});

 

0 Kudos
MichaelWen_Timmons
Occasional Contributor

I don't think this would work because view.when(() would not even fire if the basemap layer fails to load.

 

0 Kudos
ReneRubalcava
Honored Contributor

You can use reactiveUtils to watch those properties. I don't really have a way to check a bad basemap, but that would be the next step to try.

https://developers.arcgis.com/javascript/latest/api-reference/esri-core-reactiveUtils.html

0 Kudos
MichaelWen_Timmons
Occasional Contributor

I already tried it. That does not really resolve it for us because the application crashes if the default basemap fails to load, so we won't even get a chance to watch for the property change.

0 Kudos
MichaelWen_Timmons
Occasional Contributor

Is there a way for me to create a 'blank' basemap that I can use as a default, and after mapView is generated, switch to the real default if that layer loaded correctly? I tried creating a default basemap by passing a '' url but that threw an error as well.

 

0 Kudos
MichaelWen_Timmons
Occasional Contributor

Can someone please help? I tried using a USGS and ESRI basemap as the default but it messes up the zoom level of the mapView. I REALLY need to find a way to default to a blank basemap. I've already tried using '' as the url and TileLayer as the type, but it errors out. What is the correct way to create a BLANK basemap?

0 Kudos