Select to view content in your preferred language

UniqueValueRenderer - multiple attribute rendering?

7609
11
03-12-2012 12:16 PM
evanpicard
Emerging Contributor
This -

esri.renderer.UniqueValueRenderer(defaultSymbol, attributeField, attributeField2?, attributeField3?, fieldDelimeter?)

Creates a new UniqueValueRenderer object. Typically features are rendered based on the unique values of one attribute field. However up to three fields can be combined to generate a unique value. For example, if two fields are used which store the values A and B; and X, Y, and Z respectively, then the unique values for the renderer can be A:X, A:Y, A:Z, B:X, B:Y and B:Z, assuming ":" is the field delimiter.


would lead me to believe that this -

var salesRepsRend = new esri.renderer.UniqueValueRenderer (new esri.symbol.SimpleMarkerSymbol(esri.symbol.SimpleMarkerSymbol.STYLE_CROSS, 10, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([255,0,0]), 1), new dojo.Color([0,255,0,0.25])),"PCText", "Ldr_type", "Name" ":");


salesRepsRend.addValue("0:0", new esri.symbol.SimpleMarkerSymbol(esri.symbol.SimpleMarkerSymbol.STYLE_SQUARE, 10, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([255,0,0]), 1), new dojo.Color([0,255,255,0.25])));
salesRepsRend.addValue("1:0", new esri.symbol.SimpleMarkerSymbol(esri.symbol.SimpleMarkerSymbol.STYLE_X, 10, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([255,0,0]), 1), new dojo.Color([0,255,255,0.25])));
salesRepsRend.addValue("0:1", new esri.symbol.SimpleMarkerSymbol(esri.symbol.SimpleMarkerSymbol.STYLE_CIRCLE, 10, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([255,0,0]), 1), new dojo.Color([0,255,255,0.25])));





should work.  which is not the case.

I'm really only interested in rendering based on 2 fields, PCText and Ldr_type, but I get "esri.layers.FeatureLayer: unable to find ':' field in the layer 'fields' information [url: " if i don't fill in the third attribute.

so my problem is that it doesnt render uniquely, everything renders with the default renderer. 

Any ideas?

Thanks,
Evan
0 Kudos
11 Replies
JianHuang
Deactivated User
Evan,

Could you please post a repro sample here?
Thanks.
0 Kudos
evanpicard
Emerging Contributor
Evan,

Could you please post a repro sample here?
Thanks.


What does that mean?
0 Kudos
StephenLead
Honored Contributor
What does that mean?


Can you post a more complete code sample, which allows the problem to be reproduced - perhaps by modifying one of the sample ESRI scripts, or posting a link to your application online
0 Kudos
evanpicard
Emerging Contributor
Can you post a more complete code sample, which allows the problem to be reproduced - perhaps by modifying one of the sample ESRI scripts, or posting a link to your application online





Sorry, sure, here goes. app is behind a firewall, so i cant share it.
I had to delete a lot of code (other layers, search functions, etc- the forum limits to 10k char, i had almost 40k!)

******
The problem is it displays the defaultSRRSymbol "X" for all the points.  if i do a single attribute, it works fine.  If I only have 2 attributes, I get an error, it thinks the delimiter is an attribute.
I have about 50 different combinations of 2 attributes.  I took most of the .addvalue lines out, no need for the same line of code 50 more times, right?
If there is some better way to do it I'm fine with that too.




Thanks for taking a look.
(If you happened to see any other "what the hell is he doing here?!" type things, I wouldn't mind hearing about them either....)


Thanks,
Evan






<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">

<html>
    <head>
        <meta name="generator" content="HTML Tidy, see www.w3.org">
        <meta http-equiv="Content-Type" content=
        "text/html; charset=utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=7, IE=9">
        <!--The viewport meta tag is used to improve the presentation and behavior of the samples 
              on iOS devices-->
        <meta name="viewport" content=
        "initial-scale=1, maximum-scale=1,user-scalable=no">

        <title>Avon Sales Data</title>
        <link rel="stylesheet" type="text/css" href="resources/css/claro.css">
        <link rel="stylesheet" type="text/css" href="resources/css/slidedownmenuCSS.css">
        <link rel="stylesheet" type="text/css" href="resources/css/dimming.css">
        <link rel="stylesheet" type="text/css" href="http://serverapi.arcgisonline.com/jsapi/arcgis/2.6/js/esri/dijit/css/Popup.css">
      
      <style type="text/css">
 
      html, body
      {
        height: 100%;
        margin: 0px;
        padding: 0px;
        width: 100%;
      }
      .esriSimpleSlider
       div
      {
        height: 30px !important;
        width: 30px !important;
      }
    
</style>
  <script type="text/javascript" src="http://agsserver/arcgis_js_api/library/2.6/arcgis_compact/">
  </script>
  <script type="text/javascript" src="resources/jsfiles/slideinmenu.js?v=0.1b1">
  </script>
  <script type="text/javascript" src="resources/jsfiles/dimmingdiv.js">
  </script>
<script type="text/javascript">

      dojo.require("esri.map");
            
      dojo.require("dijit.form.Button");
      dojo.require("dijit.dijit");
      dojo.require("esri.layers.FeatureLayer");
      dojo.require("esri.dijit.Popup");
      dojo.require("esri.tasks.query");
      dojo.require("dojo.data.ItemFileReadStore");
      dojo.require("esri.tasks.find");
      
      
      var map, startExtent;
      var districtLayer, divisionLayer, streetMapLayer, regionsLayer, areasLayer, zipsLayer, salesRepsLayer;
      var myList;
      var findDistrict, findDivision, findParams;
      var searchQualVal, searchVal;
      var grid, store;

      var menu, menuSearch; //SLIDEINMENU    

      function init() {
        //setup the popup window 
        var popup = new esri.dijit.Popup({
          fillSymbol: new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([255,0,0]), 2), new dojo.Color([255,255,0,0.25]))
        }, dojo.create("div"));        

        //Create map and add the ArcGIS Online imagery layer

        startExtent = new esri.geometry.Extent({"xmin":-17497000,"ymin":2165000,"xmax":-4132000,"ymax":6969000,"spatialReference":{"wkid":102100}});

        map = new esri.Map("map", { 
          logo: false,
          extent: startExtent,
          infoWindow:popup
        });

        var streetMapLayer = new esri.layers.ArcGISTiledMapServiceLayer("http://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer");
        map.addLayer(streetMapLayer);


        dojo.connect(map, 'onLoad', function(evt) {
          
           
           var salesRepcontent = "<b>Name<\/b>: ${Name} <br/><b>Address<\/b>: ${ADDR1}<br/><b>City:</b> ${CITY}<br/><b>State<\/b>:$(ST_ABBR)<br/><b>YTD Netsales:<\/b>$(YTD_NetSales)<br/> <b>Sales201112<\/b>:$(Sales20112)<br/>";
           var salesRepTemplate = new esri.InfoTemplate("Sales Rep Data", salesRepcontent);
           map.infoWindow.resize(215,175);
           
        var salesRepsLayer = new esri.layers.FeatureLayer("http://agsserver/ArcGIS/rest/services/IndivTerritoriesOnly/SalesReps_simple/FeatureServer/0", {
            opacity:.65,
            mode: esri.layers.FeatureLayer.MODE_ONDEMAND,
            outFields:["NAME", "ADDR1", "CITY", "ST_ABBR", "YTD_Netsales", "Sales_201112", "Sales_201113", "PCText", "Ldr_type"],
            infoTemplate:salesRepTemplate
            }); 

           var defaultSRRSymbol = new esri.symbol.SimpleMarkerSymbol(esri.symbol.SimpleMarkerSymbol.STYLE_X, 10,
               new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID,
               new dojo.Color([255,0,0]), 1),
               new dojo.Color([0,255,0,0.25]));
                                              
           var salesRepsRend = new esri.renderer.UniqueValueRenderer (defaultSRRSymbol,"PCText", "Ldr_type", "Name", ":");
 

           salesRepsRend.addValue("0:0", new esri.symbol.SimpleMarkerSymbol(esri.symbol.SimpleMarkerSymbol.STYLE_DIAMOND, 10, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([255,85,0]), 1), new dojo.Color([255,85,0,1])));
           salesRepsRend.addValue("0:2", new esri.symbol.SimpleMarkerSymbol(esri.symbol.SimpleMarkerSymbol.STYLE_X, 10, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([255,85,0]), 1), new dojo.Color([255,85,0,1])));
           salesRepsRend.addValue("0:3", new esri.symbol.SimpleMarkerSymbol(esri.symbol.SimpleMarkerSymbol.STYLE_X, 10, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([255,85,0]), 1), new dojo.Color([255,85,0,1])));
           salesRepsRend.addValue("0:4", new esri.symbol.SimpleMarkerSymbol(esri.symbol.SimpleMarkerSymbol.STYLE_X, 10, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([255,85,0]), 1), new dojo.Color([255,85,0,1])));
           salesRepsRend.addValue("0:5", new esri.symbol.SimpleMarkerSymbol(esri.symbol.SimpleMarkerSymbol.STYLE_X, 10, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_

          salesRepsLayer.setRenderer(salesRepsRend);
          salesRepsLayer.setSelectionSymbol(new esri.symbol.SimpleMarkerSymbol().setColor(new dojo.Color([245,0,0,.60])));*

 
            dojo.connect(salesRepsLayer, 'onClick', function(evt){
            salesRepQueryFunction(evt, salesRepsLayer)});
            map.addLayer(salesRepsLayer);    

     
        });    //end of OnLoad...    

       };   //end of init

        function loaded() {
            document.addEventListener('touchmove', function(e){ e.preventDefault(); e.stopPropagation(); });
            menu = new slideInMenu('slidedownmenu', false);
            menuSearch = new slideInMenu('slidedownmenuSearch', false);
        }; //SLIDEINMENUS
        
        document.addEventListener('DOMContentLoaded', loaded);



   
      
        
         //Create data store and bind to grid.

        store = new dojo.data.ItemFileReadStore({ data:data });
        var grid = dijit.byId('grid');
        grid.setStore(store);
        //Zoom back to the initial map extent
        map.setExtent(startExtent);
      };

        
      dojo.addOnLoad(init);      
</script>
<style type="text/css" media="all">

</style>
    </head>

    <body class="slidedownmenuCSS">
 
        <div id="spacer" style="height:25px">
        </div>
        <!--slidedown menu is 25 pixels? -->

        <div id="map" style="width:100%; height:100%;">
        </div>
        <!--   <div id="content">
             </div>
        -->
        <!--  the following hidden div will be used by the script -->

   

 
    </body>
</html>





0 Kudos
evanpicard
Emerging Contributor
Any insight/suggestions for me?
I'm really stuck.
0 Kudos
evanpicard
Emerging Contributor
Yippee!
I just solved my own question.
Even if you're only using *TWO* attributes, you need to have a blank third attribute.
var salesRepsRend = new esri.renderer.UniqueValueRenderer (defaultSRRSymbol,"PCText", "Ldr_type", "", ":");
 
salesRepsRend.addValue("0:0", new esri.symbol.SimpleMarkerSymbol(esri.symbol.SimpleMarkerSymbol.STYLE_DIAMOND, 10, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([255,85,0]), 1), new dojo.Color([255,85,0,1])));

0 Kudos
NianweiLiu
Frequent Contributor
if i don't fill in the third attribute.

You should put "null' in the third attribute, not shuffle positions and put 4th parameter into the position of 3rd.  You are telling the code to find a field name that is your delimiter.
0 Kudos
shwetasharma
New Contributor
i am trying to do the same thing but nthng is working out..even i have tried the way you have suggested in the end..in my case the datatype of one field is string and other's is integer..
Please help me...
0 Kudos
evanpicard
Emerging Contributor
Can you post a sample of your code for us to see?
0 Kudos