arcgis api for js4.x 图层要素的增删改---使用服务地址的/applyEdits直接进行删除

2023-12-14 16:37:57

添加新要素到图层

_addGeo(){
        cosnt self = this
        let url = https://......./featurelayer/某某某图层/3
        let geo = 你新绘制的图形
        let attributes = 你新绘制图形的属性信息
        let addingGraphics = Graphic({
               geometry:geo,
               attributes:attributes
        })
        const pro = self._addToLayer(url , JSON.stringify(addingGraphics).replaceAll("\\", ""))
        Promise.all([pro]).then((result) => {
            const response = JSON.parse(result)
            if (response.addResults != undefined && response.addResults.length > 0) {                   
                self.$message.success("保存成功");
            } else {
                self.$message.error("保存失败,请检查服务。");
            }
            self.mapClear();
        })
},

_addToLayer(url, param) {
            var formData = new FormData();
            formData.append("f", "pjson");
            formData.append("adds", param);
            return new Promise((resolve, reject) => {
                const A= "A"
                const B= "B"
                $.ajax({
                    url: `${url}/applyEdits`,
                    type: "post",
                    async: true,
                    data: formData,
                    processData: false,
                    contentType: false,
                    headers: { //头部信息添加到这里
                        A: A,
                        B: B,
                    },
                    success: function (response) {
                        resolve(response)
                    },
                    error: function (e) {
                        reject(null)
                    },
                });
            })
        },
deletegeo(){
        cosnt self = this
        let url = https://......./featurelayer/某某某图层/3
        let feat= 你要删除的要素
let objs = [feat.attributes.objectid]  //objs是数组,可以删除多个。objectid是服务的标识字段值
 let pro1 = self._delFromLayer(url, objs)
Promise.all([pro1]).then((result) => {
                const response1 = JSON.parse(result[0])
                if (response1.deleteResults != undefined && response1.deleteResults.length > 0 ) {
                    self.$message.success("删除成功。");
                } else {
                    self.$message.error("删除失败,请检查服务。");
                }
            })

},

_delFromLayer(url, param) {
            const self = this
            var formData = new FormData();
            formData.append("f", "pjson");
            formData.append("deletes", param);
            return new Promise((resolve, reject) => {
                const A= "A"
                const B= "B"
                $.ajax({
                    url: `${url}/applyEdits`,
                    type: "post",
                    async: true,
                    data: formData,
                    processData: false,
                    contentType: false,
                    headers: {
                        A: A,
                        B: B
                    },
                    success: function (response) {
                        resolve(response)
                    },
                    error: function (e) {
                        reject(null)
                    },
                });
            })
        },

文章来源:https://blog.csdn.net/baicai_123/article/details/134926798
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。