AnsweredAssumed Answered

One button to independently trigger functions of users' choice

Question asked by alex92190 on May 20, 2014
Latest reply on May 21, 2014 by alex92190
I am looking to simplify my code. As of right now I have a code that allows the 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 fucntion:

   
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 1 button? For example, If users draw then the 1 and only "extract" button would extract data by the extent drawn by the user. FYI I am using a dijit/from/dropdown for selecting counties and units, which means there always be one element selected in these two extraction process.
Thank you,
Alex

Outcomes