Select to view content in your preferred language

Zoom to Query result

1030
2
01-07-2013 10:30 PM
emirates78John
New Contributor
Hi there,

I trying to find out what i have miss in the code.
Here the code :
function searchPrecinct(prct){
             presint = ""; 
  map.graphics.clear();
  dojo.byId("result").innerHTML = ""; 
  
  strwhere = "PRECINT_ID='"+ prct +"'";
  query.where = strwhere;
  
  qTaskPrecinct.execute(query);     
  alert(strwhere);
  dojo.connect(qTaskPrecinct,'onComplete',function(fSetPrct){
   var resultFeatures = fSetPrct.features; 
   
   if (resultFeatures.length==0){
    dojo.byId("result").innerHTML = "No record.";
    return;
   }
   
   ixmin = 0; iymin = 0; ixmax = 0; iymax = 0;
   
   for (var j=0; j<resultFeatures.length; j++){ //get xy min max
    var graphic = resultFeatures; 
    presint = graphic.attributes.PRECINT_ID; 
    
    if (j==0){
     ixmin = graphic.geometry.getExtent().xmin;
     iymin = graphic.geometry.getExtent().ymin;
     ixmax = graphic.geometry.getExtent().xmax;
     iymax = graphic.geometry.getExtent().ymax;
    }
    else{
     if (graphic.geometry.getExtent().xmin < ixmin) ixmin = graphic.geometry.getExtent().xmin;
     if (graphic.geometry.getExtent().ymin < iymin) iymin = graphic.geometry.getExtent().ymin;
     if (graphic.geometry.getExtent().xmax > ixmax) ixmax = graphic.geometry.getExtent().xmax;
     if (graphic.geometry.getExtent().ymax > iymax) iymax = graphic.geometry.getExtent().ymax;
    }
   }
   
   var newExtent = new esri.geometry.Extent();
   newExtent.xmin = ixmin - 6; 
   newExtent.ymin = iymin - 6; 
   newExtent.xmax = ixmax + 7; 
   newExtent.ymax = iymax + 7; 
   
   map.setExtent(newExtent, true);
   setTimeout( function() {
    newExtent.xmin += 1; 
    newExtent.xmax += 1; 
    map.setExtent(newExtent, true); 
       
   }, 1000); 
  });
  

I failed to zoom into the result...

Anybody can help me?
0 Kudos
2 Replies
HemingZhu
Frequent Contributor
Hi there,

I trying to find out what i have miss in the code.
Here the code :
function searchPrecinct(prct){
             presint = ""; 
  map.graphics.clear();
  dojo.byId("result").innerHTML = ""; 
  
  strwhere = "PRECINT_ID='"+ prct +"'";
  query.where = strwhere;
  
  qTaskPrecinct.execute(query);     
  alert(strwhere);
  dojo.connect(qTaskPrecinct,'onComplete',function(fSetPrct){
   var resultFeatures = fSetPrct.features; 
   
   if (resultFeatures.length==0){
    dojo.byId("result").innerHTML = "No record.";
    return;
   }
   
   ixmin = 0; iymin = 0; ixmax = 0; iymax = 0;
   
   for (var j=0; j<resultFeatures.length; j++){ //get xy min max
    var graphic = resultFeatures; 
    presint = graphic.attributes.PRECINT_ID; 
    
    if (j==0){
     ixmin = graphic.geometry.getExtent().xmin;
     iymin = graphic.geometry.getExtent().ymin;
     ixmax = graphic.geometry.getExtent().xmax;
     iymax = graphic.geometry.getExtent().ymax;
    }
    else{
     if (graphic.geometry.getExtent().xmin < ixmin) ixmin = graphic.geometry.getExtent().xmin;
     if (graphic.geometry.getExtent().ymin < iymin) iymin = graphic.geometry.getExtent().ymin;
     if (graphic.geometry.getExtent().xmax > ixmax) ixmax = graphic.geometry.getExtent().xmax;
     if (graphic.geometry.getExtent().ymax > iymax) iymax = graphic.geometry.getExtent().ymax;
    }
   }
   
   var newExtent = new esri.geometry.Extent();
   newExtent.xmin = ixmin - 6; 
   newExtent.ymin = iymin - 6; 
   newExtent.xmax = ixmax + 7; 
   newExtent.ymax = iymax + 7; 
   
   map.setExtent(newExtent, true);
   setTimeout( function() {
    newExtent.xmin += 1; 
    newExtent.xmax += 1; 
    map.setExtent(newExtent, true); 
       
   }, 1000); 
  });
  

I failed to zoom into the result...

Anybody can help me?


I would try this:
function searchPrecinct(prct){
             presint = ""; 
  map.graphics.clear();
  dojo.byId("result").innerHTML = ""; 
  
  strwhere = "PRECINT_ID='"+ prct +"'";
  query.where = strwhere;
  
  qTaskPrecinct.execute(query);     
  alert(strwhere);
  dojo.connect(qTaskPrecinct,'onComplete',function(fSetPrct){
   var resultFeatures = fSetPrct.features; 
   
   if (resultFeatures.length==0){
    dojo.byId("result").innerHTML = "No record.";
    return;
   }

   map.extent =esri.graphicsExtent(resultFeatures)  
                            });  

0 Kudos
emirates78John
New Contributor
hi hzhu,

thanks for the reply..

I already test your code but the result still same..not zoom to selected precinct..
I debug the code using chrome Javascript console, and it shows some error on the code.

Here I attached the image
[ATTACH=CONFIG]20564[/ATTACH]
0 Kudos