Select to view content in your preferred language

LabelPoints from GeometryService, am I missing something?

1006
1
10-13-2010 12:54 PM
PaulAbbott
New Contributor
I am attempting to label some selected polygon features using the following process:

1) Send the list of selected polygon features to a geometry service
2) Get the returned label points
3) For each returned point, add text based on the polygon's attributes to a graphics layer

So far 1 and 2 work fine, but the returned label points have no attributes!  I would have expected the geometry service to return the label point with all of the polygon's attributes intact so I would have something to label with, or at least the very least keep the ObjectID so I can go look up what I need.

How do I know which returned label point corresponds to which polygon, so I can retrieve the attributes needed for the label text?
0 Kudos
1 Reply
AliMirzabeigi
Emerging Contributor
The LabelPointsAsync() method of the GeometryService has a second parameter "userToken". When invoking this method also include your graphics list in the second parameter:
geometryService.LabelPointsAsync(graphicsList, graphicsList);

Then on LabelPointsCompleted event handler get the list of your graphics (with attributes) using "UserState" property of the GraphicsEventArgs, ie:
IList<Graphic> graphicsWithAttributes = e.UserState as IList<Graphic>;

The sequence of graphics in e.Results matches e.UserState hence, you just need to grab the attributes from the corresponding graphic in graphicsWithAttributes in above code snippet.
0 Kudos