AnsweredAssumed Answered

Check if service is online before running multiple source identifyTask API 4.X

Question asked by cpl09c_FREAC on Sep 13, 2018
Latest reply on Sep 20, 2018 by rscheitlin

I have a multiple source IdentifyTask that I am running on a map click. It has come to light that some of the services that I am calling on go offline during night time hours. If the services go offline, the current IdentifyTask breaks. I am trying to find a way to:

a) check if services are offline before running IdentifyTask

b) modify the IdentifyTask to exclude any offline services so it will still complete a partial identify

 

Here is the sample that I am currently working with:

 

<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no">
  <title>IdentifyTask - 4.6</title>

  <style>
    html,
    body,
    #viewDiv
{
      padding: 0;
      margin: 0;
      height: 100%;
      width: 100%;
    }

    .esri-popup .esri-popup-header .esri-title {
      font-size: 18px;
      font-weight: bolder;
    }

    .esri-popup .esri-popup-body .esri-popup-content {
      font-size: 14px;
    }
  </style>


  <link rel="stylesheet" href="https://js.arcgis.com/4.6/esri/css/main.css">
  <script src="https://js.arcgis.com/4.6/"></script>

  <script>
    var promises, tasks;
    require([
      "esri/Map",
      "esri/views/MapView",
      "esri/layers/TileLayer",
      "esri/layers/FeatureLayer",
      "esri/tasks/IdentifyTask",
      "esri/tasks/support/IdentifyParameters",
      "dojo/_base/array",
      "dojo/on",
      "dojo/dom",
      "dojo/promise/all",
      "dojo/domReady!"
    ], function(
      Map, MapView, TileLayer, FeatureLayer,
      IdentifyTask, IdentifyParameters,
      arrayUtils, on, dom, all
    ) {

      var identifyTask, params;

      var NGSpopupTemplate = {
        title: 'NGS Control Points: {objectid}',
        content: "<p>(Latitude, Longitude): {dec_lat}, {dec_long}</p>" +
          "<p>County: {county}</p>" +
          "<p>PID: {pid}</p>" +
          "<p>Data Source: <a target='_blank' href={data_srce}>here</a></p>" +
          "<p>Datasheet: <a href={datasheet2}>here</a></p>",
        actions: [{
          title: "Visit NGS website",
          id: "ngsWebsite",
          className: "esri-icon-launch-link-external"
        }]
      };

      // URL to the map service where the identify will be performed
      var soilURL =
        "https://services.arcgisonline.com/arcgis/rest/services/Specialty/Soil_Survey_Map/MapServer";

      // Add the map service as a TileLayer for fast rendering
      // Tile layers are composed of non-interactive images. For that reason we'll
      // use IdentifyTask to query the service to add interactivity to the app
      var parcelsLyr = new TileLayer({
        url: soilURL,
        opacity: 0.85
      });

      var controlPointsURL = "https://admin205.ispa.fsu.edu/arcgis/rest/services/LABINS/Control_Points_3857/MapServer"
      var controlPointsLayer = new FeatureLayer({
        url: controlPointsURL,
        title: "NGS Control Points",
        visible: true,
        //listMode: "hide",
        //popupTemplate: NGSpopupTemplate

      });

      var map = new Map({
        basemap: "osm"
      });
      //map.add(parcelsLyr);
      map.add(parcelsLyr);
      map.add(controlPointsLayer);


      var view = new MapView({
        map: map,
        container: "viewDiv",
        center: [-82.5018310546875, 29.559123451577964],
        zoom: 7
      });

      var identifyElements = [];
      var tasks, allParams
     
      view.when(function() {
        tasks = [];
        allParams = [];


        //Set the tasks array
        tasks.push(new IdentifyTask(soilURL));
        tasks.push(new IdentifyTask(controlPointsURL));

        // Set the parameters for the Identify
        params = new IdentifyParameters();
        params.tolerance = 3;
        params.layerIds = [0, 1, 2];
        params.layerOption = "all";
        params.width = view.width;
        params.height = view.height;
        params.returnGeometry = true;
        allParams.push(params);

        // Set the parameters for the Identify
        params = new IdentifyParameters();
        params.tolerance = 5;
        params.layerIds = [0];
        params.layerOption = "all";
        params.width = view.width;
        params.height = view.height;
        params.returnGeometry = true;
        allParams.push(params);

        // executeIdentifyTask() is called each time the view is clicked
        on(view, "click", executeIdentifyTask);
      });

      // Executes each time the view is clicked
      function executeIdentifyTask(event) {
        var identifyElements = [];
        var promises = [];
        // Set the geometry to the location of the view click
        allParams[0].geometry = allParams[1].geometry = event.mapPoint;
        allParams[0].mapExtent = allParams[1].mapExtent = view.extent;
        for (i = 0; i < tasks.length; i++) {
          promises.push(tasks[i].execute(allParams[i]));
        }
        var iPromises = new all(promises);

        iPromises.then(function (rArray) {
          arrayUtils.map(rArray, function(response){
            var results = response.results;
            return arrayUtils.map(results, function(result) {
              var feature = result.feature;
              var layerName = result.layerName;

              feature.attributes.layerName = layerName;
              identifyElements.push(feature);
            });
          })
          console.log(identifyElements);
        });
      }
    });
  </script>

</head>

<body>
  <div id="viewDiv"></div>
</body>

</html>

 

 

 

Thank you for your time, 

Clinton

Outcomes