Solved! Go to Solution.
I have an array of individual route graphics that I would like to be combined into one graphics layer. I am looking for the best way to do this.
Right now I add the routes to the map using map.graphics.add(solveResult.routeResults[0].route.setSymbol(routeSymbol));
What would be the best method of combining these routes into one polyline graphics layer? Thanks in advance.
require([ "dojo/_base/array", "esri/map", "esri/layers/GraphicsLayer" ], function(array, Map, GraphicsLayer){ var map = new Map("mapDiv"); var graphics = new GraphicsLayer(); map.addLayer("graphics"); //Create your array here array.forEach(solveResult.routeResults, function(routeResult){ graphics.add(routeResult.route.setSymbol(routeSymbol)); }); });
Not tested but this should work:require([ "dojo/_base/array", "esri/map", "esri/layers/GraphicsLayer" ], function(array, Map, GraphicsLayer){ var map = new Map("mapDiv"); var graphics = new GraphicsLayer(); map.addLayer("graphics"); //Create your array here array.forEach(solveResult.routeResults, function(routeResult){ graphics.add(routeResult.route.setSymbol(routeSymbol)); }); });
If you've got access to a geometryServer I would suggest using GeometryService.union to combine the geometries of your routes together.
Here is an example using the geometry service but it is performing a reshape. I think the main thing you would have to change is to get it to do a union instead that is passed an array of your graphics geometries.