-
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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
