添加新要素到图层
javascript
_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)
},
});
})
},
javascript
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)
},
});
})
},