if (layerName === 'County_City_Py') { var CityCountyTemplate = new InfoTemplate("", "City: ${CITY_NAME} <br/> County: ${COUNTY} <br/> State: ${STATE_NAME}"); CityCountyTemplate.setTitle("Search Result") feature.setInfoTemplate(CityCountyTemplate); }
if (${CITY_NAME} != null) {
if ("${CITY_NAME"} != null) {
Solved! Go to Solution.
The InfoTemplate does give you the ability to execute a function that returns the template. You can view the documentation here, but using your code, you could try this:if (layerName === 'County_City_Py') { var CityCountyTemplate = new InfoTemplate(function (graphic) { var attr = graphic.attributes; var template = "City: "; template += (attr.CITY_NAME === null) ? 'n/a' : attr.CITY_NAME; template += '<br />County: ' + attr.COUNTY; template += '<br />State: ' + attr.STATE_NAME; return template; }); CityCountyTemplate.setTitle("Search Result") feature.setInfoTemplate(CityCountyTemplate); }
if (layerName === 'County_City_Py') { if (feature.attributes.CITY_NAME === "Null") { var CityCountyTemplate = new InfoTemplate("", "City: n/a <br/> County: ${COUNTY} <br/> State: ${STATE_NAME}"); CityCountyTemplate.setTitle("Search Result") feature.setInfoTemplate(CityCountyTemplate); } else { var CityCountyTemplate = new InfoTemplate("", "City: ${CITY_NAME} <br/> County: ${COUNTY} <br/> State: ${STATE_NAME}"); CityCountyTemplate.setTitle("Search Result") feature.setInfoTemplate(CityCountyTemplate); } }
if (layerName === 'County_City_Py') { var CityCountyTemplate = new InfoTemplate(function (graphic) { var attr = graphic.attributes; var template = "City: "; template += (attr.CITY_NAME === null) ? 'n/a' : attr.CITY_NAME; template += '<br />County: ' + attr.COUNTY; template += '<br />State: ' + attr.STATE_NAME; return template; }); CityCountyTemplate.setTitle("Search Result") feature.setInfoTemplate(CityCountyTemplate); }
The InfoTemplate does give you the ability to execute a function that returns the template. You can view the documentation here, but using your code, you could try this:if (layerName === 'County_City_Py') { var CityCountyTemplate = new InfoTemplate(function (graphic) { var attr = graphic.attributes; var template = "City: "; template += (attr.CITY_NAME === null) ? 'n/a' : attr.CITY_NAME; template += '<br />County: ' + attr.COUNTY; template += '<br />State: ' + attr.STATE_NAME; return template; }); CityCountyTemplate.setTitle("Search Result") feature.setInfoTemplate(CityCountyTemplate); }
if (layerName === 'County_City_Py') { if (feature.attributes.CITY_NAME === "Null") { var CityCountyTemplate = new InfoTemplate("", "City: n/a <br/> County: ${COUNTY} <br/> State: ${STATE_NAME}"); CityCountyTemplate.setTitle("Search Result") feature.setInfoTemplate(CityCountyTemplate); } else { var CityCountyTemplate = new InfoTemplate("", "City: ${CITY_NAME} <br/> County: ${COUNTY} <br/> State: ${STATE_NAME}"); CityCountyTemplate.setTitle("Search Result") feature.setInfoTemplate(CityCountyTemplate); } }