Select to view content in your preferred language

Error handling with an Arcgis Online map (javascript api 4.16)

670
1
10-02-2020 08:34 AM
by Anonymous User
Not applicable

I have an Arcgis Online map which use refreshInterval for automatic updates.

I need to intercept an event when the network goes offline or online, like it’s done in the Map Viewer with the orange triangle at the bottom left (when I put the Network to Offline with Chrome developer tools):

Error icon on Map viewer when network goes offline 

I tried to capture an error event on the map and on the layers, but it’s not working (with javascript api 4.16, in angular):

 

  const webMap = new this._WebMap({

            portalItem: {

                id: arcgisOnlineMapId

            }

        });

 

        this.mapView = new this._MapView({

            container: this.mapViewEl.nativeElement,

            map: webMap

        });

 

        await this.mapView.when();

 

  this.mapView.on('error', (error) => {

            console.error(`mapView error: ${error}`);

        });

 

        this.mapView.map.layers.on('error', (error) => {

            console.error(`layers error: ${error}`);

        });

 

How can I do that ?

Same question for an event when the network comes back.

 

Thanks !

0 Kudos
1 Reply
ReneRubalcava
Honored Contributor

This isn't really something you would check with the API. A more reliable way is to use the browsers native.onLine property and event listeners to manage this.

Navigator.onLine - Web APIs | MDN 

0 Kudos