Select to view content in your preferred language

4.30 replacement for featureTable.clearSelection()

58
0
8 hours ago
luckachi
Occasional Contributor III

I am trying to update my application from 4.29 to 4.30 but I am running into an issue with a replacement for featureTable.clearSelection().

Below is one section of my code. I have a "filter/search" widget in the corner of the map that allows you to query by different attributes. When the page loads, the feature layer is hidden due to the large amount of data but the feature table still lists all the data (which I'd like to have stay blank until the query results come back). The section that called featureTable.clearSelection(), clears the selection from the query results but keeps them in the featureTable. Right now, I cannot make that happen. I'd like the query results to be returned but without being selected so the user can interact with each record.

Also, if anyone happens to have any suggestions to simplify the code, I would love to hear them. I am trying to figure out how to use objectIds to filter the feature table with no success. Not quite sure how to structure that.

 

 

/*** SEARCH BY PROJECT ***/

      /* Call doQuery() each time the button is clicked */
      view.when(function () {
        document.getElementById("doBtn").addEventListener("click", doQuery);
      });

      /* Executes each time the button is clicked.
      Clears results from prev. query then builds a new query.
      Executes query and calls getResults() once promise is resolved. */
      function doQuery() {
        resultsLayer.removeAll();
        params.where = "PROJECT =" + "'" + prjSelect.value + "' AND (VERIFIED = 1 OR VERIFIED = 2)";
        loader.active = true;
        obsLayer.queryFeatures(params).then(getResults).catch(promiseRejected);
       }

      /* Called each time promise is resolved.
      Loop through each results and assign symbol and PopupTemplate */
      function getResults(response) {
        var prjResults = response.features.map(function (feature) {
          feature.symbol = sym;
          feature.popupTemplate = popupTemplate;
          return feature;
        });
        resultsLayer.addMany(prjResults);

      //console.log(response.features.length);
        if(response.features.length === 0){
          alert("Search query found no results.");
          loader.active = false;
          return
        }else{
          for(let iii=0; iii < response.features.length; iii++){
            featureTable.highlightIds.add(response.features[iii].attributes.OBJECTID);
            featureTable.filterBySelectionEnabled = true;
            console.log("searching...")
          }
        };

      /* Zoom to Extent */
        var AOI = response.features;
        view.goTo(AOI);

      /* Clear filtered selection - filtered records remain */
        featureTable.clearSelection();

      /* Listen for changes in the collection of highlighted features */
        featureTable.highlightIds.on("change", (event) => {
          console.log("features selected", event.added);
          console.log("features deselected", event.removed);
          
          /* If the change is a selection, create a red circle to highlight point and zoom to it */
          let selectRecord = event.added;
          if (selectRecord) {
            console.log(selectRecord);
            var querySEL = new Query();
              querySEL.where = "OBJECTID = " + event.added[0];
              querySEL.returnGeometry = true;
              obsLayer.queryFeatures(querySEL).then(function(result){
                var resultFeaturesSEL = result.features;
                resultFeaturesSEL.map(function(gra){
                  gra.symbol = highlightsymbol;
                  view.graphics.add(gra);
                })
                view.goTo({
                  target: resultFeaturesSEL,
                  zoom: 13
                }) 
              }) 
            }

          /* If the change is a deselection, remove the red circle graphic. */
           let deselectRecord = event.removed;
           if (deselectRecord){
            view.graphics.removeAll();
            view.goTo(AOI);
           } 

        }); /* end of on change */

      }

      /* Called each time promise is rejected */
      function promiseRejected(error) {
        console.error("Promise rejected: ", error.message);
      }

 

 

 

 

 

 

0 Kudos
0 Replies