gsvc.project([ graphic ], outSR, function(features) method does not run

930
3
Jump to solution
11-15-2012 11:15 PM
PrasannaRaghavendar
New Contributor III
Hi,
I am new to this Arcgis javascript API.
    function projectToWebMercator(evt) {       map.graphics.clear();       var point = evt.mapPoint;       var symbol = new esri.symbol.SimpleMarkerSymbol().setStyle(esri.symbol.SimpleMarkerSymbol.STYLE_DIAMOND);       var graphic = new esri.Graphic(point, symbol);       var outSR = new esri.SpatialReference({ wkid: 102113});       map.graphics.add(graphic);       alert("Before method");       gsvc.project([ graphic ], outSR, function(features) {         alert("inside method");         pt = features[0].geometry;         graphic.setInfoTemplate(new esri.InfoTemplate("Coordinates",           "<p> X: " + pt.x +           "<br/> Y: " + pt.y +           "</p>"  +           "<input type='button' value='Convert back to LatLong' onclick='projectToLatLong();' />" +           "<div id='latlong'></div>"));         map.infoWindow           .setTitle(graphic.getTitle())           .setContent(graphic.getContent())           .show(evt.screenPoint, map.getInfoWindowAnchor(evt.screenPoint));       });     }



In the above code, gsvc.project([ graphic ], outSR, function(features) method does not run. I get the "Before method"-alert. But I don't get "inside method"-alert. Please do help me in resolving the issue. What could be the possible solution?

PS: I have declared gsvc as a global variable and defined it inside a init() function like
gsvc = new esri.tasks.GeometryService("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer");


Thanks
Prasanna
0 Kudos
1 Solution

Accepted Solutions
PrasannaRaghavendar
New Contributor III
Hi Arkitech,
I was using api version 3.2 but referred to 1.6 sample.
I changed the definition of gsvc like
gsvc = new esri.tasks.GeometryService("http://tasks.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer");


It works now

Thanks
Prasanna

View solution in original post

0 Kudos
3 Replies
AndyBurns
Occasional Contributor
Hi

code looks okay, i get mine working like this

function zoomToLocation(location) {


        // use this if basemap is WGS84 --- var pt = esri.geometry.geographicToWebMercator(new esri.geometry.Point(location.coords.longitude, location.coords.latitude));
        //otherwise, use this stuff below - basically we make a new point with the geolocated coordinates and reproject it, but to do so, you make the point
        //first and specify it's originating spatial reference so then you can reproject it to your own wkid

        var pt = new esri.geometry.Point(location.coords.longitude, location.coords.latitude, new esri.SpatialReference({wkid: 4236})); //don't forget to specify the originating wkid (in this case from the GPS/Geolocation)
        
        var outSR = new esri.SpatialReference({ wkid: 27700});
        gsvc.project([ pt ], outSR, function(projectedPoints) {
  pt = projectedPoints[0];
  map.centerAndZoom(pt, 12);
   //add graphic at current location - if graphic exists just move it
   if (!graphic) {
          addGraphic(pt);
        }
        else { //move the graphic if it already exists
          graphic.setGeometry(pt);
        }
        map.centerAt(pt);
      })
   }


this converts from web mecator to british national grid. I set a global var - var gsvc = null; then specify the service like you do
gsvc = new esri.tasks.GeometryService("local server");


Let us know how you get on, you should be getting some error with firebug etc.
0 Kudos
PrasannaRaghavendar
New Contributor III
Hi Arkitech,
I was using api version 3.2 but referred to 1.6 sample.
I changed the definition of gsvc like
gsvc = new esri.tasks.GeometryService("http://tasks.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer");


It works now

Thanks
Prasanna
0 Kudos
AndyBurns
Occasional Contributor
good stuff, enjoy 🙂
0 Kudos