Hi All,
Thank you for your time in advance. I am wondering if anyone could provide valuable opinions how to display the text from a Double field in the info window (code listed below). I found some records have the zero value in the Double field ${WellDepth}. I want to see if anyone could provide a function to replace the 0 to display "Unknown Value" and keep the same value if the ${WellDepth} is greater than 0.
Many thanks,
Hank
var content_magnesium_depthLocation = "<b>PointID</b>: ${POINT_ID}" + "<br><b>Date Collection</b>: ${Collection}" + "<br><b>Magnesium Value</b>: ${Mg_Symbol}${Mg}(mg/L)" + "<br><b>Well Depth</b>: ${WellDepth}(ft)" + "<br><b>Data Source</b>: ${DataSource}" + "<br><b>Data Source Information</b>: ${DataSour_1}" + "<br><b >More Information</b>:<a target='_blank' href='https://community.esri.com/maps/data/Water/${POINT_ID}/Mg' >Magnesium Info</a>";
Chang-Heng,
This is exactly one of the reasons why the InfoTemplates set setContent method can take a string or a function. Use a function to look at the features attribute value for WellDepth and if it is 0 then add text to the content string that is returned instead of the numeric value.
Hi Robert,
Thank you for the reply. I am wondering if you could provide more details on the function for this question.
Thanks,
Chang-Heng
Chang-Heng,
Here is an example function:
function setContent(value) { var formatString = "<b>Property Name: </b> + value.attributes.PropertyName +"<br/>" var sqft = geometryEngine.geodesicArea(value.geometry, "square-feet"); var squarefeet = number.format(sqft, { places: 1 }); var acres = number.format(sqft / 43560, { places: 0 }); formatString += "Acres: " + acres; return formatString; }