我想要的是,我想打开一个信息窗口,在其中使用来自 2 个不同IdentifyTask
s 的值:
这是我的代码:
dojo.connect(map, "onClick", executeIdentifyTask);
identifyTask = new esri.tasks.IdentifyTask("https://server.com/ArcGIS/rest/services/POI_Data/MapServer");
identifyTask2 = new esri.tasks.IdentifyTask("https://server.com/ArcGIS/rest/services/ProRail_Data/MapServer");
identifyParams = new esri.tasks.IdentifyParameters();
identifyParams.tolerance = 15;
identifyParams.returnGeometry = true;
identifyParams.layerIds = [0];
identifyParams.layerOption = esri.tasks.IdentifyParameters.LAYER_OPTION_ALL;
identifyParams.width = map.width;
identifyParams.height = map.height;
identifyParams2 = new esri.tasks.IdentifyParameters();
identifyParams2.tolerance = 10;
identifyParams2.returnGeometry = true;
identifyParams.layerIds = [23, 26, 31, 33];
identifyParams2.layerOption = esri.tasks.IdentifyParameters.LAYER_OPTION_ALL;
identifyParams2.width = map.width;
identifyParams2.height = map.height;
function executeIdentifyTask(evt) {
identifyParams.geometry = evt.mapPoint;
identifyParams.mapExtent = map.extent;
var deferred = identifyTask.execute(identifyParams);
identifyParams2.geometry = evt.mapPoint;
identifyParams2.mapExtent = map.extent;
var deferred2 = identifyTask2.execute(identifyParams2);
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 === 'Spoortoegang') {
console.log(feature.attributes.PARCELID);
var template = new esri.InfoTemplate("ToegangsNummer ${ToegangsNr}", "Toegangsnummer ${ToegangsNr} <br/> Baanvak: ${Baanvak}, <br/> Geocode: ${Geocode}, <br/> Kilometer: ${Kilometrering}");
feature.setInfoTemplate(template);
alert("Spoortoegang");
}
else if (result.layerName === 'sein') {
var template = new esri.InfoTemplate("", "Parcel ID: ${NUMMER}");
feature.setInfoTemplate(template);
}
return feature;
});
});
deferred2.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 === 'Wissels') {
console.log(feature.attributes.PARCELID);
var template = new esri.InfoTemplate("Wissel", "Toegangsnummer ${ToegangsNr} <br/> Baanvak: ${Baanvak}, <br/> Geocode: ${Geocode}, <br/> Kilometer: ${Kilometrering}");
feature.setInfoTemplate(template);
alert("Wissels");
}
else if (result.layerName === 'sein') {
var template = new esri.InfoTemplate("", "Sein Nummer: ${NUMMER}");
feature.setInfoTemplate(template);
alert("sein");
}
else if (result.layerName === 'Sporen') {
console.log(feature.attributes.PARCELID);
var template = new esri.InfoTemplate("Wissel", "Toegangsnummer ${ToegangsNr} <br/> Baanvak: ${Baanvak}, <br/> Geocode: ${Geocode}, <br/> Kilometer: ${Kilometrering}");
feature.setInfoTemplate(template);
alert("Sporen");
}
else if (result.layerName === 'bovenleidingpaal') {
console.log(feature.attributes.PARCELID);
var template = new esri.InfoTemplate("Wissel", "Toegangsnummer ${ToegangsNr} <br/> Baanvak: ${Baanvak}, <br/> Geocode: ${Geocode}, <br/> Kilometer: ${Kilometrering}");
feature.setInfoTemplate(template);
alert("bovenleidingspaal");
}
return feature;
});
});
// InfoWindow expects an array of features from each deferred
// object that you pass. If the response from the task execution
// above is not an array of features, then you need to add a callback
// like the one above to post-process the response and return an
// array of features.
map.infoWindow.resize(195, 75);
map.infoWindow.setFeatures([deferred]);
map.infoWindow.show(evt.mapPoint);
map.infoWindow.resize(195, 75);
map.infoWindow.setFeatures([deferred2]);
map.infoWindow.show(evt.mapPoint);
}
我只从 中获取警报和infowindow
内容deferred2
,而不是deferred