AnsweredAssumed Answered

Best way to combine query results from 2 layers to get overall extent?

Question asked by ibroad on Sep 6, 2018
Latest reply on Sep 6, 2018 by ibroad

I have a support structure layer and a surface structure layer, and I query both to find which features in each layer were inspected.

 

For the inspected features, I create a graphic on top of the feature to show which structures were inspected.

 

Now, I want to zoom to the extent of the inspected features. I can easily do this for one layer, but I'm trying to figure out the best way to combine the features of the two layers.

 

I thought I could just do something like:

view.extent = inspectionGraphicLayer.fullExtent.expand(2.5);

 

Since I'm adding the features to the same GraphicLayer, but it just zooms to the entire world. Also, since I do two separate QueryTasks for each structure layer it would call this twice.

 

Here's an example that only zooms to the extent of the surface structures:

 

function getLastInspectedStructures(results) {
    var structureNumbers = [];

    for (var i = 0; i < results.features.length; i++) {
      structureNumbers.push(results.features[i].attributes.StationNumber);
    }

    var getInspectedStructures_Q = new Query();

    getInspectedStructures_Q.where = where;
    getInspectedStructures_Q.outSpatialReference = sr;
    getInspectedStructures_Q.returnGeometry = true;
    getInspectedStructures_Q.outFields = ["gs_facility_id"];

    supportStructureInspected_QT
      .execute(getInspectedStructures_Q)
      .then(function (results) {
        displayInspectedGraphics(results, getInspectedStructures_Q);
      });

    surfaceStructureInspected_QT
      .execute(getInspectedStructures_Q)
      .then(function (results) {
        displayInspectedGraphics(results, getInspectedStructures_Q);
      });
  }

  function displayInspectedGraphics(results, query) {

    for (feature of results.features) {

      var inspectionGraphic = new Graphic({
        geometry: feature.geometry,
        symbol: {
          type: "simple-marker",
          color: [0, 255, 0, 0.9],
          outline: {
            color: [0, 0, 0],
            width: 2
          }
        }
      });
      inspectionGraphicLayer.add(inspectionGraphic);
    }

    surfaceStructureInspected_QT.executeForExtent(query).then(function (results) {
      view.extent = results.extent.expand(2.5);
    });
  }

 

What's the best way to combine the results for an overall extent?

Outcomes