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


JavaScript ArcGIS promiseUtils.create用法及代碼示例

基本信息

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

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

ESM: import * as promiseUtils from "@arcgis/core/core/promiseUtils";

對象: esri/core/promiseUtils

自從:用於 JavaScript 4.2 的 ArcGIS API

用法說明

promiseUtils.create函數(或屬性)的定義如下:

create (executor) {Promise}


用於創建和解決承諾的便捷實用方法。

參數:

類型說明
executor Executor

將使用兩種方法調用的函數, resolvereject

返回:

類型 說明
Promise 執行者將履行的承諾。

例子:

function fetchImage(url) {
  return promiseUtils.create(function(resolve, reject){
    const image = document.createElement("img");
    image.onload = function() {
      image.load = image.onerror = null;
      resolve(image);
    };

    image.onerror = function() {
      image.load = image.onerror = null;
      reject(new Error("Error while loading the image"));
    }

    image.src = url;
  });
}

fetchImage(".........")
  .then(function(image){
    console.log(image);
  });
// Load multiple modules conditionally
require([
  "esri/core/promiseUtils"
], function( promiseUtils ) {
  // load modules based on whether a user selects
  // a UI option to apply class breaks to a layer
  if (classBreaksSelected) {
    return promiseUtils.create(function(resolve, reject) {
      require([ "esri/renderers/ClassBreaksRenderer" ], resolve);
    }).then(function(ClassBreaksRenderer) {
      // Create renderer and apply it to the desired layer

    });
  }
});

相關用法


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