我想要的是,我想打开一个信息窗口,在其中使用2个不同IdentifyTask
中的值:
这是我的代码:
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
最佳答案
您可以缩短deferred2
中的代码:
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;
var template;
switch(result.layerName){
case 'Wissels':
case 'Sporen':
case 'bovenleidingpaal':
template = new esri.InfoTemplate("Wissel", "Toegangsnummer ${ToegangsNr} <br/> Baanvak: ${Baanvak}, <br/> Geocode: ${Geocode}, <br/> Kilometer: ${Kilometrering}");
break;
case 'sein':
var template = new esri.InfoTemplate("", "Sein Nummer: ${NUMMER}");
break;
}
console.log(feature.attributes.PARCELID);
feature.setInfoTemplate(template);
alert(result.layerName);
return feature;
});
});
这应该工作相同。
关于javascript - 仅执行Deferred2的Javascript,不同时执行,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/13580047/