我有一个以编程方式实现的BusyButton,方法如下:
var printButton = new BusyButton({
busyLabel: "Impression...",
label: "Imprimer",
timeout: 50000,
onClick: printMap
}, "print_button_bis").startup();
50000处的超时并不总是理想的。我如何设置函数完成时发生的超时?在声明按钮时是否有简单的方法来实现这一点,或者应该以某种方式将其集成到printMap函数中?
UPDATE第一次使用printButton.cancel()确实有效,重新启用了该按钮。但是,该按钮第二次无法变为忙碌状态,基本上像正常按钮一样工作。printButton.refresh()导致TypeError:printButton.refresh不是一个函数。
更新2
我通过删除timeout参数更改了printButton,因为cancel()函数现在成功地使忙碌按钮“超时”。
var printButton = new BusyButton({
busyLabel: "Impression...",
label: "Imprimer",
onClick: printMap
}, "print_button_bis").startup();
函数完成后,我将以如下方式重新启用busyButton:
printButton.cancel();
printButton.makeBusy();
但是,makeBusy行会使busyButton在一段时间内保持禁用状态。
以下是所有代码,以防我忽略了其他内容:
require([
"esri/layers/FeatureLayer",
"esri/dijit/Print",
"esri/tasks/PrintTemplate",
"esri/tasks/PrintTask",
"esri/tasks/PrintParameters",
"esri/tasks/GeometryService",
"esri/tasks/ProjectParameters",
"esri/geometry/Point",
"esri/SpatialReference",
"esri/request",
"esri/config",
"dijit/registry",
"dijit/form/ComboBox",
"dijit/form/Button",
"dijit/form/CheckBox",
"dojox/form/BusyButton",
"dojo/store/Memory",
"dojo/_base/array",
"dojo/dom",
"dojo/on"
], function(
FeatureLayer,
Print, PrintTemplate,
PrintTask, PrintParameters,
GeometryService,
ProjectParameters,
Point, SpatialReference,
esriRequest, esriConfig, registry,
ComboBox, Button, CheckBox, BusyButton, Memory,
arrayUtils, dom, on
) {
var printUrl = "http://ourserver/arcgis/rest/services/TOOLS/Print_Tool/GPServer/Exporter%20une%20carte%20Web";
esriConfig.defaults.io.proxyUrl = "http://ourwebserver/Java/proxy.jsp";
esri.config.defaults.io.timeout = 300000; //60 seconds = 60000
var scaleCheckBox = new CheckBox({
checked: false,
onChange: function (val) {
//dom.byId('one').innerHTML = val ? 'checked' : 'unchecked';
if (scaleCheckBox.checked) {
//params.template.preserveScale = true;
dijit.byId("scale_select").attr("disabled",false);
console.log("checked");
}
else {
//params.template.preserveScale = false;
dijit.byId("scale_select").attr("disabled",true);
console.log("unchecked");
}
}
}, 'scale_check');
var printButton = new BusyButton({
busyLabel: "Impression...",
label: "Imprimer",
onClick: printMap
}, "print_button_bis").startup();
function printMap(){
var printMap = new esri.tasks.PrintTask(printUrl);
var params = new esri.tasks.PrintParameters();
var template = new esri.tasks.PrintTemplate();
document.getElementById("print_status").innerHTML = "Impression en cours...";
document.getElementById("output_url").innerHTML = "";
var layout = dojo.byId("printLayoutId");
var index = layout.selectedIndex;
var selectedValue_layout = layout.options[index].value;
var format = dojo.byId("format");
var index = format.selectedIndex;
var selectedValue_format = format.options[index].value;
var lat = window.myMap.extent.getCenter().getLatitude().toFixed(2);
var long = window.myMap.extent.getCenter().getLongitude().toFixed(2);
var latLong = "Latitude : " + lat + " - Longitude : " + long;
var X;
var Y;
var rgpfSixSudSR = new SpatialReference ({
wkid : 3297
});
var wgsGCSEightFourSR = new SpatialReference ({
wkid : 4326
});
var geometryService = new GeometryService("http://ourserver/arcgis/rest/services/Utilities/Geometry/GeometryServer");
var inputPoint = new Point(lat, long, wgsGCSEightFourSR);
var prjParams = new ProjectParameters ();
prjParams.geometries = [inputPoint];
prjParams.outSR = rgpfSixSudSR;
geometryService.project(prjParams, function (outputpoint) {
console.log('Conversion completed');
X = outputpoint[0].x;
Y = outputpoint[0].y;
});
var center = "X : " + X + " - Y : " + Y;
console.log(latLong);
console.log(center);
params.map = window.myMap;
if (scaleCheckBox.checked) {
params.template = {
layout: selectedValue_layout,
format: selectedValue_format,
preserveScale: true,
layoutOptions: {
customTextElements : [
{
centerLatLong: latLong
}
]
}
}
console.log("checked");
}
else {
params.template = {
layout: selectedValue_layout,
format: selectedValue_format,
preserveScale: false,
layoutOptions: {
customTextElements : [
{
centerLatLong: latLong
}
]
}
}
console.log("unchecked");
}
printMap.execute(params, printResult);
function printResult(result){
console.log(result.url);
document.getElementById("print_status").innerHTML = "";
document.getElementById("output_url").href = result.url;
document.getElementById("output_url").innerHTML = "Impression";
var printButton = dijit.byId("print_button_bis");
printButton.cancel();
printButton.makeBusy(); //this one does not make it busy (only busy the first time)
var printWindow = window.open(result.url);
};
};
});
1条答案
按热度按时间umuewwlo1#
可以使用cancel()和makeBusy()以编程方式控制按钮的状态。不需要refresh()。以下是一个示例: