Combining Multiple Graphics

2320
4
Jump to solution
01-29-2014 06:06 PM
WesleyAskew
New Contributor III
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.
0 Kudos
1 Solution

Accepted Solutions
JamieSimko
New Contributor III
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.

View solution in original post

0 Kudos
4 Replies
JohnathanBarclay
Occasional Contributor
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.


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));
  });

});
0 Kudos
WesleyAskew
New Contributor III
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));
  });

});


Thanks for your response.  However, this does not seem to work as I had hoped.  I guess the best way for me to describe what i need is something similar to a merge in ArcMap.  I am not concerned with the attributes, I just need for each route that is calculated by the routeTask to be combined into one in order to perform tasks like zooming to extent, symbolizing, etc.  Am I missing something with this method or is there another way of going about this?
0 Kudos
JamieSimko
New Contributor III
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.
0 Kudos
WesleyAskew
New Contributor III
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.


This is exactly what I have been looking for.  For some reason I didn't think to look in the geometry server api.  Thanks for the response.
0 Kudos