AnsweredAssumed Answered

Error handling if basemap is unavailable

Question asked by xavier_dupessey on Jun 3, 2014
Latest reply on Jun 6, 2014 by krobine
Hello,

I would like to create a map with several ESRI basemaps.
If one basemap is unavailable (for any reason), the application must remain available with the other basemaps.

To simulate an error, I set an invalid URL / token.


  • In this first test, I set valid parameters for the first basemap of the list and invalid parameters for the second basemap. As expected, it is still possible to navigate in the map through the first basemap.


  • [HTML]<!DOCTYPE html>
    <html>
    <head>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
      <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no">
      <title></title>

      <link rel="stylesheet" href="http://js.arcgis.com/3.2/js/esri/css/esri.css">
      <script src="http://js.arcgis.com/3.2/"></script>

      <script>
       require(['dojo/on',
         'dojo/topic',
         'dojo/parser',
         'dojo/ready',
         'dojo/domReady!'],
       function (on, topic, parser, ready) {
       
        ready(function () {

         esri.config.defaults.io.timeout = 10000;

         var map = new esri.Map("mapDiv", {
          nav: true,
          slider: true,
          sliderStyle: 'default'
         });

         dojo.connect(map, 'onLayerAddResult', function (result) {
          console.log("onLayerAddResult called");
          console.log(result);
         });

         dojo.connect(map, 'onLayersAddResult', function (results) {
          console.log("onLayersAddResult called");
          console.log(results);
         });

         map.addLayers([
          new esri.layers.ArcGISTiledMapServiceLayer(
           'http://services.esrifrance.fr/arcgis/rest/services/FranceRaster/France_FranceRaster_Premium/MapServer?token=<VALID_TOKEN>',
           { id: 'France_Raster_v4', visible: true, opacity: 1.0 }
          )
         ,
          new esri.layers.ArcGISTiledMapServiceLayer(
           'http://services.esrifrance.fr/arcgis/rest/services/IGN/France_OrthoHR/MapServer?token=<INVALID_TOKEN>',
           { id: 'France_OrthoHR', visible: false, opacity: 1.0 }
          )
         ]);

        });
       
       });
      </script>
    </head>

    <body class="claro" style="background-color: gray;">
      <div id="mapDiv"></div>
    </body>

    </html>
    [/HTML]

  • But in this second test, I set invalid information for the first basemap of the list and valid parameters for the second basemap. Here, the map is not initialized and it is impossible to use it.

  • Moreover, the callback function onLayerAddResult is called only once for the fisrt basemap and the callback function onLayersAddResult is never called.

    [HTML]<!DOCTYPE html>
    <html>
    <head>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
      <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no">
      <title></title>

      <link rel="stylesheet" href="http://js.arcgis.com/3.2/js/esri/css/esri.css">
      <script src="http://js.arcgis.com/3.2/"></script>

      <script>
       require(['dojo/on',
         'dojo/topic',
         'dojo/parser',
         'dojo/ready',
         'dojo/domReady!'],
       function (on, topic, parser, ready) {
       
        ready(function () {

         esri.config.defaults.io.timeout = 10000;

         var map = new esri.Map("mapDiv", {
          nav: true,
          slider: true,
          sliderStyle: 'default'
         });

         dojo.connect(map, 'onLayerAddResult', function (result) {
          console.log("onLayerAddResult called");
          console.log(result);
         });

         dojo.connect(map, 'onLayersAddResult', function (results) {
          console.log("onLayersAddResult called");
          console.log(results);
         });

         map.addLayers([
          new esri.layers.ArcGISTiledMapServiceLayer(
           'http://services.esrifrance.fr/arcgis/rest/services/FranceRaster/France_FranceRaster_Premium/MapServer?token=<INVALID_TOKEN>',
           { id: 'France_Raster_v4', visible: false, opacity: 1.0 }
          )
         ,
          new esri.layers.ArcGISTiledMapServiceLayer(
           'http://services.esrifrance.fr/arcgis/rest/services/IGN/France_OrthoHR/MapServer?token=<VALID_TOKEN>',
           { id: 'France_OrthoHR', visible: true, opacity: 1.0 }
          )
         ]);

        });
       
       });
      </script>
    </head>

    <body class="claro" style="background-color: gray;">
      <div id="mapDiv"></div>
    </body>

    </html>
    [/HTML]

Is it by design or is it a bug?
How can I handle errors of the first basemap of the list?

Thank you in advance.

Regards,

Outcomes