Hide Table of Contents
esri/dijit/util
esri/layer/pixelFilters
esri/process
esri/workers
Class: Extent

require(["esri/geometry/Extent"], function(Extent) { /* code goes here */ });

Description

(Added at v1.0)
The minimum and maximum X- and Y- coordinates of a bounding box.

Samples

Search for samples that use this class.

Class hierarchy

esri/geometry/Geometry
|_esri/geometry/Extent

Constructors

NameSummary
new Extent(xmin, ymin, xmax, ymax, spatialReference)Creates a new Extent object.
new Extent(json)Creates a new Extent object using a JSON object.

Properties

NameTypeSummary
cacheObjectThe cache is used to store values computed from geometries that need to cleared or recomputed upon mutation.
spatialReferenceSpatialReferenceThe spatial reference of the geometry.
typeStringThe type of geometry.
xmaxNumberTop-right X-coordinate of an extent envelope.
xminNumberBottom-left X-coordinate of an extent envelope.
ymaxNumberTop-right Y-coordinate of an extent envelope.
yminNumberBottom-left Y-coordinate of an extent envelope.

Methods

NameReturn typeSummary
centerAt(point)ExtentA new extent is returned with the same width and height centered at the argument point.
clearCache()NoneSets the cache property to undefined.
contains(geometry)BooleanWhen "true", the geometry in the argument is contained in this extent.
expand(factor)ExtentExpands the extent by the factor given.
getCacheValue(name)ObjectReturns the value for a named property stored in the cache.
getCenter()PointReturns the center point of the extent in map units.
getHeight()NumberDistance between ymin and ymax.
getWidth()NumberDistance between xmin and xmax.
intersects(geometry)Extent | BooleanReturns the intersection extent if the input geometry is an extent that intersects this extent.
normalize()Extent[]Returns an array with either one Extent that's been shifted to within +/- 180 or two Extents if the original extent intersects the dateline.
offset(dx, dy)ExtentReturns a new Extent with x and y offsets.
setCacheValue(name, value)NoneSets the value for a named property stored in the cache.
setSpatialReference(sr)GeometrySets the spatial reference.
shiftCentralMeridian()ExtentReturns an extent with a spatial reference with a custom shifted central meridian if the extent intersects the dateline.
toJson()ObjectConverts object to its ArcGIS Server JSON representation.
union(extent)ExtentExpands this extent to include the extent of the argument.

NOTE: Performing a Union returns a new extent as opposed to modifying the existing extent..
update(xmin, ymin, xmax, ymax, spatialReference)ExtentUpdates this extent with the specified parameters.
Constructor Details

new Extent(xmin, ymin, xmax, ymax, spatialReference)

Creates a new Extent object. The coordinates represent the lower left and upper right corners of the bounding box. A spatial reference is also required.
Parameters:
<Number> xmin Required Bottom-left X-coordinate of an extent envelope.
<Number> ymin Required Bottom-left Y-coordinate of an extent envelope.
<Number> xmax Required Top-right X-coordinate of an extent envelope.
<Number> ymax Required Top-right Y-coordinate of an extent envelope.
<SpatialReference> spatialReference Required Spatial reference of the geometry.
Sample:
require([
  "esri/geometry/Extent", "esri/SpatialReference", ... 
], function(Extent, SpatialReference, ... ) {
  var extent = new Extent(-122.68,45.53,-122.45,45.60, new SpatialReference({ wkid:4326 }));
  ...
});

new Extent(json)

Creates a new Extent object using a JSON object.
Parameters:
<Object> json Required JSON object representing the geometry.
Sample:
require([
  "esri/geometry/Extent", ... 
], function(Extent, ... ) {
  var extent = new esri.geometry.Extent({
    "xmin":-122.68,"ymin":45.53,"xmax":-122.45,"ymax":45.6,
    "spatialReference":{"wkid":4326}
  });
  ...
});
Property Details

<Object> cache

The cache is used to store values computed from geometries that need to cleared or recomputed upon mutation. An example is the extent of a polygon. The default value is undefined. (Added at v3.13)
Default value: undefined
Sample:
var map;

require([
  "esri/InfoTemplate",
  "esri/layers/FeatureLayer",
  "esri/map",
  "esri/tasks/query", "dojo/domReady!"
], function (InfoTemplate, FeatureLayer, Map, Query){

  map = new Map("map", {
    basemap: "topo",
    center: [-122.45, 37.75], // longitude, latitude
    zoom: 10
  });

  var infoTemplate = new InfoTemplate("Attributes", "${*}");

  var countiesFeatureLayer = new FeatureLayer("http://sampleserver6.arcgisonline.com/arcgis/rest/services/USA/MapServer/3",
    {
      mode: FeatureLayer.MODE_ONDEMAND,
      infoTemplate: infoTemplate,
      outFields: ['*']
    });
  var highwaysFeatureLayer = new FeatureLayer("http://sampleserver6.arcgisonline.com/arcgis/rest/services/USA/MapServer/1",
    {
      mode: FeatureLayer.MODE_ONDEMAND,
      infoTemplate: infoTemplate,
      outFields: ['*']
    });

  map.on("load", function (){
    map.addLayer(countiesFeatureLayer);
    map.addLayer(highwaysFeatureLayer);

    var query = new Query();
    query.geometry = map.extent;
    query.spatialRelationship = Query.SPATIAL_REL_ENVELOPEINTERSECTS;
    query.returnGeometry = true;
    query.outFields = ["*"];

    countiesFeatureLayer.queryFeatures(query, function (featureSet){
      var polygon = featureSet.features[0].geometry;
      // populate the Geometry cache by calling getExtent()
      var polygonExtent = polygon.getExtent();
      console.log("polygonExtent", polygonExtent);
      console.log("polygon.cache._extent", polygon.cache._extent);

      for (var i = 0; i < featureSet.features.length; i  ) {
        var feature = featureSet.features[i];
        console.log("Polygon geometry cache, %o", feature.geometry.cache);
        feature.geometry.clearCache();
        console.log("Polygon geometry clear cache, %o", feature.geometry.cache);
        // Break out of the loop after the first result
        break;
      }
    });

    highwaysFeatureLayer.queryFeatures(query, function (featureSet){
      var line = featureSet.features[0].geometry;
      // populate the Geometry cache by calling getExtent()
      var lineExtent = line.getExtent();
      console.log("lineExtent", lineExtent);
      console.log("line.cache._extent", line.cache._extent);

      for (var i = 0; i < featureSet.features.length; i  ) {
        var feature = featureSet.features[i];
        console.log("Line geometry cache, %o", feature.geometry.cache);
        feature.geometry.clearCache();
        console.log("Line geometry clear cache, %o", feature.geometry.cache);
        // Break out of the loop after the first result
        break;
      }
    });

  });
});

<SpatialReference> spatialReference

The spatial reference of the geometry. See Projected Coordinate Systems and Geographic Coordinate Systems for the list of supported spatial references.

<String> type

The type of geometry.
Known values: point | multipoint | polyline | polygon | extent

<Number> xmax

Top-right X-coordinate of an extent envelope.

<Number> xmin

Bottom-left X-coordinate of an extent envelope.

<Number> ymax

Top-right Y-coordinate of an extent envelope.

<Number> ymin

Bottom-left Y-coordinate of an extent envelope.
Method Details

centerAt(point)

A new extent is returned with the same width and height centered at the argument point.
Return type: Extent
Parameters:
<Point> point Required Centers the extent on the specified x,y location.

clearCache()

Sets the cache property to undefined. (Added at v3.13)

contains(geometry)

When "true", the geometry in the argument is contained in this extent.
Return type: Boolean
Parameters:
<Geometry> geometry Required Can be a Point or Extent.
Sample:

var extent = map.extent;

if(extent.contains(graphic.geometry)) {

  graphic.setSymbol(highlightSymbol);

}

expand(factor)

Expands the extent by the factor given. For example, a value of 1.5 will be 50% bigger.
Return type: Extent
Parameters:
<Number> factor Required The multiplier value.
Sample:
map.setExtent(points.getExtent().expand(3));

getCacheValue(name)

Returns the value for a named property stored in the cache. (Added at v3.13)
Return type: Object
Parameters:
<String> name Required The property name of the value to retrieve from the cache.

getCenter()

Returns the center point of the extent in map units.
Return type: Point

getHeight()

Distance between ymin and ymax.
Return type: Number

getWidth()

Distance between xmin and xmax.
Return type: Number

intersects(geometry)

Returns the intersection extent if the input geometry is an extent that intersects this extent. Boolean is returned when passing in non-Extent geometry types.
Return type: Extent | Boolean
Parameters:
<Geometry> geometry Required The geometry used to test the intersection. Valid geometry includes Point, Multipoint, Extent, Polygon, or Polyline.
Sample:
var polygonExtent = polygon.getExtent();
if (polygonExtent.intersects(map.extent)) {
  alert("Polygon intersects current map extent");
}

normalize()

Returns an array with either one Extent that's been shifted to within +/- 180 or two Extents if the original extent intersects the dateline. (Added at v3.12)
Return type: Extent[]

offset(dx, dy)

Returns a new Extent with x and y offsets. Units are map units.
Return type: Extent
Parameters:
<Number> dx Required The offset distance in map units for the x-coordinate.
<Number> dy Required The offset distance in map units for the y-coordinate.

setCacheValue(name, value)

Sets the value for a named property stored in the cache. (Added at v3.13)
Parameters:
<String> name Required The property name for the value Object to store in the cache.
<Object> value Required The value Object for a named property to store in the cache.

setSpatialReference(sr)

Sets the spatial reference.
Return type: Geometry
Parameters:
<SpatialReference> sr Required Spatial reference of the geometry.

shiftCentralMeridian()

Returns an extent with a spatial reference with a custom shifted central meridian if the extent intersects the dateline. (Added at v3.12)
Return type: Extent

toJson()

Converts object to its ArcGIS Server JSON representation.
Return type: Object

union(extent)

Expands this extent to include the extent of the argument.

NOTE: Performing a Union returns a new extent as opposed to modifying the existing extent.
Return type: Extent
Parameters:
<Extent> extent Required The minx, miny, maxx, and maxy bounding box.

update(xmin, ymin, xmax, ymax, spatialReference)

Updates this extent with the specified parameters.
Return type: Extent
Parameters:
<Number> xmin Required Bottom-left X-coordinate of an extent envelope.
<Number> ymin Required Bottom-left Y-coordinate of an extent envelope.
<Number> xmax Required Top-right X-coordinate of an extent envelope.
<Number> ymax Required Top-right Y-coordinate of an extent envelope.
<SpatialReference> spatialReference Required Spatial reference of the geometry.