Add point to multipath

918
2
12-27-2011 07:26 PM
User123
New Contributor
I'm trying to use multipath to draw a polyline on map.

I have a list of point.

              18301.4356455055, 36146.9169192426
              18885.8294820658, 35820.7585324813
              19550.6387151067, 35448.3823042103
              19679.1625972969, 35397.5744970106
              19731.6957098375, 35383.8743903451

How can i add them in multipath and draw a polyline on the map?

If anyone can help.

Thank you
0 Kudos
2 Replies
DanO_Neill
Occasional Contributor III
Since Polyline inherits from Multipath you can do something like the following workflow to create a Polyline from your list:

1. Create Point from list
Point pntStart = new Point(18301.4356455055, 36146.9169192426);
Point pntEnd = new Point(18885.8294820658, 35820.7585324813);
2. Create Segment from your Points
Segment seg1 = new Segment();
seg1.setStart(pntStart);
seg1.setEnd(pntEnd);
3. Add Segment to Polyline
Polyline p = new Polyline();
p.addSegment(seg1, true);
0 Kudos
NigelDsouza
Occasional Contributor
hey
What you could also do is create an point array list like.
ArrayList<Point> points = new ArrayList<Point>();
*then populate this arrayilst with your points put the starting point at the 0'th index on the list ant the last at the last index of thr list.
*The create a multipath object. and run a loop that populates the multipath object with values from your array list.

Multipath multipath  = new Polygon()/Polyline()
multipath.startPath(points.get(0));
for (int i = 1; i < points.size(); i++) {
  multipath.lineTo(points.get(i));
}
Then create a symbol for it.
*
graphic = new Graphic(multipath,new SimpleLineSymbol(Color.BLACK, 4));

or for polygon

SimpleFillSymbol simpleFillSymbol = new SimpleFillSymbol(
    Color.TRANSPARENT);
  simpleFillSymbol.setAlpha(100);
  simpleFillSymbol.setOutline(new SimpleLineSymbol(Color.BLACK, 4));
  graphic = new Graphic(multipath,(simpleFillSymbol));
cheers!!
0 Kudos