Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

In using the JS API, I need to detect if the current extent matches the initial extent. If no match, then I need to display a UI element ("Return to Original Extent").

The initial extent is cached in a data store after the map loads (in my own object mapState.initialExtent). This is properly configured as an instance of an esri extent. I can trigger the map to move to this extent successfully.

I have created a listener on the map (onExtentChange) which calls a function which compares the current extent to the initial extent. It seems the best way to do this is to compare the x/y min/max which is fine and works EXCEPT that BOTH the return from the call to map.extent AND the extent return by the listener are inaccurate.

That is: if I do this:


dojo.connect(map, "onExtentChange", compareExtent)

// this works

function compareExtent(extent, delta, levelChange, lod) {

 var currentExtent = map.extent;
 var returnedExtent = extent;
 var initialExtent = mapState.initialExtent;

console.log("currentExtent.xmin", currentExtent.xmin, "initialExtent.xmin",        initialExtent.xmin, "extent.xmin", extent.xmin);
console.log("currentExtent.ymin", currentExtent.ymin, "initialExtent.ymin", initialExtent.ymin, "extent.ymin", extent.ymin);

//these do not match
currentExtent.xmin -8476373.507203963 
initialExtent.xmin -8476287.515547141 
extent.xmin -8476373.507203963

currentExtent.ymin 4412584.280379601 
initialExtent.ymin 4412589.057693868 
extent.ymin 4412584.280379601


So, I checked to see if this listener actually returns BEFORE the map is finished but it does not.

Anyone have ideas?

Thanks to all


I am sorry this is not clear. I set the map to the initial extent, change the extent in response to a UI event and then return to the initial extent: the values do not match though the map appear to be correct.

To be clear, on map init I set the extent to initialExtent - using setExtent(initialExtent) where initialExtent is a cached instance of an extent. I then go to a different cached extent and later return to initialExtent. The console shows the returns.

The value currentExtent.xmin -8476373.507203963 is what is returned by the listener.

The value initialExtent is what is initially cached (which is passed as the argument in both the first and the final setExtent function - - this value is initialExtent.xmin -8476287.515547141.

The following value is what is returned by map.extent after the listener fires after setExtent(initialExtent):extent.xmin -8476373.507203963

I expect these 3 values to be same.

share|improve this question
If you can edit your post, you should add more detail to the title; just naming the general subject area is not likely to garner many views. –  tmcw Jun 7 '12 at 14:21
I am confused as to the nature of your problem. In your 'compareExtent' function, it is expected that the extent argument passed into that function would equal the current map extent. Your console read out verifies that, as the 'currentExtent' values are equal to that of 'extent'. And the 'initialExtent' doesn't match either of them. –  user890 Jun 7 '12 at 16:24
add comment

1 Answer

The differences may be due to the map levels. If you have a tiled service that defines the LODs of the map, when you set the initial extent it will actually adjust to the closest LOD (map.level) that can match the given initialExtent you provided. I'm not completely sure, but it's something that has bitten me before.

share|improve this answer
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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