Select to view content in your preferred language

Create a multipart polyline.

2680
2
05-25-2011 05:59 AM
CraigGallant
Deactivated User
Hello All,

I???m trying to create a multipart polyline and I am having trouble with it adding connection lines when I add it to the feature layer. I start by adding the line graphic to a PointCollection.


ObservableCollection<PointCollection> lpc = new ObservableCollection<PointCollection>();

PointCollection PC = new PointCollection();



void LineDrawingSurface_DrawComplete(object sender, DrawEventArgs e)
{
         GraphicsLayer linegraphicsLayer = MyMap.Layers["LineDrawGraphicsLayer"] as GraphicsLayer;

         ESRI.ArcGIS.Client.Graphic graphic = new ESRI.ArcGIS.Client.Graphic()
         {
                Geometry = e.Geometry,
                Symbol = MyLineSymbol
         };

        linegraphicsLayer.Graphics.Add(graphic);


        Polyline PL = graphic.Geometry as Polyline;
                                  
           
        for (int i = 0; i < PL.Paths.Count; i++)
        {
                foreach (var mp in PL.Paths)
                {
                    PC.Add(mp);
                }
        }

                       
        lpc.Add(PC);

}


Next I draw two lines on the graphic layer. This shows two separate graphics like I want. Now when I???m done and press the save button I create a polyline and set it to the pointcollection. Then I create a graphic and set is geometry to the polyline. Finally I add the graphic to the featurelayer and save edits.



private void btnSave2_Click(object sender, RoutedEventArgs e)
{
         GraphicsLayer linegraphicsLayer = MyMap.Layers["LineDrawGraphicsLayer"] as GraphicsLayer;
         linegraphicsLayer.ClearGraphics();

         Polyline pl = new Polyline();
         pl.Paths = lpc;
         pl.SpatialReference = MyMap.SpatialReference;
 
         Graphic graph = new Graphic();
         graph.Geometry = pl;

         FeatureLayer fLayer = MyMap.Layers["FeatureLayer"] as FeatureLayer;

         fLayer.Graphics.Add(graph);

         fLayer.EndSaveEdits += Insert_EndSaveEdits;
          fLayer.SaveEdits();

}





Now this all works fine but the problem is the polyline is one continuous line and not two separate lines as a multipart record as originally draw on the graphic layer. I have attached a image of what it is doing.

So how can get it to skip the line in the middle when I???m writing the record?

Thanks,
Craig
0 Kudos
2 Replies
JenniferNery
Esri Regular Contributor
If you are using Editor.Add or TemplatePicker or EditorWidget, you can add two polyline features from your FeatureLayer, select both of them and create union. What this gives you is a Polyline with two Paths.

If you are using Draw, you can do something like this, where you grab the point collection from DrawComplete and add to the polyline path.
Polyline polyline = new Polyline();
void draw_DrawComplete(object sender, DrawEventArgs e)
{
 draw.IsEnabled = false;
 GraphicsLayer l = this.MyMap.Layers["MyGraphicsLayer"] as GraphicsLayer;
 Symbol s = this.LayoutRoot.Resources["MyRedLineSymbol"] as Symbol;
 if (polyline.Paths.Count == 2)
 {
  l.Graphics.Clear();
  l.Graphics.Add(new Graphic() { Geometry = polyline, Symbol = s });
 }
 else
 {
  polyline.Paths.Add((e.Geometry as Polyline).Paths[0]);
  l.Graphics.Add(new Graphic() { Geometry = e.Geometry, Symbol = s });
 }
}
0 Kudos
CraigGallant
Deactivated User
Thank you,

This is the line of code I needed.

"polyline.Paths.Add((e.Geometry as Polyline).Paths[0]);"



Craig
0 Kudos