Select to view content in your preferred language

Simple projection problem, bad geometry

1206
1
11-22-2010 01:31 AM
ChrisBennett
New Contributor
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.split("=");
        if (kv[0] == key) {
          return kv[1];
        }
      }
    }
 
    dojo.addOnLoad(init);
0 Kudos
1 Reply
ChrisBennett
New Contributor
Problem solved.  Chalk it up to working too late and giving it a fresh look.  The main problem here was the incorrect output WKID (needs to be 102100).  Other problems include trying to reference 'features[0].geometry' (doesn't exist), and wrong case on 'pt.X' and 'pt.Y'. 

But it is very reassuring to be able to generate these objects programmatically.  I've had problems in the past, and I'd never seen examples that didn't use at least one component returned from the map.

Cheers.
0 Kudos