Select to view content in your preferred language

UniqueValueRenderer supports only one field rather than 3 fields as suggested by API

3363
1
10-02-2013 09:39 AM
dw2
by
Deactivated User
There is a way to publish shapefile to local server on the fly, as illustrated in the Runtime sample app com.esri.client.samples.datasources.LocalShapefileApp.  During that process, we can also introduce a renderer.  In the sample app, a pre-defined simple renderer is used.  Rather than doing that, a custom UniqueValueRenderer is defined.  It works well if only one field is used for classification.  From looking at the Runtime API and other ArcGIS SDK's, it appears multiple fields can be used.  However, it appears not to work when 2 or more fields are used.  The code that works:

        UniqueValueRenderer uvRenderer = new UniqueValueRenderer();
        uvRenderer.setAttributeName1("field1");

        Object[] o;
        uvRenderer.addValue(new UniqueValueInfo(new Object[]{11}, getFillSymbol()));

The code that does not work:

        UniqueValueRenderer uvRenderer = new UniqueValueRenderer();
        uvRenderer.setAttributeName1("field1");
        uvRenderer.setAttributeName2("filed2");
        Object[] o;
        o = new Object[]{11,22};
        uvRenderer.addValue(new UniqueValueInfo(o, getFillSymbol()));

The Runtime used is 10.1.  Don't know if it gets fixed in 10.2

Thanks.
0 Kudos
1 Reply
ColinAnderson1
Esri Contributor
Unfortunately this is a bug in the unique value renderer when you create it programatically. If the render is read from JSON i.e. from a service then multiple fields will work.

When creating one in code a work around is to turn the unique values into JSON and then read back into a unique value e.g.

 
        import org.codehaus.jackson.JsonNode;
        import org.codehaus.jackson.map.ObjectMapper;

 private UniqueValueInfo getUniqueValueInfo(Object[] values, Symbol symbol) throws Exception {        
  UniqueValueInfo uv = new UniqueValueInfo(values, symbol);

  ObjectMapper mapper = new ObjectMapper();
  JsonNode node = mapper.readTree(uv.toJson(","));

  return new UniqueValueInfo(node);
 }


So create your renderer like this

UniqueValueRenderer uvr = new UniqueValueRenderer(null, "TYPE", "SEVERITY", "ATTACHMENTTYPE");
  
uvr.addValue(getUniqueValueInfo(new Object[] {0, 1, 0}, getPMS("resources/traffic_cone.png", 20)));
uvr.addValue(getUniqueValueInfo(new Object[] {0, 2, 0}, getPMS("resources/traffic_cone.png", 30)));
uvr.addValue(getUniqueValueInfo(new Object[] {0, 3, 0}, getPMS("resources/traffic_cone.png", 40)));


This should hopefully resolve your problem.
0 Kudos