chrisoti

Simple projection problem, bad geometry

Discussion created by chrisoti on Nov 22, 2010
Latest reply on Nov 22, 2010 by chrisoti
Hello,

I'd like to do something rather simple, set up a web site to return a projected point from the url query string, so a completely programmatic geometry construction.  For some reason, I seem to be getting the creation of the spatial reference wrong.  Could someone take a look at this code and tell me what I'm doing wrong?

Thanks very much,
-chris

Here is the javascript portion of the script:
   dojo.require("esri.map");
   dojo.require("esri.tasks.geometry");

   function init() {
      var projector = new esri.tasks.GeometryService("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer");

      var x = queryString("X") *1.0;
      var y = queryString("Y") *1.0;
      var sr = new esri.SpatialReference( {wkid:4326} );    // is this the problem?
      var mapPoint = new esri.geometry.Point(x, y, sr);      // this seems to incorrectly created

      var outSR = new esri.SpatialReference({ wkid: 102113});

      projector.project([ mapPoint ], outSR, function(features) {
        pt = features[0].geometry;
        document.write("X="+pt.X+", Y="+pt.Y);
      });
    }

    function queryString(key) {
      var s = window.location.search.substring(1);
      var args = s.split("&");
      for (i=0;i<args.length;i++) {
        var kv = args[i].split("=");
        if (kv[0] == key) {
          return kv[1];
        }
      }
    }
 
    dojo.addOnLoad(init);

Outcomes