Select to view content in your preferred language

map.extent issue using webMercatorToGeographic utility method

800
3
03-31-2011 03:17 PM
PayamPayandeh1
New Contributor
Hello,

I am trying to find the bounding box that I derived from the map.extent. Inside a Widget i have the following code:

var extent:Extent = map.extent;
if(map.spatialReference.wkid != 4326)
{
var geom:Geometry = extent as Geometry;
geom = WebMercatorUtil.webMercatorToGeographic(geom);
extent = geom as Extent;
}
var bbox:String = extent.xmin + "," + extent.ymin + "," + extent.xmax + "," + extent.ymax;
Alert.show( "bbox = " + bbox );

I zoom out where the whole world is showing and I would think I would get something very close to:
bbox = -180,-90,180,90

instead I get (not consistently):

bbox = 132.1875000001546,-89.10609998620168,-132.1875000001546,89.10609998620168

and if I move the map (which is the whole world), which is still smaller than the window it is positioned in I get:

bbox = -30.355906316675714,-89.15909109779587,65.26909368301506,89.04976985003408

Does anyone have any ideas what I am doing wrong, I am new to GIS, not programming though.

Thanks in advance.
Tags (2)
0 Kudos
3 Replies
PayamPayandeh1
New Contributor
Ok, so after looking at the output when zoomed in closer, like at the continental level and closer, it seems to be producing the correct lat/lon extents. Its only when the whole world is exposed that it starts generating incorrect results.
0 Kudos
ScottErwin
New Contributor
I am seeing this same issue.  Did you ever find a solution??
0 Kudos
PayamPayandeh
New Contributor
I needed the values to generate queries passed to a web service, so this might not be a solution to what you are trying to do, but I basically check the value and truncate if its outside of the allowed values.

public function getMinLat() : String
{
    var ext:Extent = map.extent as Extent;
    if (ext.ymin < -90 ){
        return "-90"
    } else {
        return String(ext.ymin)
    }
}
   
public function getMaxLat() : String 
{
    var ext:Extent = map.extent as Extent;
    if (ext.ymax > 90 ){
        return "90";
    } else {
        return String(ext.ymax)
    }
}
   
public function getMinLon() : String 
{
    var ext:Extent = map.extent as Extent;
    if (ext.xmin < -180 ) {
        return "-180";
    } else {
        return String(ext.xmin)
    }
}
   
public function getMaxLon() : String
{
    var ext:Extent = map.extent as Extent;
    if ( ext.xmax > 180) {
        return "180";
    } else {
        return String(ext.xmax)
    }
}


I hope this helps,

-Payam
0 Kudos