kerankousyal

Query a single layer with different search params

Discussion created by kerankousyal on Apr 15, 2014
Latest reply on Apr 17, 2014 by craygo
All,

i have to query a layer with different search parameters and populate a datagrid.I have a drop down of search types and an input field for searchText.When i do a search with the help of a search button the datagrid will be populated.

For ex: street name,owner name,account number as options in a drop down.

Based on the type of search selected I am trying to change the findParameters.searchFields but i could only see a null for searchFields while doing so.

Here is the code:

<script>
      require([
        "esri/map",
        "esri/tasks/FindTask",
        "esri/tasks/FindParameters",
        "esri/symbols/SimpleMarkerSymbol",
        "esri/symbols/SimpleLineSymbol",
        "esri/symbols/SimpleFillSymbol",
        "esri/toolbars/navigation",
         
        "esri/Color",
        "dojo/on",
        "dojo/dom",
        "dijit/registry",
        "dojo/_base/array",
        "dojo/_base/connect",
        "dojox/grid/DataGrid",
        "dojo/data/ItemFileReadStore",
        "dijit/form/Button",
        "dojo/parser",
         
        "dijit/layout/BorderContainer",
        "dijit/layout/ContentPane",
        "dojo/domReady!"
      ], function(
        Map, FindTask, FindParameters, SimpleMarkerSymbol, SimpleLineSymbol, SimpleFillSymbol,navigation,
        Color, on, dom, registry, arrayUtils, connect, DataGrid, ItemFileReadStore, Button, parser
      ) {     
        var findTask;
        var map, center, zoom;
        var grid, store;
       
        parser.parse();       
       
        registry.byId("search").on("click", doFind);
       
        center = [-83.266, 42.568];
        zoom = 11;
        map = new esri.Map("map", {
          basemap: "streets",
          center: center,
          zoom: zoom
        });

        //Create Find Task using the URL of the map service to search
        findTask = new FindTask("http://localhost:6080/arcgis/rest/services/MidParcelFabric/MapServer/");
               
       
        function doFind() {
   var findParams;
          findParams = new FindParameters();
             findParams.returnGeometry = true;
             findParams.layerIds = [1];
             findParams.outSpatialReference = map.spatialReference;
            
             console.log("find sr: ", findParams.outSpatialReference);
            
         var searchOptions = $('#searchType').val();
         console.log(searchOptions);
            switch(searchOptions) {
          
            case 1:
              console.log('by location');
             findParams.searchFields = ["STREET_NAME", "STREET_NUMBER"];
             console.log(findParams.searchFields);
             break;
            case 2:
             console.log('by owner');
             findParams.searchFields = ["GRANTEE"];
             break;
            case 3:
             console.log('by maplot/unit');
             findParams.searchFields = ["MAPLOT_1", "LOT_1","UNIT__"];
             break;
            case 4:
             console.log('by account no');
             findParams.searchFields = ["CAMAACCT_1"];
             break;
            case 5:
             console.log('by pid');
             findParams.searchFields = ["pid"];
             break;
            }
          findParams.searchText = dom.byId("searchFilter").value;
         
          console.log(findParams.searchText);
          console.log(findParams.searchFields);
          findTask.execute(findParams, showResults);
        }

        function showResults(results) {
          //This function works with an array of FindResult that the task returns
          map.graphics.clear();
          var symbol = new SimpleFillSymbol(
            SimpleFillSymbol.STYLE_SOLID,
            new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID, new Color([98, 194, 204]), 2),
            new Color([98, 194, 204, 0.5])
          );

          //create array of attributes
          var items = arrayUtils.map(results, function (result) {
            var graphic = result.feature;
            graphic.setSymbol(symbol);
           
Thanks in advance.

--keran.

Outcomes