如何使用一个变量放置两个执行语句
how to place two execute statements with one variable?
我想使用 javascript/dojo 用一个变量触发以下两个执行语句。
identifyTaskParcels.execute(identifyParams);
identifyTaskZoning.execute(identifyParams);
我尝试了以下各种变体:
var deferred = [identifyTaskParcels.execute(identifyparams), identifyTaskZoning.execute(identifyParams)];
这是可以做到的吗?
编辑
我正在尝试构建一个 Web 制图应用程序,该应用程序从 2 个服务中提取信息,并在带有功能信息的信息窗口/弹出窗口中显示它们。
使用 1 个服务很容易做到,但我发现使用 2 个服务很难做到。工作代码示例:
编辑 2
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:path/to/url/service");
identifyTaskParcels = new esri.tasks.IdentifyTask("https://path/to/url/service");
//Set Zoning Parameters
identifyParamsZoning = new esri.tasks.IdentifyParameters();
identifyParamsZoning.tolerance = 3;
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 = 3;
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);
};
我不确定我是否理解这个问题,但似乎您需要dojo/promise/all
:
require(["dojo/Deferred", "dojo/promise/all"], function(Deferred, all) {
var taskParcels = new Deferred();
var taskZoning = new Deferred();
var deferred = all([taskParcels, taskZoning])
deferred.then(function(result) {
console.log(result);
});
taskParcels.resolve('hello');
setTimeout(function() {
taskZoning.resolve('world');
}, 1000);
});
查看实际操作:http://jsfiddle.net/phusick/S3b4B/
相关文章:
- Javascript RegEx-强制执行两个最大长度
- 如何停止两个按钮执行相同的工作?在这种情况下,它们都会滚动到顶部
- 在两个元素的 onrender 事件之后执行函数
- 表单以执行两个不同的操作
- 如何执行两个javascript函数
- 带有两个提交按钮的提交表单,每个按钮执行不同的操作问题
- 根据两个异步函数调用的结果执行
- 为什么获胜't执行两个Jquery行
- 执行Jquery函数()的两个条件
- IE可以同时执行两个JavaScript函数吗?
- 如果在 JavaScript 中的 if 条件之后在执行块中使用两个等于而不是只有一个,会发生什么情况
- jQuery.toggle - 在交替单击时执行两个或多个处理程序
- 两个捕获的承诺/块声明都没有执行
- 满足两个条件时的 jQuery 执行函数
- 为什么 asp:文本框的两个 onblur 事件都被执行了
- 如何在同一个表单中有两个按钮来在 ajax 中执行不同的操作
- 两个 ng 单击函数不会一起执行
- 如何在jQuery中单击两个按钮之一时执行功能
- 如何检查两个单独函数的执行结果
- 如何使用一个变量放置两个执行语句