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

1259
4
06-05-2017 12:12 PM
JacobTodd2
New Contributor III

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!

Tags (3)
0 Kudos
4 Replies
JacobTodd2
New Contributor III

Just an update. I was able to get my definition query to adjust dynamically when an item is either selected or deselected.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Jacob,

  So are you good to go now?

0 Kudos
JacobTodd2
New Contributor III

Unfortunately not. I am still unsure how to apply the queryTask.executeForExtent

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Jacob,

  So you need a sample of how to do a query for extent then?

0 Kudos