Solved! Go to Solution.
// Function to format info window content based on feature attributes
function featureContent(feature) {
var type = feature.attributes["TYPE"];
var notes = feature.attributes["NOTES"];
var baseContent = "<strong>Type:</strong> " + type;
if (notes) { baseContent += "<br/><strong>Info:</strong> <span class='data'>" + notes + "</span>"; }
return baseContent;
}
var idTask = new IdentifyTask(mapUrl);
var idParams = new IdentifyParams();
idParams.returnGeometry = true;
idParams.layerIds = [56, 59];
idParams.layerOption = IdentifyParams.LAYER_OPTION_TOP;
idParams.tolerance = 5;
function infoTask(evt) {
idParams.geometry = evt.mapPoint;
idParams.width = map.width;
idParams.height = map.height;
idParams.mapExtent = map.extent;
idTask.execute(idParams, function (idResults) {
if (idResults[0]) {
array.forEach(idResults, function (result) {
var selFeature = result.feature;
map.infoWindow.setTitle(result.layerName);
var content = featureContent(selFeature);
map.infoWindow.setContent(content);
map.infoWindow.show(evt.mapPoint);
});
}
}, null);
}
on(map, "click", infoTask);
function getData(evt){
try {
require(["esri/InfoTemplate"], function(InfoTemplate){
var graphic = evt.graphic;
var countryName = evt.graphic.attributes.CNTRY_NAME;
var template=new InfoTemplate();
console.log(" got countryName" + countryName);
var alertDetailUrl = getAlertDetailsUrl(countryName);
console.log(" alertDetailUrl " + alertDetailUrl);
dojo.xhrGet({
url: alertDetailUrl,
handleAs: 'json',
load: function(data){
console.log("data ");
var popUpData = getPopUpContent(data);
template.setTitle(countryName);
template.setContent(popUpData);
graphic.setInfoTemplate(template);
map.graphics.add(graphic);
graphic.show();
console.log(" complete ");
},
error: dojo.hitch(this, "failure")
});
});
}
catch (e) {
console.log("error occured " + e);
}
}
on(featureLayerInstance, "click", function (evt) {
var graphic = evt.graphic;
var countryName = evt.graphic.attributes.CNTRY_NAME;
var template=new InfoTemplate();
console.log(" got countryName" + countryName);
var alertDetailUrl = getAlertDetailsUrl(countryName);
console.log(" alertDetailUrl " + alertDetailUrl);
dojo.xhrGet({
url: alertDetailUrl,
handleAs: 'json',
load: function(data){
console.log("data ");
var popUpData = getPopUpContent(data);
template.setTitle(countryName);
template.setContent(popUpData);
graphic.setInfoTemplate(template);
//You don't needto add the graphic to the map unless you want to give it a new selection symbol.
//map.graphics.add(graphic);
//graphic.show();
console.log(" complete ");
},
error: dojo.hitch(this, "failure")
});
});
on(featureLayerInstance, "click", function (evt) {
var graphic = evt.graphic;
var countryName = evt.graphic.attributes.CNTRY_NAME;
console.log(" got countryName" + countryName);
var alertDetailUrl = getAlertDetailsUrl(countryName);
console.log(" alertDetailUrl " + alertDetailUrl);
dojo.xhrGet({
url: alertDetailUrl,
handleAs: 'json',
load: function(data){
console.log("data ");
var popUpData = getPopUpContent(data);
map.infoWindow.setTitle(countryName);
map.infoWindow.setContent(popUpData);
map.infoWindow.show(evt.mapPoint);
console.log(" complete ");
},
error: dojo.hitch(this, "failure")
});
});