Select to view content in your preferred language

draw line programmatically

3404
8
06-04-2013 02:54 PM
LefterisKoumis
Frequent Contributor
Similar to the polylines that google overlays on their map, I am looking for a similar functionality to draw a line on a map based on predefined sets of coordinates. The app for the hurricanes provides this functionality at http://www.arcgis.com/home/webmap/viewer.html?webmap=2f5a28f82f4d41ec8dbe6cf96375a970.

Any ideas?
Tags (2)
0 Kudos
8 Replies
RhettZufelt
MVP Notable Contributor
the hurricane map looks like it is consuming a feed with the track data so the line is pre-rendered.

Are you looking for a way to make a service that updates itself when the points of the line change (like from an event theme) or actually having someone enter two coordinates in the flexviewer, and having it draw the line?

R_
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Lefteris,

   Drawing a line programatically is quite simple you just create an array of points and add them to a polylines path.

                            var pA:Array;
                             pA = [];
                            //just some loop to add all your XYs for your lines points
                            for (m=0; m<gArrObj.length; m++){
                                pA.push(new MapPoint(X,Y,new SpatialReference(102100)));
                            }
                            var pLine:Polyline = new Polyline(null,new SpatialReference(102100));
                            pLine.addPath(pA);
                            var gra:Graphic = new Graphic(pLine);
                            graphicsLayer.add(gra);
0 Kudos
LefterisKoumis
Frequent Contributor
the hurricane map looks like it is consuming a feed with the track data so the line is pre-rendered.

Are you looking for a way to make a service that updates itself when the points of the line change (like from an event theme) or actually having someone enter two coordinates in the flexviewer, and having it draw the line?

R_


Thanks for the reply. The second case, to enter two coordinates in the flexviewer, and having it draw the line.
0 Kudos
RhettZufelt
MVP Notable Contributor
In that case, it looks like Robert has put you on the right track.

R_
0 Kudos
LefterisKoumis
Frequent Contributor
Lefteris,

   Drawing a line programatically is quite simple you just create an array of points and add them to a polylines path.

                            var pA:Array;
                             pA = [];
                            //just some loop to add all your XYs for your lines points
                            for (m=0; m<gArrObj.length; m++){
                                pA.push(new MapPoint(X,Y,new SpatialReference(102100)));
                            }
                            var pLine:Polyline = new Polyline(null,new SpatialReference(102100));
                            pLine.addPath(pA);
                            var gra:Graphic = new Graphic(pLine);
                            graphicsLayer.add(gra);


Thank you Robert. Very similar to the google javascript code. A challenging task is to overlay a section of a line from a line layer and following its path. Other than inserting multiple points on the line I don't see any other way to be done.
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Lefteris,

   I am not sure if there is question in your last post or not...?
0 Kudos
LefterisKoumis
Frequent Contributor
In that case, it looks like Robert has put you on the right track.

R_

Yes. Thank you.
0 Kudos
LefterisKoumis
Frequent Contributor
Lefteris,

   I am not sure if there is question in your last post or not...?

Sorry for confusion....I was just throwing my thoughts out about overlay over a section of a line without the need of multiple points to establish the path of the overlay over the line. For example, if you need to overlay a section of a road to show the project limits, how can you do it other than inserting multiple points along the section? I don't think there is anything out there yet...
0 Kudos