So I have an application where I only want the popup to open when identifying 1 visible layer.How do I have the popup close or not even display if the results are NULL or return "No information Available"?Here's some of my code.Thanks...function mapReady(map){
dojo.connect(map,'onClick',executeIdentifyTask);
//create identify tasks and setup parameters
identifyTask = new esri.tasks.IdentifyTask("http://gis.dvrpc.org/ArcGIS/rest/services/Ci2_raster/MapServer");
identifyParams = new esri.tasks.IdentifyParameters();
identifyParams.tolerance = 3;
identifyParams.returnGeometry = true;
// identifyParams.layerIds = [6];
identifyParams.layerIds = cii.visibleLayers;
identifyParams.layerOption = esri.tasks.IdentifyParameters.LAYER_OPTION_VISIBLE;
identifyParams.width = map.width;
identifyParams.height = map.height;
}
function updateDynLayerVisibility() {
var inputs = dojo.query(".dyn_item");
visible = [];
for (var i = 0, il = inputs.length; i < il; i++) {
if (inputs.checked) {
visible.push(inputs.id);
}
}
// If no layers are visible set the array value to = -1
// and disconnect the identify task
if (visible.length === 0) {
visible = [-1];
map.infoWindow.hide();
}
// Update Identifys layers
identifyParams.layerIds = visible;
// Update layer visiblity
cii.setVisibleLayers(visible);
}
function executeIdentifyTask(evt) {
// custom code to only identify visible layers
// start
if (visible.length === 1 && visible[0] == -1){
map.infoWindow.clearFeatures();
map.infoWindow.show(evt.mapPoint);
} else {
identifyParams.geometry = evt.mapPoint;
identifyParams.mapExtent = map.extent;
//end
var deferred = identifyTask.execute(identifyParams);
deferred.addCallback(function(response) {
// response is an array of identify result objects
// Let's return an array of features.
return dojo.map(response, function(result) {
var feature = result.feature;
feature.attributes.layerName = result.layerName;
if (result.layerName === 'CIIndex'){
var template = new esri.dijit.PopupTemplate();
var attr = feature.attributes;
content = "<B>Community Investment Index:</B><br>"
+"<FONT color=red><B>${Pixel value:Numberformat(value:0)}</B></FONT><br>";
template.setContent(content);
// template.setContent("${*}");
feature.setInfoTemplate(template);
}
return feature;
});
});
map.infoWindow.setFeatures([ deferred ]);
map.infoWindow.show(evt.mapPoint);
}
// add for Visible code
}