How to manage Symbols for best performance in GraphicsLayer ?

3079
0
06-17-2015 02:44 AM
JeremieJoalland
New Contributor II

What is the best choice in term of performance to draw lot's of graphics on a GraphicsLayer ?? (around 10 000 graphics in one GraphicsLayer, nearly 10 GraphicsLayer with thousands of graphics for some of them, some of them with redraw of thousands of graphics each second...) :

A. like my sample code, define a UniqueValueRenderer on a GraphicsLayer, based on attributes of my graphics (and in this case when I add my graphics can I pass "null" for the symbol ? Why there is no constructor of Graphic without Symbol ?)

or

B. for each graphic I pass the correct symbol (symbols are Constants for 1 Symbol = 1 instance) based on its attribute value (no renderer applied to the GraphicsLayer)

In my case, some GraphicsLayer have an unique symbol for all graphics... some other can have up to 10 different symbols depending on a attributes values.

Code sample :

  1. private void colorUniqueValueRenderingComplex() { 
  2.     final String ATTRIBUTE_NAME = "CAPITAL"
  3.  
  4.     if (graphicLayerCplx != null) { 
  5.         graphicLayerCplx.removeAll(); 
  6.  
  7.     } else { 
  8.         graphicLayerCplx = new GraphicsLayer(); 
  9.         map.getLayers().add(graphicLayerCplx); 
  10.  
  11.         final SimpleMarkerSymbol SYM_DEFAULT = new SimpleMarkerSymbol(Color.GRAY, 12, Style.TRIANGLE); 
  12.         final SimpleMarkerSymbol SYM_NON_CAPITAL = new SimpleMarkerSymbol(Color.GREEN, 9, Style.CIRCLE); 
  13.         final CompositeSymbol compositeMarkerSquare = new CompositeSymbol(); 
  14.         compositeMarkerSquare.getSymbols().add(new SimpleMarkerSymbol(Color.GREEN, 16, SimpleMarkerSymbol.Style.SQUARE)); 
  15.         compositeMarkerSquare.getSymbols().add(new SimpleMarkerSymbol(Color.YELLOW, 10, SimpleMarkerSymbol.Style.SQUARE)); 
  16.  
  17.         final UniqueValueRenderer uvRenderer = new UniqueValueRenderer(); 
  18.         uvRenderer.setAttributeName1(ATTRIBUTE_NAME); 
  19.         uvRenderer.addValue(new UniqueValueInfo(new Object[] { "Y" }, compositeMarkerSquare)); 
  20.         uvRenderer.addValue(new UniqueValueInfo(new Object[] { "N" }, SYM_NON_CAPITAL)); 
  21.         uvRenderer.setDefaultSymbol(SYM_DEFAULT); 
  22.  
  23.         graphicLayerCplx.setRenderer(uvRenderer); 
  24.     } 
  25.  
  26.     final Map<String, Object> attCapY = ImmutableMap.<String, Object> builder().put(ATTRIBUTE_NAME, "Y").build(); 
  27.     final Map<String, Object> attCapN = ImmutableMap.<String, Object> builder().put(ATTRIBUTE_NAME, "N").build(); 
  28.     final Map<String, Object> attCapZ = ImmutableMap.<String, Object> builder().put(ATTRIBUTE_NAME, "Z").build(); 
  29.  
  30.     graphicLayerCplx.addGraphic(new Graphic(new Point(4.00, 44.00), null, attCapN)); 
  31.     graphicLayerCplx.addGraphic(new Graphic(new Point(4.20, 44.30), null, attCapN)); 
  32.     graphicLayerCplx.addGraphic(new Graphic(new Point(4.40, 44.60), null, attCapY)); 
  33.     graphicLayerCplx.addGraphic(new Graphic(new Point(4.60, 44.90), null, attCapY)); 
  34.     graphicLayerCplx.addGraphic(new Graphic(new Point(4.80, 45.20), null, attCapY)); 
  35.     graphicLayerCplx.addGraphic(new Graphic(new Point(5.00, 45.50), null, attCapZ)); 
  36. }
0 Kudos
0 Replies