Select to view content in your preferred language

Correct method for sending graphics array for reproject

793
2
07-27-2010 09:16 PM
DrewDowling
Frequent Contributor
I need to send a collection of points to a geometry service for reprojection. The points are in a graphics layer from when the users clicked on the map.

the code I am using is:

var arraycollhope:Object;
arraycollhope = myXYGraphicsLayer.graphicProvider
var outSR:SpatialReference = new SpatialReference(2230);
geometry1.project(arraycollhope.toArray(), outSR);

where myXYGraphicsLayer is the graphics layer.
This seems to work but what i don't understand why. arraycollhope is defined as an object not as an array collection. If I define it as an array collection I get an implicit conversion error as myXYGraphicsLayer.graphicProvider returns an object. Yet when I call the method .toArray it appears to work, even though this isn't a method on IObject. To me this implies an implicit conversion anyway.

Is there another preferred way of doing this?

Thanks for any help or comments

Drew
Tags (2)
0 Kudos
2 Replies
RobertScheitlin__GISP
MVP Emeritus
Drew,

   The way that you are doing it is fine. The graphicProvider of a graphicsLayer return value is type object (normally that object is an array collection). You could do
var arraycollhope:ArrayCollection;
arraycollhope = myXYGraphicsLayer.graphicProvider  as ArrayCollection;
The project method is expecting and Array (not ArrayCollection) so that is why you have to use
arraycollhope.toArray()
0 Kudos
DrewDowling
Frequent Contributor
Thanks Robert, helpful as always.

This still feels a little hokey to me. I basically had to guess that myXYGraphicsLayer.graphicProvider returned an array collection. It's kind of obvious but if I had to guess here I'm worried that there are other places down the line that it won't be obvious.

I like your way of using the "as ArrayCollection;" declaration during the assignment. Its a little more structured.

Cheers

Drew
0 Kudos