ArcGIS Maps SDK for JavaScript – Understanding Extent Formats

arcgis-javascript-apiextents

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?

Best Answer

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).