I am trying to understand how the extent works in the javascript api. I create an extent like the following:

var beginExt = new esri.geometry.Extent(-159.6716766, 19.520, -67.843, 64.8348, new esri.SpatialReference({wkid:4326}));
var revExt = esri.geometry.geographicToWebMercator(beginExt);

I add it to the map but when I display the current extent with this:

function showExtent(extent) {
        var s = "";
        s = "XMin: "+ extent.xmin.toFixed(2) + " "
           +"YMin: " + extent.ymin.toFixed(2) + " "
           +"XMax: " + extent.xmax.toFixed(2) + " "
           +"YMax: " + extent.ymax.toFixed(2);
        dojo.byId("info").innerHTML = s;

I get this as output:

XMin: -9384566.21 YMin: 4732448.76 XMax: -7756763.25 YMax: 5357397.90

This is not even close. It appears to be a different format maybe using a different spatial reference? I would like to to be able to see the extent so I can set the extent I need for the map. However when I replace my existing Extent with these output numbers the page does not display. How can I get my extent in the correct format so I can see an extent and use those numbers to set it for my map?

2 Answers 2


When working with a map that uses web mercator as its spatial reference, you can use map.geographicExtent to get the map's extent in wgs84 (lat/lon coordinates).


The issue is of two differing spatial referenceses.

When you create an extent with:
var beginExt = new esri.geometry.Extent(-159.6716766, 19.520, -67.843, 64.8348, new esri.SpatialReference({wkid:4326}));

The extent is is WGS 84, with units in Lat-long. Most Probably your map is in Web mercator. Hence you are projecting from gcs wgs84 to webmercator with the following line of code:

var revExt = esri.geometry.geographicToWebMercator(beginExt);

When you use the function showExtent, it shows the extent in the map's spatial reference. Hence, the number are large, since the units are (pseudo) meters.

If you want to set the extent of your map to this extent, use the following code:

//102100 is the wkid for webmercator in ESRI's JSAPI
var ext=new esri.geometry.Extent(-9384566.21,4732448.76,-7756763.25,5357397.90, 
new esri.SpatialReference({wkid:102100 })); 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.