當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


JavaScript ArcGIS Portal.createPrintTask用法及代碼示例

基本信息

以下是所在類或對象的基本信息。

AMD: require(["esri/portal/Portal"], (Portal) => { /* code goes here */ });

ESM: import Portal from "@arcgis/core/portal/Portal";

類: esri/portal/Portal

繼承: Portal > Accessor

自從:用於 JavaScript 4.0 的 ArcGIS API

用法說明

Portal.createPrintTask函數(或屬性)的定義如下:

createPrintTask () {Promise<PrintTask>}


自從:ArcGIS 適用於 JavaScript 4.12 的 API
已棄用 從 4.21 版本開始。請使用 print 和 helperServices 代替。

一個幫助函數,它返回門戶的 PrintTask helper service 的實例。

返回:

類型 說明
Promise<PrintTask> 解析後,返回 PrintTask 的實例。

例子:

// example using "esri/rest/print" with helperServices

require([
 "esri/portal/Portal",
 "esri/rest/print",
 "esri/rest/support/PrintTemplate",
 "esri/rest/support/PrintParameters",
 ...
], function(Portal, print, PrintTemplate, PrintParameters, ... ) {

  // create new Portal object with relevant URL
  const portal = new Portal({
     url: "YOUR_PORTAL_URL"
  });

  const template = new PrintTemplate({
    format: "pdf",
    exportOptions: {
      dpi: 12
    },
    layout: "a4-portrait",
    layoutOptions: {
      titleText: "Gillette Stadium",
      authorText: "Thomas B."
    }
  });

  const params = new PrintParameters({
    view: view,
    template: template
  });

  // load Portal instance
  portal.load().then(function() {
    // access helperServices from the Portal instance
    // to get the print URL of interest
    const printURL = portal.helperServices.printTask.url;
    // use helperServices to perform printing
    print.execute(printURL, params).then(printResult).catch(printError);
  }

  function printResult(result) {
    console.log(result.url);
    window.open(result.url);
  }

  function printError(err) {
    console.log("Something broke: ", err);
  }
});

相關用法


注:本文由純淨天空篩選整理自arcgis.com大神的英文原創作品 Portal.createPrintTask。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。