newtonpage

problem map extent functions

Discussion created by newtonpage on Jun 7, 2012
Latest reply on Jun 9, 2012 by hzhu
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:

// SET LISTENER ON MAP LOAD
dojo.connect(map, "onExtentChange", compareExtent)

// AT SOME TIME LATER DO THIS
map.setExtent(mapState.initialExtent) // this works

function compareExtent(extent, delta, levelChange, lod) {
// FAILS WHEN COMPARING THE FOLLOWING:
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
//HERE IS THE CONSOLE READ OUT
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

S

Outcomes