AnsweredAssumed Answered

How to utilize queryTask.executeForExtent to zoom to the extent of features corresponding to a definitionExpression?

Question asked by JTTodd on Jun 5, 2017
Latest reply on Jun 5, 2017 by rscheitlin

I am using the ArcGIS API for Javascript 4.3 and want to zoom to features that correspond to a definition expression. It was suggested by @Robert Scheitlin that I use queryTask.executeForExtent to accomplish this. Although, this may be correct, I am still unsure how to incorporate this into my code.

function selectionDefExpression(selectionArray) {
              routeNameStr = selectionArray.join("', '");
              var definitionExpression = corridorLayer.definitionExpression = "BOTH_ROUTE_NAME IN ('" + routeNameStr + "')";
              return definitionExpression;
          }

          function deselectionDefExpression() {
              return corridorLayer.definitionExpression = "BOTH_ROUTE_NAME IN ('" + "" + "')";
          }

          var routeName;
          var routeNameStr;
          var selectedRows = [];
          grid.on('dgrid-select', function (event) {
              routeName = event.rows[0].data.routeName;
              var rows = event.rows;
              for (i = 0; i < rows.length; i++) {
                  selectedRows.push(routeName);
                  selection = document.getElementById("selectedRoutes");
                  selection.innerHTML += "<li>" + routeName + "<a href='#'> Remove</a></li>";
              }
             
              selectionDefExpression(selectedRows);

              if (!corridorURL.visible) {
                  corridorLayer.visible = true;
              }

              }, function (error) {
                  console.log(error)
              });
          });

          grid.on('dgrid-deselect', function (event) {
              //var x = [].slice.call(document.querySelectorAll("#selectedRoutes li"));
              //x.filter(function(e){
              //    return e.firstChild.checked
              //}).forEach(function (e) {
              //    e.remove();
              //})
              deselectionDefExpression();
          });

I could also use some assistance on adjusting my definitionExpression based on what is deselected. The act of selection and deselection should make the extend of my features change, thus re-positioning the map as well.

 

Any suggestions or samples would be greatly appreciated.

 

Thanks!

Outcomes