Trouble getting geometry of projected point...

578
5
02-20-2012 05:26 AM
GISAdmin1
New Contributor III
I have a simple request to project a point:


var projectedPoint =  gsvc.project([hiddenFacilities], outSR, function(projectedPoints){ 
 pt = projectedPoints[0];
 return(pt);
});

var hiddenFacilitiesGraphic = new esri.Graphic(projectedPoint, markerSymbol, attr); 


How do I get the geometry of projected point.  I can see the coordinates after inspecting projectedPoint in Firebug.  I just can't seem to use the object to create a graphic.

Thanks in advance,

M
0 Kudos
5 Replies
nicogis
MVP Frequent Contributor
on callback or onProjectComplete or dojo.Deferred you get geometry projected

gsvc.project([ point ], outSR, function(projectedPoints) {  projectedPoint = projectedPoints[0]; var hiddenFacilitiesGraphic = new esri.Graphic(projectedPoint, markerSymbol, attr);});
0 Kudos
GISAdmin1
New Contributor III
I originally had my code structured like this>:
for (var i = 0; i < facilityMaster.length; i++) {

       gsvc.project([hiddenFacilities], outSR, function(projectedPoint){ 
               
       pt = projectedPoint[0];
       hiddenFacilitiesGraphic = new esri.Graphic();
       hiddenFacilitiesGraphic.setGeometry(pt);
       hiddenFacilitiesGraphic.setSymbol(markerSymbol);  
       hiddenFacilitiesGraphic.setAttributes(i);   
       parkNameLayer.add(hiddenFacilitiesGraphic);
       });

}



The problem is, the projected graphic is not getting the attribute "i" (setAttributes(i)).  The created graphics all have the same attribute.  I need the projected graphics to have a unique value.

Thanks!
0 Kudos
nicogis
MVP Frequent Contributor
The behaviour is right because the clousure provided by anonymous function passed to projected doesn't resolve the variable 'i' until it's resolved
0 Kudos
GISAdmin1
New Contributor III
Can you suggest another approach?  Can I create the graphic with the attributes and then project the graphic instead of just the point geometry?
0 Kudos
nicogis
MVP Frequent Contributor
Project has in input array of geometry. You can do your loop into function like:


       gsvc.project([hiddenFacilities], outSR, function(projectedPoint){ 
            for (var i = 0; i < facilityMaster.length; i++) {
    pt = projectedPoint;
                hiddenFacilitiesGraphic = new esri.Graphic();
                hiddenFacilitiesGraphic.setGeometry(pt);
                hiddenFacilitiesGraphic.setSymbol(markerSymbol);  
                hiddenFacilitiesGraphic.setAttributes(...);   
                parkNameLayer.add(hiddenFacilitiesGraphic);
          }
       });

0 Kudos