dexconor

Problem with Search then click-zoom-into

Discussion created by dexconor on Jun 13, 2013
Latest reply on Jun 14, 2013 by dexconor
Hello everyone,

I slightly change code from http://developers.arcgis.com/en/javascript/samples/find_map_datagrid/
but I can't get it to work.

So far, the results highlighted on the map but no list return (dojo grid).

I'm not sure that where should I fix or change
searching 4 layers but they are having different column name but would it be a problem? if so should I make all the layers have same column name for all layers?


Please help me to get it work.


function init()
        findTask = new esri.tasks.FindTask("http://localhost:6080/arcgis/rest/services/FC/MapInfo/MapServer");

        dojo.connect(map, "onLoad", function() {
          //Create the find parameters
          findParams = new esri.tasks.FindParameters();
          findParams.returnGeometry = true;
          findParams.layerIds = [0,1,2,3];
          findParams.searchFields = ["Number","Name","Abbrev"];
          findParams.outSpatialReference = map.spatialReference;
          console.log("find sr: ", findParams.outSpatialReference);
        });  

function doFind() {
 
        //Set the search text to the value in the box
        findParams.searchText = dojo.byId("searchField").value;
        findTask.execute(findParams,showResults);
      }

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

        //create array of attributes
        var items = dojo.map(results,function(result){
          var graphic = result.feature;
          graphic.setSymbol(symbol);
          map.graphics.add(graphic);
    //alert(JSON.stringify(result.feature.attributes));
      //alert(result.feature.attributes.OBJECTID);
    //alert(result.feature.attributes.Abbrev);
          return result.feature.attributes;

        });
        
        //Create data object to be used in store
        var data = {
          identifier: "OBJECTID",  //This field needs to have unique values
          label: "PARCELID", //Name field for display. Not pertinent to a grid but may be used elsewhere.
          items: items
        };
    

         //Create data store and bind to grid.
        store = new dojo.data.ItemFileReadStore({ data:data });
        var grid = dijit.byId('grid');
        grid.setStore(store);

        //Zoom back to the initial map extent
        map.centerAndZoom(center, zoom);
      }

      //Zoom to the parcel when the user clicks a row
      function onRowClickHandler(evt){
        var clickedTaxLotId = grid.getItem(evt.rowIndex).PARCELID;
        var selectedTaxLot;

        dojo.forEach(map.graphics.graphics,function(graphic){
          if((graphic.attributes) && graphic.attributes.PARCELID === clickedTaxLotId){
            selectedTaxLot = graphic;
            return;
          }
        });
        var taxLotExtent = selectedTaxLot.geometry.getExtent();
        map.setExtent(taxLotExtent);
      }

<input type="text" id="searchField" size="30" value="" /><button data-dojo-type="dijit.form.Button"  onClick="doFind();" value="Search">
        Search
      </button>
<table data-dojo-type="dojox.grid.DataGrid" data-dojo-id="grid"  id="grid" data-dojo-props="rowsPerPage:'10', rowSelector:'20px'">
      <thead>
        <tr>
          <th field="PARCELID">Parcel ID</th>
          <th field="Number" >Owner 1</th>
          <th field="Abbrev">Owner 2</th>
          <th field="CampusCode">Year Built</th>
        </tr>
      </thead>
    </table>

Outcomes