I am trying to have one infowindow/popup show from multiple services. I have successfully added the second service to my code, however, only 1 result will display.
Ex. if I am at full scale, only the zoning layer is returned in the popup. If I zoom in, only the parcel layer is returned in the popup.
How can I get both services to show within the popup? Additionally, how can I make it so only the visible layers show within the popup?
Here is the code I have edited:
dojo.require("esri.dijit.Popup"); //Infowindow
var identifyTask,identifyParams;
function mapReady(map){
dojo.connect(map,"onClick",executeIdentifyTask);
//create identify tasks and setup parameters
identifyTaskZoning = new esri.tasks.IdentifyTask("https://www.marioncountyfl.org/arcgis/rest/services/Dynamic/Zoning/MapServer");
identifyTaskParcels = new esri.tasks.IdentifyTask("https://www.marioncountyfl.org/arcgis/rest/services/Dynamic/Parcels/MapServer");
//Set Zoning Parameters
identifyParamsZoning = new esri.tasks.IdentifyParameters();
identifyParamsZoning.tolerance = 7;
identifyParamsZoning.returnGeometry = true;
identifyParamsZoning.layerIds = [0,1,2,3,4];
identifyParamsZoning.layerOption = esri.tasks.IdentifyParameters.LAYER_OPTION_VISIBLE;
identifyParamsZoning.width = map.width;
identifyParamsZoning.height = map.height;
//Set Parcel Parameters
identifyParamsParcels = new esri.tasks.IdentifyParameters();
identifyParamsParcels.tolerance = 15;
identifyParamsParcels.returnGeometry = true;
identifyParamsParcels.layerIds = [0,1,2,3,4];
identifyParamsParcels.layerOption = esri.tasks.IdentifyParameters.LAYER_OPTION_VISIBLE;
identifyParamsParcels.width = map.width;
identifyParamsParcels.height = map.height;
//resize the map when the browser resizes
dojo.connect(dijit.byId('map'), 'resize', map,map.resize);
};
function executeIdentifyTask(evt){
identifyParamsParcels.geometry = evt.mapPoint;
identifyParamsParcels.mapExtent = map.extent;
var deferred = identifyTaskParcels.execute(identifyParamsParcels);
deferred.addCallback(function(response){
if (response.length > 0) {
// console.log(response.length)
// 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 === 'TaxParcel'){
console.log(feature.attributes.NAME);
var template = new esri.dijit.PopupTemplate({
title:"Parcels",
description:"<b>Parcel ID:</b> {Parcel Identification Number} <br/> <b>Address:</b> {Site Address}"
});
feature.setInfoTemplate(template);
}
return feature;
});
}
else {
identifyParamsZoning.geometry = evt.mapPoint;
identifyParamsZoning.mapExtent = map.extent;
var deferred = identifyTaskZoning.execute(identifyParamsZoning);
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 === 'Zoning Classifications'){
console.log(feature.attributes.NAME);
var template = new esri.dijit.PopupTemplate({
title:"Zoning",
description:"<b>Zoning:</b> {Zoning Classification} <br/> <b>Description:</b> {Zoning Description}"
});
feature.setInfoTemplate(template);
}
else if (result.layerName === 'Assisted Living Facilities'){
var template = new esri.dijit.PopupTemplate({
title:"Assisted Living Facilities",
description:"<b>Parcel ID:</b> {Parcel} <br/> <b>Applicant:</b> {BusinessApplicantName} <br/> <b>No. of Residents</b> {NbrResidents}"
});
feature.setInfoTemplate(template);
}
else if (result.layerName === 'Family Divisions'){
var template = new esri.dijit.PopupTemplate({
title:"Family Divisions",
description:"<b>Parcel ID:</b> {Parcel} <br/> <b>Project Number:</b> {project_nbr} </br> <b>Status:</b> {Status}"
});
feature.setInfoTemplate(template);
}
else if (result.layerName === 'Policy 120'){
var template = new esri.dijit.PopupTemplate({
title:"Policy 120",
description:"<b>Parcel ID:</b> {Parcel} <br/> <b>Business Name:</b> {BusinessName} </br> <b>Date of Letter:</b> {DateOfLetter}"
});
feature.setInfoTemplate(template);
}
else if (result.layerName === 'Zoning Changes'){
var template = new esri.dijit.PopupTemplate({
title:"Zoning Changes",
description:"<b>Parcel ID:</b> {Parcel} <br/> <b>Request Number:</b> {REQUEST_NBR} </br> <b>Property Owner:</b> {PROPERTY_OWNER}"
});
feature.setInfoTemplate(template);
}
return feature;
});
});
};
map.infoWindow.setFeatures([deferred]);
map.infoWindow.show(evt.mapPoint);
});
map.infoWindow.setFeatures([deferred]);
map.infoWindow.show(evt.mapPoint);
};