Select to view content in your preferred language

Help converting function to API version 3.8

929
3
03-27-2014 08:47 AM
BenCamp
Deactivated User
I haven't been able to get this function to run properly.  It works as expected in version 2.6, but I am at my wits end trying to get it working in 3.8.  Any help is greatly appreciated.

      //Zoom to the POINT when the user clicks a row
      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 = new esri.geometry.Extent();
                taxLotExtent.xmin = selectedTaxLot.geometry.x - .1;
                taxLotExtent.ymin = selectedTaxLot.geometry.y - .1;
                taxLotExtent.xmax = selectedTaxLot.geometry.x + .5;
                taxLotExtent.ymax = selectedTaxLot.geometry.y + .5;
        map.setExtent(taxLotExtent);
      }
0 Kudos
3 Replies
JakeSkinner
Esri Esteemed Contributor
Hi John,

This appears correct.  Would you be able to post your entire code, or create a jsfiddle?
0 Kudos
JeffPace
MVP Alum
I haven't been able to get this function to run properly.  It works as expected in version 2.6, but I am at my wits end trying to get it working in 3.8.  Any help is greatly appreciated.

      //Zoom to the POINT when the user clicks a row
      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 = new esri.geometry.Extent();
                taxLotExtent.xmin = selectedTaxLot.geometry.x - .1;
                taxLotExtent.ymin = selectedTaxLot.geometry.y - .1;
                taxLotExtent.xmax = selectedTaxLot.geometry.x + .5;
                taxLotExtent.ymax = selectedTaxLot.geometry.y + .5;
        map.setExtent(taxLotExtent);
      }


There is only one item in here that is not AMD, dojo.forEach

in your require
"dojo/_base/array",

alias it to
"array"

and change your line above to
array.forEach(map.graphics.graphics,function(graphic){
0 Kudos
BenCamp
Deactivated User
Thank you for the response.  I believe I have finally found the problem.  I believe the problem was a lack of spatial reference.  I've been converting my application to the 3.8 API over the last couple days (from the 2.6 API) and this was the last major problem I ran into.  Thanks again for the assistance. 

The code below now works as expected (zooms and centers correctly). 
        //Zoom to the POINT when the user clicks a row
        function onRowClickHandler(evt) {
          var clickedTaxLotId = evt.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 spatialRef = new esri.SpatialReference({wkid:102100})
        var taxLotExtent = new esri.geometry.Extent();
                taxLotExtent.xmin = selectedTaxLot.geometry.x - .1;
                taxLotExtent.ymin = selectedTaxLot.geometry.y + .5;
                taxLotExtent.xmax = selectedTaxLot.geometry.x - .1;
                taxLotExtent.ymax = selectedTaxLot.geometry.y + .5;
                taxLotExtent.spatialReference = spatialRef;

        map.setExtent(taxLotExtent);
      }
0 Kudos