Calculating label points for polyline features

1022
1
11-24-2011 01:42 AM
AndyFrench
New Contributor
I am writing an application using the Silverlight toolkit to display pipe networks. I need to be able to annotate some of the pipes with additional data and to do this I would like to add a TextSymbol to the middle point of the pipe.

Calculating the center point of the bounding envelope is unsatisfactory when the pipe is curved or looped; the label ends up far away from the pipe.

I have tried to use the Geometry Service REST API and call the Label Points operation. However, it appears the Label Points operation doesn???t support Polylines (the pipes) but only Polygons. Attempting to pass the Polylines to the Geometry Service results in an ???Object reference not set to an instance of an object??? error being returned.

Does anyone have any suggestions about how I can get the Label Point for a Polyline?
0 Kudos
1 Reply
AndyFrench
New Contributor
I can answer my own question.
I used the Buffer operation to do the conversion for me. It seems to work quite well. Something like this:

public void SomeMethod()
{
    _geometryService = new GeometryService("some URL here...");
    _geometryService.LabelPointsCompleted += OnLabelPointsCompleted;
    _geometryService.SimplifyCompleted += OnSimplifyCompleted;
    _geometryService.BufferCompleted += OnBufferCompleted;

    _geometryService.SimplifyAsync(_polylines); // Start by simplifying the polyline graphics to find the label points for
}

private void OnSimplifyCompleted(object sender, GraphicsEventArgs e)
{
    var bufferParams = new BufferParameters();
    bufferParams.BufferSpatialReference = _spatialReference; // whatever spatial reference you need
    bufferParams.OutSpatialReference = _spatialReference;
    bufferParams.Unit = LinearUnit.Centimeter;
    bufferParams.Distances.Add(1.0d);
    bufferParams.Features.AddRange(e.Results);

    _geometryService.BufferAsync(bufferParams);
}

private void OnBufferCompleted(object sender, GraphicsEventArgs e)
{
    _geometryService.LabelPointsAsync(e.Results);
}

private void OnLabelPointsCompleted(object sender, GraphicsEventArgs e)
{
    // Do someting with label points...
}
0 Kudos