我正在使用ArcGIS javaScript 3.5,我想实现打印地图。我知道它是一个内置工具我们也可以使用该服务但我的问题是实现所有三个步骤(打印,打印,PrintOut)只需点击一下(首选其他点击)。
为此我做了类似---
的事情首先我在设计级别添加了一个div并将visiblity设置为false
<div id="print_button" style="visibility:hidden;display:none;"></div>
在init中我使用esri.dijit.Print选项
var app = {};
app.webmapId = "8315cf7d20f0484e869c4791f70f4f15";
app.printUrl = "abc/arcgis/rest/services/Utilities/PrintingTools/GPServer/Export%20Web%20Map%20Task";
var layouts = [{
"name": "Letter ANSI A Landscape",
"label": "Landscape (PDF)",
"format": "pdf",
"options": {
"legendLayers": [], // empty array means no legend
"scalebarUnit": "Miles",
"titleText": "Map"
}
}];
var templates = [];
dojo.forEach(layouts, function (lo) {
var t = new esri.tasks.PrintTemplate();
t.layout = lo.name;
t.label = lo.label;
t.format = lo.format;
t.layoutOptions = lo.options
templates.push(t);
});
app.printer = new esri.dijit.Print({
"map": map,
"templates": templates,
url: app.printUrl,
}, dojo.byId("print_button"));
app.printer.startup();
并在我的内部点击我想点击此打印按钮
function export1() {
document.getElementById('print_button').click();//This is not working obviously this is not a button
return false;
}
我怎么能做到这一点。请帮帮我。
在分析之后,我发现了这些元素
<div class="esriPrint">
<span class="dijit dijitReset dijitInline dijitButton esriPrintButton dijitButtonDisabled dijitDisabled"
role="presentation" widgetId="dijit_form_Button_0">
<span class="dijitReset dijitInline dijitButtonNode" role="presentation" data-dojo-attach-event="ondijitclick:_onClick">
<span disabled="" class="dijitReset dijitStretch dijitButtonContents" id="dijit_form_Button_0" role="button" aria-disabled="true"
aria-labelledby="dijit_form_Button_0_label" style="-ms-user-select: none;" data-dojo-attach-point="titleNode,focusNode">
<span class="dijitReset dijitInline dijitIcon dijitNoIcon" data-dojo-attach-point="iconNode">
</span>
<span class="dijitReset dijitToggleButtonIconChar">
●
</span>
<span class="dijitReset dijitInline dijitButtonText" id="dijit_form_Button_0_label" data-dojo-attach-point="containerNode">
Printing
</span>
</span>
</span>
<input tabindex="-1" disabled="" class="dijitOffScreen" role="presentation" type="button" value="" data-dojo-attach-point="valueNode">
</span></div>
<div class="esriPrint">
<span class="dijit dijitReset dijitInline dijitButton esriPrintButton" role="presentation" widgetId="dijit_form_Button_1">
<span class="dijitReset dijitInline dijitButtonNode" role="presentation" data-dojo-attach-event="ondijitclick:_onClick">
<span tabindex="0" class="dijitReset dijitStretch dijitButtonContents" id="dijit_form_Button_1"
role="button" aria-labelledby="dijit_form_Button_1_label" style="-ms-user-select: none;" data-dojo-attach-point="titleNode,focusNode">
<span class="dijitReset dijitInline dijitIcon dijitNoIcon" data-dojo-attach-point="iconNode">
</span>
<span class="dijitReset dijitToggleButtonIconChar">
●
</span>
<span class="dijitReset dijitInline dijitButtonText" id="dijit_form_Button_1_label" data-dojo-attach-point="containerNode">
Print
</span>
</span>
</span>
<input tabindex="-1" class="dijitOffScreen" role="presentation" type="button" value="" data-dojo-attach-point="valueNode">
</span></div>
但我如何调用此click事件,因为它很容易找到该元素,但调用click事件并不简单,或者我不知道如何调用data-dojo-attach-event =“ondijitclick:_onClick”此事件?
你能建议我怎么称呼这个事件吗?
答案 0 :(得分:1)
虽然这不是一个完整的答案,但我认为你.click()
失败的原因是因为你'点'错了。在我的地图的源代码中,我只有:
<div id="printButton"></div>
但是在运行时Dojo将其扩展为:
<div id="printButton">
<div class="esriPrint">
<span class="dijit dijitReset dijitInline esriPrintButton dijitButton" role="presentation" widgetid="dijit_form_Button_0">
<span class="dijitReset dijitInline dijitButtonNode" data-dojo-attach-event="ondijitclick:_onClick" role="presentation">
...etc
并记下第二个data-dojo-attach-event
标记上的<span>
标记。我会查看找到<span>
标记并查看是否可以在其上引发点击事件。
<小时/> 修改:
是的,.click()
正确的元素是否会触发打印任务,我只是在我自己的应用程序中尝试过。我广泛使用jQuery,所以我使用选择器#printButton .dijitInline
来查找.dijitInline
的子类<div id="printButton">
的任何元素:
$('#printButton .dijitInline').click();
...然后就像我用鼠标点击了按钮那样解雇了打印任务。您应该能够使用dojo equivalent找到正确的元素并单击它。