how to get xmin, ymin, ymax, xmax values from a feature's extent

6066
4
05-09-2013 12:00 PM
JoanSteinbacher
New Contributor III
I am trying to get the xmin, ymin, ymax, xmax values from a feature's extent to use in a "Zoom To" hyperlink.  The code throws an error on the line xmin = feature.getExtent().xmin -- saying xmin is undefined. I'm sure it's something simple (?), but I can't figure out how to get at these values. If I hardcode the values, the code (listed below) works fine. But I need to set the values based on the feature. Can anyone shed some light on this?   Thanks - Joan

function getParcelInfoWindowContent(idParcelInfoResults) {
 console.log("-->inside getParcelInfoWindowContent");
 //idParcelInfoResults are the results of an Identify Task on the parcel layer.
 
 //Only want to show the 1st Parcel (so hardcode i=0 and don't loop thru the results).
 i=0;
  
    var idParcelInfoResult = idParcelInfoResults;
 console.log("idParcelInfoResult.layerId: " + idParcelInfoResult.layerId);
 console.log("idParcelInfoResult.layerName: " + idParcelInfoResult.layerName);
 console.log("idParcelInfoResult.displayFieldName: " + idParcelInfoResult.displayFieldName);
   
 //Create a feature set. This will contain only the first result. 
    var featureArray = {displayFieldName:idParcelInfoResult.displayFieldName,features:[]}; 
    featureArray.features.push(idParcelInfoResult.feature);
    console.log("featureArray length = " + featureArray.length);
      
    //var feature = idParcelInfoResult.feature;
   

      
    var feature = featureArray.features;
    console.log("feature geometry type: " + feature.geometry.type);
      
    //highlight the feature on the map.

    symbol = new esri.symbol.SimpleFillSymbol(highlightfillSymbol);
    feature.setSymbol(symbol);
    map.graphics.add(feature);

 //Get the extent of the feature.
    var xmin, ymin, ymax, xmax;  
    // xmin = feature.getExtent().xmin;
 // ymin = feature.getExtent().ymin;
 // xmax = feature.getExtent().xmax;
 // ymax = feature.getExtent().ymax;

 xmin = -9215700;
 ymin = 3216400;
 xmax = -9119800;
 ymax = 3256100;
   
 //create the content for the Parcel tab.
 var parCp = new dijit.layout.ContentPane({
             title: idParcelInfoResult.layerName,
             content: layerParcelInfoTabContent(featureArray,idParcelInfoResult.layerName) //creates content of each tab.
    });

    //Get the FOLIO number to pass to the Land Use Acreage query task.
    //console.log("FOLIO: " + featureArray.features.attributes['FOLIO']);
    var folio = featureArray.features.attributes['FOLIO'];
    console.log("FOLIO: " + folio);
    
    //Call the query task function.
    doQueryFolio(folio);
    
    //create the content for the Land Use Acreage info.
 var luCp = new dijit.layout.ContentPane({
             title: "Land Use",
             content: "<div id='luContent'></div>"  
    });

      
    //({'xmin':-17893.572423357622,'ymin':6709881.59745682,'xmax':-12385.329072411998,'ymax':6714133.407158158,'spatialReference':{'wkid':102100}})
    //var zoomToLink = "<a href='#' onclick=map.setExtent({'xmin':-17893.572423357622,'ymin':6709881.59745682,'xmax':-12385.329072411998,'ymax':6714133.407158158,'spatialReference':{'wkid':102100}});>Zoom To</a>"; 
    var zoomToLink =  "<a href='#' onclick='zoomTo(" + xmin + ","+ ymin + "," + xmax + "," + ymax + ");'>Zoom To</a>";
      
    console.log("g_luHTML: " + g_luHTML);
      
    var printLink = "<a href='#' onclick='printElement(&quot;parLanduse&quot;)'>Print</a>";
    console.log("printLink: " + printLink);
      
    var popupContent = zoomToLink + "  " + printLink + "<br /><br /><div id='parLanduse'>" + luCp.content + "<br/><br/>" + parCp.content + "</div>";
    console.log("popupContent: " + popupContent);
     
    //Make a content pane to hold all the info in the popu window. 
 var cp = new dijit.layout.ContentPane({
   style: "width:100%;height:100%;"
 }, dojo.create("div", { innerHTML: popupContent }));  

 return cp.domNode;
}
function zoomTo(xmin,ymin,xmax,ymax) {
 console.log("-->inside zoomTo");
 console.log("xmax: " + xmax);
 //var extent = new esri.geometry.Extent({"xmin":-9215700,"ymin":3216400,"xmax":-9119800,"ymax":3256100,"spatialReference":{"wkid":102100}});
 var extent = new esri.geometry.Extent({"xmin":xmin,"ymin":ymin,"xmax":xmax,"ymax":ymax,"spatialReference":{"wkid":102100}});
 map.setExtent(extent,true);
}
0 Kudos
4 Replies
GregKnight
Occasional Contributor
Joan,

Its possible you need to do get the extent object first, then get the min/max values from it.

//Get the extent of the feature.
var extent = feature.getExtent();
var xmin = extent.xmin;


etc...

Hope this helps,
Greg
0 Kudos
JoanSteinbacher
New Contributor III

//Get the extent of the feature.
var extent = feature.getExtent();
var xmin = extent.xmin;



Unfortunately that throws the error:
TypeError: feature.getExtent is not a function
0 Kudos
JoanSteinbacher
New Contributor III
Okay, after playing with it some more, I modified it to the following which works. Thanks, Greg, for leading me in the right direction.

var extent = new esri.geometry.Extent(feature.geometry.getExtent());
var xmin = extent.xmin;
GregKnight
Occasional Contributor
Glad you figured it out.
0 Kudos