Hide Table of Contents
esri
Map
toolbars
Class: SpatialReference
[ AMD Module Require | Legacy Module Require ]

Description

The spatial reference of a map, layer, or inputs to and outputs from a task. Each projected and geographic coordinate system is defined by both a well-known ID (WKID) or a definition string (WKT). Note that pre 10 only wkid was supported. For a complete list of supported IDs and their corresponding definition strings, see:

Samples

Search for samples that use this class.

Class hierarchy

esri.SpatialReference

Constructors

ConstructorDescription
new esri.SpatialReference(json)Creates a new SpatialReference object.
new esri.SpatialReference(wkid)Create a spatial reference object and initialize it with a well-known ID (wkid).
new esri.SpatialReference(wkt)Create a spatial reference object and initialize it with the given well-known text (wkt).

Properties

PropertyTypeDescription
wkidNumberThe well-known ID of a spatial reference. See Projected Coordinate Systems and Geographic Coordinate Systems for the list of supported spatial references.
wktStringThe well-known text that defines a spatial reference.

Methods

MethodReturn ValueDescription
equals(sr)BooleanReturns true if the input spatial reference object has the same wkid or wkt as this spatial reference object. Returns false otherwise. 
isWebMercator()BooleanReturns true if the wkid of the spatial reference object is one of the following values: 102113, 102100, 3857
toJson()ObjectReturns an easily serializable object representation of the spatial reference.
Constructor Details

new esri.SpatialReference(json)

Creates a new SpatialReference object.
Parameters:
<Object> jsonRequiredThe REST JSON representation of the spatial reference: {"wkid" : <wkid>}
Code Snippet:

Specify the spatial reference using either well-known text (wkt) or a well-known id (wkid). Note that pre 10 only wkid was supported.

var spatialReference = new esri.SpatialReference({wkid:32662});

var spatialReference2 = new esri.SpatialReference({"wkt": 'PROJCS["NAD_1983_HARN_StatePlane_Oregon_North_FIPS_3601",' + 
        'GEOGCS["GCS_North_American_1983_HARN",DATUM["D_North_American_1983_HARN",' +
        'SPHEROID["GRS_1980",6378137.0,298.257222101]]' +
        'PRIMEM["Greenwich",0.0],' +
        'UNIT["Degree",0.0174532925199433]],PROJECTION["Lambert_Conformal_Conic"],' +
        'PARAMETER["False_Easting",8202099.737532808],PARAMETER["False_Northing",0.0],' +
        'PARAMETER["Central_Meridian",-120.5],' +
        'PARAMETER["Standard_Parallel_1",44.33333333333334],' +
        'PARAMETER["Standard_Parallel_2",46.0],' +
        'PARAMETER["Latitude_Of_Origin",43.66666666666666],UNIT["Foot",0.3048]]'
 });
 

new esri.SpatialReference(wkid)

Create a spatial reference object and initialize it with a well-known ID (wkid).
Parameters:
<Number> wkidRequiredThe well-known id (wkid) of the coordinate system.
Code Snippet:
var sr = new esri.SpatialReference(4326);

new esri.SpatialReference(wkt)

Create a spatial reference object and initialize it with the given well-known text (wkt).
Parameters:
<String> wktRequiredThe well-known text (wkt) of the coordinate system.
Code Snippet:
var sr = new esri.SpatialReference('GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",
  SPHEROID["WGS_1984",6378137.0,298.257223563]],
  PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]]'
);
Property Details

<Number> wkid

The well-known ID of a spatial reference. See Projected Coordinate Systems and Geographic Coordinate Systems for the list of supported spatial references.

<String> wkt

The well-known text that defines a spatial reference. Many browser have a limit to the length of a GET request of approximately 2048 characters. When using well-known text to specify the spatial reference you can easily exceed this limit. In these cases, you will need to setup and use a proxy page.
Method Details

equals(sr)

Returns true if the input spatial reference object has the same wkid or wkt as this spatial reference object. Returns false otherwise. 
Return Value: Boolean
Input Parameters:
<SpatialReference> srRequiredThe spatial reference to compare. 
Code Snippet:
  var sr1 = new esri.SpatialReference(4326);
  var sr2 = new esri.SpatialReference(4326);
  console.log(sr1.equals(sr2); // true

isWebMercator()

Returns true if the wkid of the spatial reference object is one of the following values: 102113, 102100, 3857
Return Value: Boolean
Code Snippet:
var sr = new esri.SpatialReference(102100);
console.log(sr.isWebMercator()); // true

toJson()

Returns an easily serializable object representation of the spatial reference.
Return Value: Object