Select to view content in your preferred language

GeometryService Project

2036
2
05-28-2010 07:49 AM
GeoffreyMahase
Emerging Contributor
I'm trying to do a basic sample of using the Geometry Service Project method, and I can't seem to get it working.  I know I'm probably just doing something stupid and can't spot it.  I've loaded the map and that's all working, I'll just post the code for the project.

            dojo.require("esri.map");

            function onProjectComplete(graphics)
            {
                console.log(graphics);            
            }
            
            function onError()
            {
                console.log("Error");
            }
            
            function doStuff()
            {
                console.log("dostuff");                
                var geoservice = new esri.tasks.GeometryService("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer");
                var sourcewkid = new esri.SpatialReference({ "wkid": 2263 });
                var destwkid = new esri.SpatialReference({ "wkid": 4326 });
                var point = new esri.geometry.Point(975762, 171410, sourcewkid);
                console.log(sourcewkid, destwkid, point);
                try
                {
                    geoservice.project([point], destwkid, onProjectComplete, onError);
                }
                catch(err)
                {
                    console.log(err);
                }
                var infoTemplate = new esri.InfoTemplate("Test","test: ${test}");
                var attr = {"test":"test"};
                var sms = new esri.symbol.SimpleMarkerSymbol().setStyle(
                             esri.symbol.SimpleMarkerSymbol.STYLE_SQUARE).setColor(
                             new dojo.Color([255,0,0,0.5]));
                var test = new esri.Graphic(point, sms, attr, infoTemplate);
                map.graphics.add(test);
            }


I keep getting an error saying "TypeError: Cannot read property 'spatialReference' of undefined" in chrome.  And an error in Firefox firebug ""_63f[0].geometry is undefined".
0 Kudos
2 Replies
derekswingley1
Deactivated User
Since you're sending an array with geometry (as opposed to graphics), point your code to a 10 geometry service:  http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer

See http://help.arcgis.com/en/webapi/javascript/arcgis/help/jshelp_start.htm#jshelp/migration_20.htm
0 Kudos
GeoffreyMahase
Emerging Contributor
Since you're sending an array with geometry (as opposed to graphics), point your code to a 10 geometry service:  http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer

See http://help.arcgis.com/en/webapi/javascript/arcgis/help/jshelp_start.htm#jshelp/migration_20.htm


I knew it was something stupid...should have gotten more sleep last night.  I kept looking at the function and wondering what was wrong.  In my head I kept thinking I wanted to convert one point to another.

But anyway...Thanks 🙂
0 Kudos