Is it possible to merge line features with the Javascript API?

05-05-2014 11:41 AM
New Contributor
Has anyone been able to successfully merge two or more line geometries with the JAPI?  If so, is there sample code somewhere?  The editor widget in the api provides a union tool but that only works for polygons.  Interestingly, the doc for the editor widget calls this operation a merge and not a union, but it is just a union of polygons.  That's a bit confusing since there is a difference between a merge and union operation.  And according to the doc, the geometry service only allows for a union and not a merge like you can do in ArcMap.  I'm trying to create a web app that will allow my editors to merge line features.  The following older post asked a similar question but it was never answered.

I would appreciate any insight as to how to do this with JAPI.
0 Kudos
2 Replies
Occasional Contributor

I haven't explored using the editor widget but here is a code sample that should get you started:

function mergeLines(graphicsArray) {

     // merge geometries of polyline graphics into one geometry (graphics array could be,, etc.)

     var polyline = new Polyline(map.spatialReference);

     for (var i = 0; i < graphics.length; i++){

          var paths = graphics.geometry.paths;

          for (var j = 0; j < paths.length; j++){ //needed for multi part lines




    return polyline;



var mergedGraphicGeometry = mergeLines();

0 Kudos
New Contributor III

If you have your own API deployed on your server go to the file ( and find:



To fix the bug with merging the above must be replaced with:

function(a){return a.geometryType&&a.visible&&a._isMapAtVisibleScale()}



For some reason Esri is checking if the geometry type is polygon before UNION function is used on the geometry server? WHY???


Removed "esriGeometryPolygon"===a.geometryType


Everything working as expected.

Hope this helps.