Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I am looking to simplify my code. As of right now I have some code that allows users to extract GIS data in three different ways:

  1. Extract by drawn extent
  2. Extract by extent of the a county
  3. Extract by extent by unit.

1st function:

function extractData() {
  //get clip layers
  var clipLayers = [];
  if (registry.byId("layer1").get("checked")) {
    clipLayers.push("SRA");
  }
  if (registry.byId("layer2").get("checked")) {
    clipLayers.push("Burn");
  }
  if (clipLayers.length === 0 || map.graphics.graphics.length === 0) {
    alert("Select layers to extract and draw an area of interest.");
    return;
  }

  var featureSet = new FeatureSet();
  var features = [];
  features.push(map.graphics.graphics[0]);
  featureSet.features = features;

  var params3 = {
    "Layers_to_Clip": clipLayers,
    "Area_of_Interest": featureSet,
    "Feature_Format": registry.byId("formatBox").get("value")
  };

  domStyle.set(loading2, "display", "inline-block");
  gp.submitJob(params3, completeCallback, statusCallback2, function (error) {
    alert(error);
    domStyle.set(loading2, "display", "none");
  });
}

2nd function:

function executeQueryTask(county) {
  var clipLayers = [];
  if (registry.byId("layer1").get("checked")) {
    clipLayers.push("SRA");
  }
  if (registry.byId("layer2").get("checked")) {
    clipLayers.push("Burn");
  }
  if (clipLayers.length === 0) {
    alert("No layers to clip, please select a layer you would like to clip...");
    return;
  }

  var county = document.getElementById("sel_county").value;
  var queryTask = new QueryTask("http://webgisdevint1/arcgis/rest/services/Alex_Try/Counties/MapServer/0");
  queryTask.on("complete", addToMap);
  var query = new Query();
  query.returnGeometry = true;
  query.outFields = ["NAME_PCASE"];
  query.where = "NAME_PCASE = '" + county + "'";
  query.outSpatialReference = map.spatialReference;
  queryTask.execute(query, function (featureSet) {
    var AOI = featureSet.features[0].geometry;
    var graphic = new Graphic(AOI, symbol);
    var features = [];
    features.push(graphic);
    var fSet = new FeatureSet();
    fSet.features = features;

    var params = {
      "Layers_to_Clip": clipLayers,
      "Area_of_Interest": fSet,
      "Feature_Format": registry.byId("formatBox").get("value")
    };

    domStyle.set(loading, "display", "inline-block");
    gp.submitJob(params, completeCallback, statusCallback, function (error) {
      alert(error);
      domStyle.set(loading, "display", "none");
    });
  });
}

And a third that looks exactly like the one above except that I query by units not county.

Each function is triggered by this:

registry.byId("extract1").on("click", executeQueryTask);

And this:

<button id="extract1" data-dojo-type="dijit/form/Button" data-dojo-props="iconClass:'Query', showLabel:false">
    Extract Data
</button>

Now here is my question: How can independently trigger each function from one and only one button?

As of right now I have three buttons that triggers each function.

Would it be possible to trigger each function independently from only one button?

For example, if users draw then the one and only "extract" button would extract data by the extent drawn by the user.

FYI I am using a dijit/from/dropdownfor selecting counties and units, which means there will always be one element selected in these two extraction processes.

share|improve this question
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.