Zoom into Point using the Find Task

721
5
Jump to solution
05-15-2012 06:38 AM
RachelLinonis
New Contributor
Hello everyone,

I know that there is a few threads on this topic, but I'm still having some difficulty. In the FindTask sample, I want that same search-n-zoom functionality... but instead of zooming into a polygon, I want to zoom into a point. I've added my layer and the search function works fine .. However, the code seems to break in the onRowClickHandler function, because there's no zoomage to the clicked point.

Any ideas as to what I should change in the onRowClickHandler function? (Yes, I left the variables the same...):

            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;                          return;                      }                  });                 var taxLotExtent = selectedTaxLot.geometry.getExtent();                                    map.setExtent(taxLotExtent);              }


Let me know if you need to see more code.

Thanks everyone,
Rach
0 Kudos
1 Solution

Accepted Solutions
JMcNeil
Occasional Contributor III
Rachel,

There are a lot of posts on this subject and I think I handle it somewhat differently, which probably is not correct or good coding cause I'm a total hack but here's how I handle it:



  //Zoom to the parcel when the user clicks a row       function onRowClickHandler(evt){         var clickedId = grid.getItem(evt.rowIndex).OBJECTID;         var g;          dojo.forEach(map.graphics.graphics,function(graphic){           if((graphic.attributes) && graphic.attributes.OBJECTID === clickedId){             g = graphic;             return;           }         });                  if (g.geometry.type == "point"){         var pExtent = new esri.geometry.Extent({"xmin":g.geometry.x - 500,"ymin":g.geometry.y - 500,"xmax":g.geometry.x + 500,"ymax":g.geometry.y + 500,"spatialReference":{"wkid":g.geometry.spatialReference.wkid}});       map.setExtent(pExtent);     }     else{         var gExtent = g.geometry.getExtent();           map.setExtent(gExtent);         }                       }


That should work!

If my post helped or answered your question please send a point my way!

Jay

View solution in original post

0 Kudos
5 Replies
JayGregory
New Contributor III
You should be able to just use the map methods centerAndZoom or centerAt.
All you should need is map.centerAt(selectedTaxLot.geometry) or map.centerAt(selectedTaxLot.geometry, 24)

Hope that helps!

Jay
0 Kudos
JMcNeil
Occasional Contributor III
Rachel,

There are a lot of posts on this subject and I think I handle it somewhat differently, which probably is not correct or good coding cause I'm a total hack but here's how I handle it:



  //Zoom to the parcel when the user clicks a row       function onRowClickHandler(evt){         var clickedId = grid.getItem(evt.rowIndex).OBJECTID;         var g;          dojo.forEach(map.graphics.graphics,function(graphic){           if((graphic.attributes) && graphic.attributes.OBJECTID === clickedId){             g = graphic;             return;           }         });                  if (g.geometry.type == "point"){         var pExtent = new esri.geometry.Extent({"xmin":g.geometry.x - 500,"ymin":g.geometry.y - 500,"xmax":g.geometry.x + 500,"ymax":g.geometry.y + 500,"spatialReference":{"wkid":g.geometry.spatialReference.wkid}});       map.setExtent(pExtent);     }     else{         var gExtent = g.geometry.getExtent();           map.setExtent(gExtent);         }                       }


That should work!

If my post helped or answered your question please send a point my way!

Jay
0 Kudos
RachelLinonis
New Contributor
Rachel,

There are a lot of posts on this subject and I think I handle it somewhat differently, which probably is not correct or good coding cause I'm a total hack but here's how I handle it:



  //Zoom to the parcel when the user clicks a row
      function onRowClickHandler(evt){
        var clickedId = grid.getItem(evt.rowIndex).OBJECTID;
        var g;

        dojo.forEach(map.graphics.graphics,function(graphic){
          if((graphic.attributes) && graphic.attributes.OBJECTID === clickedId){
            g = graphic;
            return;
          }
        });
        
        if (g.geometry.type == "point"){
        var pExtent = new esri.geometry.Extent({"xmin":g.geometry.x - 500,"ymin":g.geometry.y - 500,"xmax":g.geometry.x + 500,"ymax":g.geometry.y + 500,"spatialReference":{"wkid":g.geometry.spatialReference.wkid}});
      map.setExtent(pExtent);
    }
    else{
        var gExtent = g.geometry.getExtent();
          map.setExtent(gExtent);
        }
      
        
      }


That should work!

If my post helped or answered your question please send a point my way!

Jay


Hi Jay, that worked!

(Sorry it took me a day or two to get back to you ... Our servers were down.)

Thank you so much for your responses.
0 Kudos
RachelLinonis
New Contributor
You should be able to just use the map methods centerAndZoom or centerAt.
All you should need is map.centerAt(selectedTaxLot.geometry) or map.centerAt(selectedTaxLot.geometry, 24)

Hope that helps!

Jay


This also worked, but I wasn't able to figure out how to zoom into the point. The code below seemed to work fine. Thanks again for your response! 🙂

Smiles,
Rachel
0 Kudos
JayGregory
New Contributor III
Whoops!  I made a mistake - to zoom to a point, you have to use the line map.centerAndZoom(geometry, zoomlevel).  Probably too late, but this is a quick, elegant way to zoom to a single point. 
Thanks, Jay
0 Kudos