Select to view content in your preferred language

Project function fails - Cannot read property 'spatialReference' of undefined

8287
5
03-06-2013 06:40 AM
MatthewLawton
Deactivated User
This has been giving me fits. Why doesn't this work?

function showCoordinatesNew(evt) {
 var mp = esri.geometry.webMercatorToGeographic(evt.mapPoint);
 console.log(mp.x+","+mp.y); //<-- returns correct geographic coordinates
 console.log(mp.spatialReference.wkid); //<-- returns wkid 4326
 var params = new esri.tasks.ProjectParameters();
 params.geometries = mp;
 //setting output Spatial Reference to Nevada State Plane West Zone NAD83
 params.outSR = new esri.SpatialReference({wkid: 102709});
 //execute project function, callback will be picked up by onProjectComplete
 gsvc.project(params); //<-- fails with Uncaught TypeError: Cannot read property 'spatialReference' of undefined
}
       
function onProjectComplete(geometries) {
 //project function never gets this far.
 var mp = geometries[0];
 console.log("Returned Coordinates: " + mp.x + "," + mp.y);
 convertSP(mp.x,mp.y);
}

function onError(message) {
 alert(message);
}


Here is the full error:

Uncaught TypeError: Cannot read property 'spatialReference' of undefined serverapi.arcgisonline.com:34
dojo.declare.toJson serverapi.arcgisonline.com:34
dojo.declare.project serverapi.arcgisonline.com:34
showCoordinatesNew QuickMap32.js:192
_4ff.(anonymous function)._504 serverapi.arcgisonline.com:15
_599._fire serverapi.arcgisonline.com:34
_599._onMouseMoveHandler serverapi.arcgisonline.com:34
(anonymous function)
0 Kudos
5 Replies
JohnGrayson
Esri Alum
It's expecting an array of geometries; try this:

params.geometries = [mp];
0 Kudos
MatthewLawton
Deactivated User
Your result, sir:

Error {code: 400, message: "JSON syntax error", details: Array[1], log: undefined, _ssl: undefined}
_ssl: undefined
code: 400
details: Array[1]
get stack: function () { [native code] }
log: undefined
message: "JSON syntax error"
set stack: function () { [native code] }
__proto__: d
serverapi.arcgisonline.com:15
(anonymous function) serverapi.arcgisonline.com:15
reject.errback serverapi.arcgisonline.com:15
dojo.declare._errorHandler serverapi.arcgisonline.com:34
(anonymous function) serverapi.arcgisonline.com:15
dfd._pendingDfd.esri.request.error serverapi.arcgisonline.com:34
(anonymous function) serverapi.arcgisonline.com:34
_1c6 serverapi.arcgisonline.com:15
_1c4 serverapi.arcgisonline.com:15
reject.errback serverapi.arcgisonline.com:15
_1c6 serverapi.arcgisonline.com:15
_1c4 serverapi.arcgisonline.com:15
reject.errback serverapi.arcgisonline.com:15
_1c6 serverapi.arcgisonline.com:15
_1c4 serverapi.arcgisonline.com:15
reject.errback serverapi.arcgisonline.com:15
(anonymous function) serverapi.arcgisonline.com:34
_1c6 serverapi.arcgisonline.com:15
_1c4 serverapi.arcgisonline.com:15
reject.errback serverapi.arcgisonline.com:15
_1c6 serverapi.arcgisonline.com:15
_1c4 serverapi.arcgisonline.com:15
resolve.callback serverapi.arcgisonline.com:15
_1c6 serverapi.arcgisonline.com:15
_1c4 serverapi.arcgisonline.com:15
resolve.callback serverapi.arcgisonline.com:15
_1c6 serverapi.arcgisonline.com:15
_1c4 serverapi.arcgisonline.com:15
resolve.callback serverapi.arcgisonline.com:15
_1c6 serverapi.arcgisonline.com:15
_1c4 serverapi.arcgisonline.com:15
resolve.callback serverapi.arcgisonline.com:15
_437 serverapi.arcgisonline.com:15
func serverapi.arcgisonline.com:15
_430
0 Kudos
MatthewLawton
Deactivated User
I am getting some weird results from params.outSR. I modified the outSR to include BOTH the wkid and wkt for good measure and then logged the result as follows:

params.outSR = new esri.SpatialReference({wkid:102709,wkt:'PROJCS["NAD_1983_StatePlane_Nevada_West_FIPS_2703_Feet",GEOGCS["GCS_North_American_1983",DATUM["D_North_American_1983",SPHEROID["GRS_1980",6378137,298.257222101]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]],PROJECTION["Transverse_Mercator"],PARAMETER["False_Easting",2624666.666666666],PARAMETER["False_Northing",13123333.33333333],PARAMETER["Central_Meridian",-118.5833333333333],PARAMETER["Scale_Factor",0.9999],PARAMETER["Latitude_Of_Origin",34.75],UNIT["Foot_US",0.30480060960121924]]'});
console.log(params.outSR);


Here is the log return that I get from this:

Object {wkid: 102709, wkt: "PROJCS["NAD_1983_StatePlane_Nevada_West_FIPS_2703_�?�igin",34.75],UNIT["Foot_US",0.30480060960121924]]", wkid: null, wkt: null, _info: Object�?�}
wkid: 102709
wkt: "PROJCS["NAD_1983_StatePlane_Nevada_West_FIPS_2703_Feet",GEOGCS["GCS_North_American_1983",DATUM["D_North_American_1983",SPHEROID["GRS_1980",6378137,298.257222101]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]],PROJECTION["Transverse_Mercator"],PARAMETER["False_Easting",2624666.666666666],PARAMETER["False_Northing",13123333.33333333],PARAMETER["Central_Meridian",-118.5833333333333],PARAMETER["Scale_Factor",0.9999],PARAMETER["Latitude_Of_Origin",34.75],UNIT["Foot_US",0.30480060960121924]]"
__proto__: Object


Notice that there are wkid and wkt values that are correctly populated, BUT then there are two more wkid and wkt values that are set to null. What gives? Maybe this is the spatial reference that is not being correctly populated, but why?
0 Kudos
MatthewLawton
Deactivated User
So I created a very simple app with the same project function as above, except I stored it directly in the script tag in the html file instead of referencing to an external js file, and it works. But if I reference the exact same code in an external js file then it errors on the project output.
0 Kudos
MatthewLawton
Deactivated User
After hours of combing through all of my code, I finally isolated the problem. I use the Prototype framework to run a pull-down list in my application. Apparently the reference to that framework was conflicting with the project function. I don't know what the conflict is, but that is what is causing all of my problems.
0 Kudos