【问题标题】:Esri ArcGIS Print the mapEsri ArcGIS 打印地图
【发布时间】:2013-06-15 12:31:18
【问题描述】:

我正在使用 ArcGIS javaScript 3.5,我想实现打印地图。我知道它是一个内置工具,我们也可以使用该服务,但我的问题是实现所有三个步骤(打印、打印、打印输出)一键点击(首选其他点击)。

为此,我做了类似的事情---

首先我在设计级别添加了一个 div 并将可见性设置为 false

   <div id="print_button" style="visibility:hidden;display:none;"></div>

在初始化中我使用 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 之后,我找到了这些元素

<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>

但是我怎么能调用这个点击事件,因为它很容易找到元素但是调用点击事件并不简单,或者我不知道如何调用 data-dojo-attach-event="ondijitclick:_onClick" 这个事件?

你能建议我如何调用这个事件吗?

【问题讨论】:

  • 技术上很好的笑话@Juffy 但这不是做的正确时间。如果你有任何答案,然后发布....
  • 当然,这没有帮助。也许翻译失败了,但在要求答案之前只等待 7 小时(记住这是一个全球站点,我们中的一些人已经睡着了)不会为您赢得任何朋友。 :)

标签: javascript arcgis


【解决方案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

并注意第二个&lt;span&gt; 标记上的data-dojo-attach-event 标记。我会看看找到那个&lt;span&gt; 标签,看看你是否可以在它上面引发点击事件。


编辑:

是的,.click()ing 正确的元素确实会触发打印任务,我刚刚在自己的应用程序中尝试过。我广泛使用 jQuery,所以我使用选择器 #printButton .dijitInline 来查找类 .dijitInline 的任何元素,它是 &lt;div id="printButton"&gt; 的子类:

$('#printButton .dijitInline').click();

...这就像我用鼠标单击按钮一样触发了打印任务。您应该可以使用dojo equivalent 找到正确的元素并单击它。

【讨论】:

  • 感谢@Juffy 再次回复。而且我知道这个 document.getElementById('print_button').click() 将不起作用,因为它是一个 div。
  • 不,这不是因为它是一个 div - div 是完全可点击的。这是因为没有为该 div 定义 onClick() 行为,智能部分在子节点中。
  • 我曾经使用过:require(["dojo/query", "dojo/dom"], function (query, dom) { var node = dom.byId("print_button"); nl = query (".dijitButtonNode", 节点); if (nl.length > 0) nl[0].click(); });
  • 是否有任何其他方式,例如该 print_button 正在使用的直接调用打印事件......因为我遇到了很多问题......
  • 您好,我正在尝试调用 PrintingTools (GPServer) - 导出 Web 地图任务 - 手动执行。为此,我需要将我的地图对象更改为 json 对象(Web Map as JSON:(GPString))。这是第一个论点。所以我可以手动构造 json 对象,但是有什么方法可以直接在 Arcgis javascript 3.5 API 中获取 Json 对象?
猜你喜欢
  • 2015-03-10
  • 2020-12-09
  • 1970-01-01
  • 1970-01-01
  • 2013-11-09
  • 1970-01-01
  • 2021-02-25
  • 2015-05-30
  • 1970-01-01
相关资源
最近更新 更多