how are infoWindow format 'per attribute' function parameters passed?

2663
0
07-21-2015 03:39 PM
DavidDoop
New Contributor II

In the 'Format InfoWindow Content' examples there is a line that substitutes attribute values using a function.  In line 3 it the compare function is called on the POP2007 attribute - ${POP2007:compare}.  The compare function takes 3 arguments: value, key, and data.  How are these argument passed to the function?

Here is the code:

var infoTemplate = new InfoTemplate();
infoTemplate
.setTitle("Population in ${NAME}");
infoTemplate
.setContent("<b>2007 :D: </b>${POP2007:compare}<br/>" +
 
"<b>2007 density: </b>${POP07_SQMI:compare}<br/><br/>" +
 
"<b>2000: </b>${POP2000:NumberFormat}<br/>" +
 
"<b>2000 density: </b>${POP00_SQMI:NumberFormat}");

compare
= function (value, key, data) {
 
var result = "", diff, pctChange;

 
switch (key) {
   
case "POP2007":
      result
= value > data.POP2000 ? "images/up.png" : "images/down.png";
      diff
= data.POP2007 - data.POP2000;
      pctChange
= (diff * 100) / data.POP2000;
     
break;

   
case "POP07_SQMI":
      result
= value > data.POP00_SQMI ? "images/up.png" : "images/down.png";
      diff
= data.POP07_SQMI - data.POP00_SQMI;
      pctChange
= (diff * 100) / data.POP00_SQMI;
     
break;
 
}

 
return number.format(value) +
   
"   <img src='" + result + "'>" +
   
"  <span style='color: " +
   
(pctChange < 0 ? "red" : "green") + ";'>"
    
+ number.format(pctChange, { places: 3 }) +
   
"%</span>";
};

thanks

Tags (2)
0 Kudos
0 Replies