Select to view content in your preferred language

Display polygon results from geographic to WebMercator coordinates

911
4
01-03-2013 11:04 AM
DonCaviness
Occasional Contributor
I am querying a service that returns back a polygon dataset which have geographic coordinates.  I want to convert the coordinates to WebMercator coordinates so the polygon can be displayed in the correct location.  I have tried several things with little success.  This seems extremely easy to accomplish but I'm just missing something.  Any help is appreciated.  Here is the code I'm using that displays the polygon in geographic coordinates.

var responseObj = eval('(' + response + ')');
                
var fs = new esri.tasks.FeatureSet(responseObj.RecordSet);
                    
    for (var i = 0; i < fs.features.length; i++) {
                    
        var gra = fs.features;
        if (i == 0) {
            var polySymbolBlue = new esri.symbol.SimpleFillSymbol();
            polySymbolBlue.setOutline(new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([0, 0, 0, 1]), 1));
                polySymbolBlue.setColor(new dojo.Color([48, 48, 100, 1]));
                 gra.setSymbol(polySymbolBlue);
        }
                        
    map.graphics.add(gra);
                    
    //  Zoom to the collection of features
    map.setExtent(esri.graphicsExtent(fs.features));
}


Here is a sample of what is returned from the service that the responseObj variable gets populated from:

{"TaskMessagesArray":[],"StdGeographiesFeatures":[{"FeatureID":"718","FeatureName":"Jackson,MS"}],
"RecordSet":{"geometryType":"esriGeometryPolygon","spatialReference":{"wkid":4326},
"features":[{"attributes":{"ID":"718","NAME":"Jackson,MS",
"Gen4_Length":13.660685252638258,"Gen4_Area":3.4404911073537887},
"geometry":{"rings":[[[-91.043553,32.57627],
.................
,[-91.043553,32.57627]]],"spatialReference":{"wkid":4326}}}]}}
0 Kudos
4 Replies
DonCaviness
Occasional Contributor
Does anyone have any ideas on how to accomplish this conversion?
0 Kudos
KellyHutchins
Esri Notable Contributor
Don,

You can use
esri.geometry.geographicToWebMercator
to convert a geometry from geographic coordinates to Web Mercator.

View the API reference for more details:

http://help.arcgis.com/en/webapi/javascript/arcgis/help/jsapi/namespace_geometry.htm
0 Kudos
DonCaviness
Occasional Contributor
Thanks Kelly.  I was actually able to get this to work without have to convert the coordinates.  I am using a BAO service and it turns out the BAO REST API page omitted an input parameter for the service I am using.  On a hunch I figured it out.
0 Kudos
JeffJacobson
Frequent Contributor
What kind of service are you querying? ArcGIS Server map services and most GP services will allow you to specify the output coordinate system. You should be able to request the output coordinate system to match your map.
0 Kudos