Select to view content in your preferred language

Extent.intersects() method returns incorrect value

2984
2
Jump to solution
09-03-2012 07:59 AM
SamLarsen
Occasional Contributor
I am using the esri.geometry.Extent.intersects() method which is returning a boolean true or false based on whether or not the extent intersects the other extent.
The documentation states that it should return the actual intersection extent:
http://help.arcgis.com/en/webapi/javascript/arcgis/help/jsapi_start.htm#jsapi/extent.htm#intersects

Is this a case of the documentation being incorrect or the API being incorrect?
0 Kudos
1 Solution

Accepted Solutions
SamLarsen
Occasional Contributor
It appears that the API is correct and the documentation is incorrect or out of date.

For those looking for an actual intersection extent i have extended the API to generate the extent:
dojo.extend(esri.geometry.Extent,{  intersection: function(/*esri.geometry.Extent*/ extent) {   //  summary:    //    Calculate the intersection extent of two extents   //  returns:   //    The intersection extent   //    esri.geometry.Extent || null   var overlap = null;   if(this.intersects(extent)){    //  create a new intersection geometry    overlap = new esri.geometry.Extent(     this.xmin > extent.xmin ? this.xmin : extent.xmin,     this.ymin > extent.ymin ? this.ymin : extent.ymin,     this.xmax < extent.xmax ? this.xmax : extent.xmax,     this.ymax < extent.ymax ? this.ymax : extent.ymax,     this.spatialReference    );   }   return overlap;  } });

View solution in original post

0 Kudos
2 Replies
SamLarsen
Occasional Contributor
It appears that the API is correct and the documentation is incorrect or out of date.

For those looking for an actual intersection extent i have extended the API to generate the extent:
dojo.extend(esri.geometry.Extent,{  intersection: function(/*esri.geometry.Extent*/ extent) {   //  summary:    //    Calculate the intersection extent of two extents   //  returns:   //    The intersection extent   //    esri.geometry.Extent || null   var overlap = null;   if(this.intersects(extent)){    //  create a new intersection geometry    overlap = new esri.geometry.Extent(     this.xmin > extent.xmin ? this.xmin : extent.xmin,     this.ymin > extent.ymin ? this.ymin : extent.ymin,     this.xmax < extent.xmax ? this.xmax : extent.xmax,     this.ymax < extent.ymax ? this.ymax : extent.ymax,     this.spatialReference    );   }   return overlap;  } });
0 Kudos
derekswingley1
Deactivated User
Hi Sam,

esri.geometry.Extent.intersects does return an extent when an extent is passed to it and the two extents intersect. Here's a test case:  http://jsfiddle.net/w45HY/

If you're not passing an extent to extent.intersects() (that is, you pass some other geometry type like Point or Polygon), you get a boolean back. Can you confirm that this works on your end?

Edit:  we'll update the docs to say that a boolean is returned if a non-extent geometry is passed to extent.intersects().
0 Kudos