Select to view content in your preferred language

show all Identify results on one page content

402
2
01-29-2021 09:55 AM
wyeo
by
New Contributor

Is there possible to show the identify results on one content page?

<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no">
  <title>IdentifyTask - 4.18</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.18/esri/css/main.css">
  <script src="https://js.arcgis.com/4.18/"></script>

  <script>
    var promises, tasks;
    require([
      "esri/Map",
      "esri/views/MapView",

      "esri/layers/FeatureLayer",
      "esri/tasks/IdentifyTask",
      "esri/tasks/support/IdentifyParameters",

      "dojo/_base/array",
      "dojo/on",
      "dojo/dom",
      "dojo/dom-class",
      "dojo/promise/all",
      "dojo/domReady!"
    ], function(
      Map, MapView, FeatureLayer,
      IdentifyTask, IdentifyParameters, 
      arrayUtils, on, dom, domClass, all
    ) {

      var identifyTask, params;
      var stateURL="https://sampleserver6.arcgisonline.com/arcgis/rest/services/Census/MapServer/3";
      var stateURL1="https://sampleserver6.arcgisonline.com/arcgis/rest/services/Census/MapServer";
      var stateLayer = new FeatureLayer({
        url:stateURL1,
        layerId: [3],
        opacity:0.7
      });

      var cityURL = "https://sampleserver6.arcgisonline.com/arcgis/rest/services/USA/MapServer/0";
      var cityURL1 = "https://sampleserver6.arcgisonline.com/arcgis/rest/services/USA/MapServer"                    
      var cityLayer = new FeatureLayer({
        url: cityURL1,
        layerId: 0,
        title: "City",
        visible: true
      });

      var map = new Map({
        basemap: "osm",
        layers: [stateLayer, cityLayer] 
      });

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




      //var identifyElements = [];
      var identifyElements;

      view.when(function() {

        tasks = [];
        allParams = [];

        //Set the tasks array
        tasks.push(new IdentifyTask(stateURL1));
        tasks.push(new IdentifyTask(cityURL1));

        // Set the parameters for the Identify
        params = new IdentifyParameters();
        params.tolerance = 3;
        params.layerIds = [2,3];
        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) {
        identifyElements = [];
	       console.log("Show identify element"+identifyElements);
         document.getElementById("viewDiv").style.cursor = "wait";
        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) {
          var rsltContent = 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;
              if (layerName === 'states') {
                  feature.popupTemplate = { // autocasts as new PopupTemplate()
                  title: "States",
                  content: 
                  "<p>State Name: {STATE_NAME}</p>" +
                  "<p>Top population: {POP2007}</p>" +
                  "<p>State ABBR: {STATE_ABBR}</p>" ,

                };

              }else if(layerName === 'Detailed Counties'){
                feature.popupTemplate = { 
					        title: 'County: {NAME}',
                  content: 
                  "<p>State: {STATE_NAME}</p>" +
                  "<p>City COUNTY_FIPS: {CNTY_FIPS}</p>" ,
                };
              
              
            }else if (layerName === 'Cities') {
                feature.popupTemplate = { 
					        title: 'City: {AREANAME}',
                  content: 
                  "<p>Capitol: {CAPITAL}</p>" +
                  "<p>City Population: {POP2000}</p>" ,
                };
              }
              identifyElements.push(feature);
              console.log(identifyElements);
            });
          })
          showPopup(identifyElements);
        });//end rArray

        // Shows the results of the Identify in a popup once the promise is resolved
        function showPopup(response) {
          console.log(response);
          if (response.length > 0) {
            view.popup.open({
              features: response,
              location: event.mapPoint
            });
          }
          dom.byId("viewDiv").style.cursor = "auto";
        }
      }
    });
  </script>
</head>

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

</html>

   

0 Kudos
2 Replies
by Anonymous User
Not applicable

I think, in your function that is iterating over your identify results and creating all of the popupTemplates, you need to instead do a for loop over the results and combine the template outputs into one template.

 

0 Kudos
wyeo
by
New Contributor

Do you mind send me the modify code?

 

Thanks.

0 Kudos