Select to view content in your preferred language

adding "zoom to" on search result

667
4
05-07-2013 08:04 AM
GyeyoungChoi
Deactivated User
Hello,

I've used http://help.arcgis.com/en/webapi/javascript/arcgis/jssamples/find_nomap.html
this find task but now I want to add "zoom to" with my result.

However I couldn't find examples or right api

Can anyone help me with this?

Thank you,

Jack
0 Kudos
4 Replies
ShreyasVakil
Frequent Contributor
While defining the findTask you need to make sure the returnGeometry is set to true so that you can zoom. By default it is false.

Once you have the geometry on the client side, you can either use the centerAndZoom method or use the map.setExtent depending upon the geometry you receive.(point or polygon)
0 Kudos
VinayBansal
Frequent Contributor
You may get an idea from this sample.

http://help.arcgis.com/en/webapi/javascript/arcgis/jssamples/find_map_datagrid.html

Sample shows find task data in grid and then zooms to the results.

Vinay Bansal
0 Kudos
MarcoAmaya
New Contributor
hi

if you did the zoom to search result , pleas share it . i need to do some like that.


Thanks
0 Kudos
GyeyoungChoi
Deactivated User
hi

if you did the zoom to search result , pleas share it . i need to do some like that.


Thanks


I haven't succeed yet 
        findTask = new esri.tasks.FindTask("http://localhost:6080/arcgis/rest/services/FC/AapInfo/MapServer");

        dojo.connect(map, "onLoad", function() {
          findParams = new esri.tasks.FindParameters();
          findParams.returnGeometry = true;
          findParams.layerIds = [2];
          findParams.searchFields = ["OBJECTID","Number","Abbrev","CampusCode"];
          findParams.outSpatialReference = map.spatialReference;
          console.log("find sr: ", findParams.outSpatialReference);
        }); 

function doFind() {
         findParams.searchText = dojo.byId("searchField").value;
        findTask.execute(findParams,showResults);
      }

      function showResults(results) {
        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]));

        var items = dojo.map(results,function(result){
          var graphic = result.feature;
          graphic.setSymbol(symbol);
          map.graphics.add(graphic);
          return result.feature.attributes;
        });
        

        var data = {
          identifier: "OBJECTID",
          label: "OBJECTID",
          items: items
        };
    
        store = new dojo.data.ItemFileReadStore({ data:data });
  grid.setStore(store);
        map.centerAndZoom(center, zoom);
      }

      function onRowClickHandler(evt){
        var clickedTaxLotId = grid.getItem(evt.rowIndex).OBJECTID;
        var selectedTaxLot;

        dojo.forEach(map.graphics.graphics,function(graphic){
          if((graphic.attributes) && graphic.attributes.OBJECTID === clickedTaxLotId){
            selectedTaxLot = graphic;
   //alert(selectedTaxLot);
            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:'5', rowSelector:'10px'">
      <thead>
        <tr>
          <th field="Number" width="50">Num</th>
          <th field="Abbrev" width="50">Abbr</th>
          <th field="CampusCode" width="50">Camp</th>
        </tr>
      </thead>
    </table>


All i can get is result highlighted on the map but no return on "dojo grid " at the <table>

if someone knows why please HELP!
0 Kudos