用rest api 添加数据集中的要素,提示:当前数据服务不可编辑
function AddFeature()
{
var commit=getcommit();
var uri="http://localhost:8090/iserver/services/data-map_new/rest/data/datasources/orcl/datasets/POINT_TEST/features.rjson";
//欲增加的要素信息。
var NewFeature={
"ID": 5000,
"fieldNames": [
"SMID",
"SMX",
"SMY",
"SMLIBTILEID",
"SMUSERID",
"NAME"
],
"fieldValues": [
"5000",
"300",
"200",
"1",
"0",
"杭州"
],
"geometry": {
"id": 5000,
"parts": null,
"points": [{
"x": 300,
"y": 200
}],
"style": null,
"type": "POINT"
}
}
//欲增加的要素信息集合(包含1个要素)
var entity=[NewFeature];
commit.open("POST",encodeURI(uri)+"?returnContent=true",false,"","");
commit.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
commit.send(toJSON(entity));
//解析从服务器端返回的 json 字符串,解析为一个 JavaScript 对象。
alert(commit.responseText);
var response = json_parse(commit.responseText, null);
alert(response);
//获取用作显示的 Div 容器。
var container = document.getElementById('container');
//输出结果
container.innerHTML="";
if (response.length>0)
{
container.innerHTML+='<p>sucessinfo:</p>';
container.innerHTML+='<p>sucess ID 为:'+response[0]+'</p>';
}else{
container.innerHTML+='<p>fail</p>';
}
}