mwaldstein24

QueryTask and Zoom to Result

Discussion created by mwaldstein24 on Feb 18, 2013
Latest reply on Aug 16, 2013 by kenbuja
Hi,

I am looking to see if anyone knows how I can have both a queryTask function and have the map zoom to the result automatically after the search button is clicked. I am stuck on how to create the zoom function, as my search works.

Below is the code i have for the search ability:

var watershed_areas = new esri.layers.ArcGISDynamicMapServiceLayer("http://54.245..................");
map.addLayers(watershed_areas);



findTask = new esri.tasks.FindTask("http://54.245...............");

   
    findParams = new esri.tasks.FindParameters();
    findParams.returnGeometry = true;
    findParams.layerIds = [0];
    findParams.searchFields = ["NWWTRSHDCD", "WTRSHDD"];


   

function execute(searchText) {
   
    findParams.searchText = searchText;
    findTask.execute(findParams, showResults);
   }
   function showResults(results) {   
    var polygonSymbol = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([255, 0, 0]), 1), new dojo.Color([255, 0, 0, 1]));
    map.graphics.clear();
    var dataForGrid = [];
   
    dojo.forEach(results, function(result) {
     var graphic = result.feature;
     dataForGrid.push([result.layerName, result.foundFieldName, result.value]);
     switch (graphic.geometry.type) {
      case "point":
       graphic.setSymbol(markerSymbol);
       break;
      case "polyline":
       graphic.setSymbol(lineSymbol);
       break;
      case "polygon":
       graphic.setSymbol(polygonSymbol);
       break;
     }
     map.graphics.add(graphic);
    });
    var data = {
     items : dataForGrid
    };
    var store = new dojo.data.ItemFileReadStore({
     data : data
    });
    grid.setStore(store);
   }

If anyone could lend any assistance, i would greatly appreciate it.

Thanks,

Margaret

Outcomes