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

3555
2
05-05-2014 11:41 AM
SteveClarke
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.

http://forums.arcgis.com/threads/47155-Editor-Widget-Union-Tool-and-Polyline-features?highlight=merg...

I would appreciate any insight as to how to do this with JAPI.
0 Kudos
2 Replies
BrandonFlessner
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 map.graphics.graphics, featureLayer.graphics, 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

          polyline.addPath(paths);

          }

     }

    return polyline;

}

 

var mergedGraphicGeometry = mergeLines();

0 Kudos
AndrzejBieniek
New Contributor III

If you have your own API deployed on your server go to the file (https://js.arcgis.com/3.18/esri/dijit/editing/Editor.js) and find:

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

 

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.

Regards,

Andrzej