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


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

基本信息

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

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.debounce函數(或屬性)的定義如下:

debounce (callback) {Function} static


自從:ArcGIS 適用於 JavaScript 4.12 的 API

用於確保輸入函數一次不會同時被多次調用的實用程序。這對於高度交互的應用程序很有用,例如對 mouse-move 或 mouse-drag 事件執行統計查詢的應用程序。您可以"debounce" 或取消函數執行,而不是對每個此類事件執行查詢,直到相同函數調用的先前執行完成。這提高了此類應用程序的性能和用戶體驗。

參數:

類型說明
callback Function

防止在執行對同一函數的先前調用期間執行的函數。這通常是可以在 mouse-move 或 mouse-drag 事件上調用的函數。

返回:

類型 說明
Function 與回調具有相同簽名的函數。

例子:

// Queries a layer for the count of features that intersect a
// 1 km buffer of the pointer location. The debounce() method
// prevents the updateStatistics function from executing before
// a previous invocation of the same function finishes.
const updateStatistics = promiseUtils.debounce(function (geometry) {
  return layerView.queryFeatures({
    geometry,
    distance: 1,
    units: "kilometers",
    outStatistics: [{
      onStatisticField: "*",
      outStatisticFieldName: "feature_count",
      statisticType: "count"
    }]
  }).then(function(featureSet) {
    console.log(`Feature Count: ${featureSet.features[0].attributes["feature_count"]}`);
  });
});

view.on("drag", (event) => updateStatistics(view.toMap(event)));

相關用法


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