Select to view content in your preferred language

Query a single layer with different search params

1991
1
04-15-2014 10:37 PM
kiranbodhasrungi
Deactivated User
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.
0 Kudos
1 Reply
RaymondGoins
Regular Contributor
You look to be using jQuery code to get the value.

Is your code encased in jQuery document ready?. If not $('#searchType').val(); will not work.

Use
var searchOptions = jQuery('#searchType').val();
or
var searchOptions = registry.byId("searchType").get("value");

If you are not getting a value for searchOptions it will return null because you don't have a default for your switch.

Ray
0 Kudos