Select to view content in your preferred language

converting symbolfunciton from 1.3 to renderer in 2.0

1149
7
10-04-2010 10:22 AM
abukhan
Occasional Contributor
I had a  symbolfunction that looked like this:

  private function getTrackSymbol(graphic:Graphic):Symbol
         {      
              var symbol:Symbol = nodatasymbol;
              var minpall:Number;
             if (mapvariables.strshowAALayer==MapInitialData.strMinorityField )
                 {
                     if (minoritysetting.boolminoritypercentdefault)
                          minpall = graphic.attributes.MIN_P_ALL;
                         else
                         {
                          if (minoritysetting.strminoritypercentfields.length > 0)
                          {
                          
                           var tmnumber:Number = 0;
                           if (minoritysetting.strminoritypercentfields.indexOf("t_pop_black_african_amer") > -1)
                            tmnumber += Number(graphic.attributes.t_pop_black_african_amer);
                           if (minoritysetting.strminoritypercentfields.indexOf("t_pop_asian") > -1)
                            tmnumber += Number(graphic.attributes.t_pop_asian);
                           if (minoritysetting.strminoritypercentfields.indexOf("t_pop_hisp") > -1)
                            tmnumber += Number(graphic.attributes.t_pop_hisp);
                            if (minoritysetting.strminoritypercentfields.indexOf("t_pop_haw_PI") > -1)
                            tmnumber += Number(graphic.attributes.t_pop_haw_PI);
                        
                           minpall = (graphic.attributes.persons_pop==0)?0:(tmnumber*100/graphic.attributes.persons_pop);
                          }
                          else
                             minpall = 0;
                         
                         }
                     }
             else  if (mapvariables.strshowAALayer==MapInitialData.strIncomeField)
                      minpall = graphic.attributes.INC_P_ALL;
          
               // show on map
               if (minpall >=0 )
                {
                          if (minpall < commonaasetting.numaabreak1toplimit)//20
                         {
                          symbol =  gsymbol1;//trackinsymbol[0];
                        }
                      else if (minpall >=  commonaasetting.numaabreak1toplimit && minpall < commonaasetting.numaabreak2toplimit)
                        {
                         symbol = gsymbol2;//trackinsymbol[1];
                         }
                        else if (minpall >= commonaasetting.numaabreak2toplimit && minpall < commonaasetting.numaabreak3toplimit)
                      {
                           symbol = gsymbol3;//trackinsymbol[2];
                       }
                        else if (minpall >= commonaasetting.numaabreak3toplimit && minpall < commonaasetting.numaabreak4toplimit)
                        {
                         symbol = gsymbol4;//trackinsymbol[3];
                        }
                        else if (minpall >= commonaasetting.numaabreak4toplimit && minpall < commonaasetting.numaabreak5toplimit)
                         {
                          symbol = gsymbol5;//trackinsymbol[3];
                       }
                          else if (minpall >= commonaasetting.numaabreak5toplimit )
                       {
                        symbol = gsymbol6;//trackinsymbol[3];
                       }
              }
   
          return symbol;             
        }


The issue is here:

in symbolfunction I could get a value say: minpall = graphic.attributes.MIN_P_ALL;
and based on user selection I could compute a  value and then compare  the value with the limits to give symbols.

But in classbreak renderer in api 2, I can only mention
classValuerenderer.attribute = "MIN_P_ALL";
and compare that attribute value to the limits..

Is there a way to do a computed value comparison with the limits in api 2 (similar to symbol function in 1.3)?
Tags (2)
0 Kudos
7 Replies
DasaPaddock
Esri Regular Contributor
One option could be to create a new custom Renderer class by extending Renderer and overriding the getSymbol() function.

Reference:
http://help.arcgis.com/en/webapi/flex/apiref/com/esri/ags/renderers/Renderer.html
0 Kudos
abukhan
Occasional Contributor
I converted symbol function as follows:
package Components
{
import com.esri.ags.Graphic;
import com.esri.ags.renderers.Renderer;
import com.esri.ags.symbols.Symbol;

public class MinorityRenderer extends Renderer
{
  public var symbol1:Symbol;
  public var symbol2:Symbol;
  public var symbol3:Symbol;
  public var symbol4:Symbol;
  public var symbol5:Symbol;
  public var symbol6:Symbol;
  public var othersymbol:symbol;
  public var booldefault:Boolean;
  public var strminoritypercentfields:String;
  public var numaabreak1toplimit:Number;
  public var numaabreak2toplimit:Number;
  public var numaabreak3toplimit:Number;
  public var numaabreak4toplimit:Number;
  public var numaabreak5toplimit:Number;
 
  private var minpall:Number;
  private var tmnumber:Number=0;
  public function MinorityIncomeRenderer()
  {
   super();
  }
  override public function getSymbol(graphic:Graphic):Symbol
  {
   if (booldefault)
    minpall = graphic.attributes.MIN_P_ALL;
   else
   {  if (stringselected.length > 0)
     {
      if (strminoritypercentfields.indexOf("t_pop_black_african_amer") > -1)
       tmnumber += Number(graphic.attributes.t_pop_black_african_amer);
      if (strminoritypercentfields.indexOf("t_pop_asian") > -1)
       tmnumber += Number(graphic.attributes.t_pop_asian);
      if (strminoritypercentfields.indexOf("t_pop_hisp") > -1)
       tmnumber += Number(graphic.attributes.t_pop_hisp);
      if (strminoritypercentfields.indexOf("t_pop_haw_PI") > -1)
       tmnumber += Number(graphic.attributes.t_pop_haw_PI);
      minpall = (graphic.attributes.persons_pop==0)?0:(tmnumber*100/graphic.attributes.persons_pop);
     
     }
     else 
       minpall = 0;
    }
   if (minpall >=0)
   {
     if (minpall < numaabreak1toplimit)//20
       return symbol1;
     else if (minpall >=  numaabreak1toplimit && minpall < numaabreak2toplimit)
      return symbol2;
     else if (minpall >= numaabreak2toplimit && minpall < numaabreak3toplimit)
      return symbol3;
     else if (minpall >= numaabreak3toplimit && minpall < numaabreak4toplimit)
      return symbol4;
     else if (minpall >= numaabreak4toplimit && minpall < numaabreak5toplimit)
      return symbol5;
     else if (minpall >= numaabreak5toplimit )
      return symbol6;
    
   }
   else
    return othersymbol;
  
  }
}
}

But for implementing I am having issue with getsymbol function with input parameter????

How I am get graphic for the getSymbol function input parameter??????

private function getaarenderer():Renderer
   {
   
    var minorityrenderer:MinorityRenderer = new MinorityRenderer();
    minorityrenderer.booldefault = minoritysetting.boolminoritypercentdefault;
    minorityrenderer.strminoritypercentfields = minoritysetting.strminoritypercentfields;
    minorityrenderer.numaabreak1toplimit = commonaasetting.numaabreak1toplimit;
    minorityrenderer.numaabreak2toplimit = commonaasetting.numaabreak2toplimit;
    minorityrenderer.numaabreak3toplimit = commonaasetting.numaabreak3toplimit;
    minorityrenderer.numaabreak4toplimit = commonaasetting.numaabreak4toplimit;
    minorityrenderer.numaabreak5toplimit = commonaasetting.numaabreak5toplimit;
    minorityrenderer.symbol1 = gsymbol1;
    minorityrenderer.symbol2 = gsymbol2;
    minorityrenderer.symbol3 = gsymbol3;
    minorityrenderer.symbol4 = gsymbol4;
    minorityrenderer.symbol5 = gsymbol5;
    minorityrenderer.symbol6 = gsymbol5;


    minorityrenderer.getSymbol(?????);
}
0 Kudos
abukhan
Occasional Contributor
Desa:

Do you have any example of using custom renderer?

Both the class and implementation...

Thanks..
0 Kudos
DasaPaddock
Esri Regular Contributor
Here's an example:
http://forums.arcgis.com/threads/1631-Beta-10-GraphicsLayer-Symbol-by-GeometryType

You don't need to call getSymbol() directly. It's called by the GraphicsLayer just like the symbolFunction used to be called. You just need to set the GraphicsLayer's renderer property.
0 Kudos
MelonyBarrett
Occasional Contributor
Dasa,

I don't understand how you set the GraphicsLayer's renderer property in the mxml.  How do you do this?  I get an error when I do the following, but this is exactly how I used to call my SymbolFunction.  The error states the following "Initializer for 'renderer': values of type com.esri.ags.renderers.Renderer cannot be represented in text."

<esri:GraphicsLayer id="queryGraphicsLayer"  graphicProvider="{joinQueryTask.executeLastResult.features}"  renderer="MyGeomTypeRenderer"/>


Please advise.  Thank you.
0 Kudos
DasaPaddock
Esri Regular Contributor
It needs an instance. See this sample:
http://help.arcgis.com/en/webapi/flex/samples/index.html?sample=Renderer

You could also put it in the Declarations and bind to it's id the way that sample is doing with the symbols.

You can also put the symbols inline like in this sample:
http://help.arcgis.com/en/webapi/flex/samples/index.html?sample=FeatureLayerWithTooltips
0 Kudos
MelonyBarrett
Occasional Contributor
Thank you thank you thank you!!!  That was the push I was looking for.  It's actually better than my former SymbolFunction, too!
0 Kudos