A bug of GeometryService.project?

583
2
09-25-2010 12:24 AM
RayGuo
by
New Contributor
hi

i am now using ags js api 2.1, the basemap's wkid is 102100, i need to transform the wkid to 4326 to display longitude and latitude.

i use this service: http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer

    dojo.connect(map, "onMouseMove", function(evt) {
        var gsvc = new esri.tasks.GeometryService('http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer');
        var pt;
        gsvc.project([evt.mapPoint], { "wkid": 4326 }, function(projectedPoints) {
            debugger;
            pt = projectedPoints[0];
        });
        coordinateBar.setText('ç»�度ï¼?' + pt.x + "ï¼?纬度ï¼?" + pt.y);
    });


when i call the gsvc.project method, it goes to
esri.request({url:this._url.path+"/project",content:_74e,callbackParamName:"callback",load:(function(r,i){_750(r,i,_74f,_74a,_74b,_74c)}


i monitor the variable "content:_74e", it is like the following

f "json"
geometries {"geometryType":"esriGeometryPoint","geometries":[{"x":-13299349.801652893,"y":4242526.207236842,"spatialReference":{"wkid":102100}}]}
inSR 102100
outSR 4326

according to the project service's parameters, the red part of "content:_74e" caused the problem

the following is the right parameters of project service

http://help.arcgis.com/EN/arcgisserver/10.0/apis/rest/project.html
Example:
{
"geometryType" : "esriGeometryPoint",
"geometries" : [
{"x" : -104.53, "y" : 34.74},
{"x" : -63.53, "y" : 10.23}
]
}

has anybody encountered the problem?
thanks!
0 Kudos
2 Replies
AxelSchaefer
New Contributor II
So, what is your error? 😉

Your request includes the definition of the input-geometry. Mostly, the coordinate-system is included in the JSON-format of the geometry, as it is in your case ("x":..., "y":...,"spatialReference":...). The inSR and outSR are also defined. But your line looks OK, except of a blank after the "geometries" name-attribute.

If you think you've got a wrong REST-request, I recommend a WebDeveloper-Tool for your Webbbrowser, like Firebug for Firefox, the developer tools in Chrome/Chromium or Opera Dragonfly. They are able to catch and list all the requests that are sent out of your webbrowser application. In this case you'll get the "project" requests to the geometry-service at http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer, like this:

http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer/project?inSR=1021...
0 Kudos
KellyHutchins
Esri Frequent Contributor
Instead of using the geometry service to project your point from Web Mercator to geographic you can use esri.geometry.webMercatorToGeographic to display your coordinates.
var mp = esri.geometry.webMercatorToGeographic(evt.mapPoint);
dojo.byId("info").innerHTML = mp.x + ", " + mp.y;


Take a look at the following sample that shows how this works:
http://help.arcgis.com/EN/webapi/javascript/arcgis/help/jssamples_start.htm#jssamples/map_xycoords.h...
0 Kudos