-
applyEdits(edits, options){Promise<EditsResult>}
將編輯應用於圖層中的要素。可以創建新函數,也可以更新或刪除現有函數。特征幾何形狀和/或屬性可以被修改。僅適用於 feature service 中的圖層以及通過圖層源設置的客戶端函數。還可以添加、更新或刪除附件。
如果使用 applyEdits() 在運行時添加、刪除或更新客戶端函數,則使用 queryFeatures() 返回更新的函數。
在沒有vertical coordinate system 信息的服務上調用applyEdits 方法時,
edits對象中幾何的z-values 將自動轉換為匹配圖層的空間參考。示例:服務有一個使用feet單位的水平空間參考,並且基於meter單位使用z-values 調用applyEdits(),然後該方法將自動將z 值從meter轉換為feet單位.從版本 4.17 開始,使用 applyEdits 將帶有 z-values 的幾何圖形添加到帶有
hasZ: false的 FeatureLayer 不再靜默刪除 z-value 並且現在會引發錯誤。參數:
規格:類型 說明 edits Object包含要添加、更新或刪除的函數和附件的對象。
規格:addFeatures可選的 要添加的特征數組或collection。添加新函數時必須提供不可為空字段的值。日期字段必須具有表示通用時間的 numeric 值。
updateFeatures可選的 要更新的函數的數組或collection。每個函數都必須具有有效的 objectId。更新函數時必須提供不可為空字段的值。日期字段必須具有代表通用時間的 numeric 值。
可選的 要素的數組或collection,或者每個要刪除的要素的帶有
objectId或globalId的對象數組。當傳遞一個數組或一組要素時,每個要素必須有一個有效的 objectId。使用對象數組時,每個對象必須為objectId或globalId屬性設置有效值。addAttachments可選的 要添加的附件數組。僅當
options.globalIdUsed參數設置為true時適用。用戶必須提供全局 ID 才能添加所有附件。updateAttachments可選的 要更新的附件數組。僅當
options.globalIdUsed參數設置為true時適用。用戶必須提供全局 ID 才能更新所有附件。可選的 用於刪除附件的全局 ID 數組。僅當
options.globalIdUsed參數設置為true時適用。options Object可選的 編輯要素或附件時要指定的其他編輯選項。
規格:gdbVersion可選的 應用編輯的地理數據庫版本。僅當圖層的 capabilities.data.isVersioned 屬性為
true時,此參數才適用。如果未指定 gdbVersion 參數,則會對已發布Map的版本進行編輯。returnEditMoment可選的 指示編輯結果是否應返回應用編輯的時間。如果是
true,要素服務將返回編輯結果的editMoment屬性中應用編輯的時間。僅適用於 ArcGIS 服務器服務。此選項是在 4.20 版本中添加的。returnServiceEditsOption可選的 如果設置為
original-and-current-features,則 EditedFeatureResult 參數將包含在applyEdits響應中。它包含作為編輯要素的結果參與數據庫中複合關係的所有已編輯要素。請注意,即使對於刪除,也會返回已刪除要素的幾何和屬性。original-and-current-features選項僅在rollbackOnFailureEnabled為true時有效。默認值為none,它不會在響應中包含EditedFeatureResult參數。這僅適用於ArcGIS 服務器服務。此選項是在 4.20 版本中添加的。可能的值:"none"|"original-and-current-features"
rollbackOnFailureEnabled可選的 指示是否僅當所有提交的編輯都成功時才應應用編輯。如果是
false,即使某些提交的編輯失敗,服務器也會應用成功的編輯。如果是true,則僅當所有編輯成功時服務器才會應用編輯。如果使用此參數,圖層的capabilities.editing.supportsRollbackOnFailure屬性必須為true。如果某個層的supportsRollbackOnFailure是false,則rollbackOnFailureEnabled將始終為 true,無論參數如何設置。globalIdUsed可選的 指示是否可以使用要素或附件的 globalIds 應用編輯。僅當圖層的 capabilities.editing.supportsGlobalId 屬性為
true時,此參數才適用。當false時,隨函數一起提交的 globalId 將被忽略,並且服務會為新函數分配新的 globalId。當true時,globalIds 必須與新函數一起提交。更新現有函數時,如果globalIdUsed為false,則必須提供待更新函數的 objectId。如果globalIdUsed為true,則必須提供要更新的函數的 globalId。刪除現有函數時,請將此屬性設置為false,因為刪除操作在當前版本的 API 中僅接受objectIds。添加、更新或刪除附件時,必須將
globalIdUsed參數設置為true,並設置附件globalId。對於新附件,用戶必須提供 globalIds。為了更新或刪除附件,客戶端必須包含其 globalId。當globalIdUsed為false時,編輯有效負載中不支持附件。// add an image attachments to features function addAttachment(selectedFeature) { const blob = new Blob(byteArrays, { type: "image/png" }); addAttachments.push({ feature: selectedFeature, attachment: { globalId: "8c4d6085-a33c-42a0-8e11-21e9528bca0d", name: "brokenLight", data: blob } }); const edits = { addAttachments: addAttachments }; const options = { // globalIdUsed has to be true when adding, updating or deleting attachments globalIdUsed: true, rollbackOnFailureEnabled: true }; featureLayer.applyEdits(edits, options).then(function(results) { console.log("edits added: ", results); }); }返回:
類型 說明 Promise<EditsResult> 解析後,將返回 EditsResult 對象。 例子:
function addFeature(geometry) { const attributes = {}; attributes["Description"] = "This is the description"; attributes["Address"] = "380 New York St"; // Date.now() returns number of milliseconds elapsed // since 1 January 1970 00:00:00 UTC. attributes["Report_Date"] = Date.now(); const addFeature = new Graphic({ geometry: geometry, attributes: attributes }); const deleteFeatures = [ { objectId: 467 }, { objectId: 500 } ]; // or specify globalIds of features to be deleted // const deleteFeature = [ // { globalId: "18633204-1801-4d35-a73a-174563608ad9" } // ]; const promise = featureLayer.applyEdits({ addFeatures: [addFeature], deleteFeatures: deleteFeatures }); }
基本信息
以下是所在類或對象的基本信息。
AMD:
require(["esri/layers/FeatureLayer"], (FeatureLayer) => { /* code goes here */ });
ESM:
import FeatureLayer from "@arcgis/core/layers/FeatureLayer";
類:
esri/layers/FeatureLayer
繼承: FeatureLayer > Layer > Accessor
自從:用於 JavaScript 4.0 的 ArcGIS API
用法說明
FeatureLayer.applyEdits函數(或屬性)的定義如下:
相關用法
- JavaScript ArcGIS FeatureLayer.apiKey用法及代碼示例
- JavaScript ArcGIS FeatureLayer.addAttachment用法及代碼示例
- JavaScript ArcGIS FeatureLayer.queryExtent用法及代碼示例
- JavaScript ArcGIS FeatureLayer.when用法及代碼示例
- JavaScript ArcGIS FeatureLayer.getFieldDomain用法及代碼示例
- JavaScript ArcGIS FeatureLayer.queryFeatureCount用法及代碼示例
- JavaScript ArcGIS FeatureLayer.formTemplate用法及代碼示例
- JavaScript ArcGIS FeatureLayer.relationships用法及代碼示例
- JavaScript ArcGIS FeatureLayer.objectIdField用法及代碼示例
- JavaScript ArcGIS FeatureLayer.opacity用法及代碼示例
- JavaScript ArcGIS FeatureLayer.queryRelatedFeatures用法及代碼示例
- JavaScript ArcGIS FeatureLayer.datesInUnknownTimezone用法及代碼示例
- JavaScript ArcGIS FeatureLayer.featureEffect用法及代碼示例
- JavaScript ArcGIS FeatureLayer.timeInfo用法及代碼示例
- JavaScript ArcGIS FeatureLayer.createQuery用法及代碼示例
- JavaScript ArcGIS FeatureLayer.queryRelatedFeaturesCount用法及代碼示例
- JavaScript ArcGIS FeatureLayer.outFields用法及代碼示例
- JavaScript ArcGIS FeatureLayer.version用法及代碼示例
- JavaScript ArcGIS FeatureLayer.fullExtent用法及代碼示例
- JavaScript ArcGIS FeatureLayer.visible用法及代碼示例
- JavaScript ArcGIS FeatureLayer.labelingInfo用法及代碼示例
- JavaScript ArcGIS FeatureLayer.maxScale用法及代碼示例
- JavaScript ArcGIS FeatureLayer.queryTopObjectIds用法及代碼示例
- JavaScript ArcGIS FeatureLayer.queryTopFeatureCount用法及代碼示例
- JavaScript ArcGIS FeatureLayer.on用法及代碼示例
注:本文由純淨天空篩選整理自arcgis.com大神的英文原創作品 FeatureLayer.applyEdits。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
