我有以下代码:
var map;
function init()
{
map = new esri.Map("mapDiv");
var basemap: new esri.layer.arcGISTiledMapServiceLayer("link");
map.addLayer(basemap);
var content = "Hello!";
var infoTemplate = new esri.InfoTemplate();
infoTemplate.setTitle("<b>${BUILDING_NO}</b>);
infoTemplate.setTitle(content);
var featureLayer = new esri.layers.FeatureLayer("link",
mode:esri.layers.FeatureLayer.MODE_ONDEMAND,
outFields:["*"],
infoTemplate:infoTemplate
});
map.addLayer(featureLayer);
}
我尝试做的是根据其中一个字段的值更改infoTemplate内容。关于如何实现这一目标的任何想法?
答案 0 :(得分:1)
您可以使用函数setContent,例如:
infoTemplate.setContent(getContent);
function getContent(graphic) {
var templateContent = '';
if (graphic.attributes.AssetTypeID === 1) {
templateContent += 'UpperLimit : ' + graphic.attributes.UpperLimit;
}
else if (graphic.attributes.AssetTypeID === 2) {
templateContent += 'Intersection1 : ' + graphic.attributes.Intersection1;
}
return templateContent;
}