实现思路:
1.arcgis server颁布的FeatureServer处事供给的图层在线编纂能力:
2.实现的在线编纂(增删改),主要是通过前端ajax请求后台FeatureServer处事来实现的
(1):6080/arcgis/rest/services/dlsde/FeatureServer/0/updateFeatures
public void ProcessRequest (HttpContext context) { string featureserverurl = context.Request.Params["featureserverurl"]; string features = context.Request.Params["features"]; string param = "features=" + features + "&f=json"; string url = featureserverurl + "/updateFeatures"; string ret = PostDataToUrl(param, url, "application/x-www-form-urlencoded"); context.Response.Write(ret); }
(2):6080/arcgis/rest/services/dlsde/FeatureServer/0/addFeatures
public void ProcessRequest (HttpContext context) { string featureserverurl = context.Request.Params["featureserverurl"]; string features = context.Request.Params["features"]; string param = "features=" + features + "&f=json"; string url = featureserverurl + "/addFeatures"; string ret = PostDataToUrl(param, url, "application/x-www-form-urlencoded"); context.Response.Write(ret); }
(3):6080/arcgis/rest/services/dlsde/FeatureServer/0/deleteFeatures
public void ProcessRequest (HttpContext context) { string featureserverurl = context.Request.Params["featureserverurl"]; string id = context.Request.Params["OBJECTID"]; string param = "where=OBJECTID=" + id + "&f=json"; string url = featureserverurl + "/deleteFeatures"; string ret = PostDataToUrl(param, url, "application/x-www-form-urlencoded"); context.Response.Write(ret); context.Response.End(); }
3.前端ajax请求
(1)添加一笔记录:
var features = []; var rec = {}; rec.attributes = {}; rec.geometry = DCI.editLayers.geometry; rec.attributes["NAME"] = $("#update_name").val(); rec.attributes["KIND"] = $("#update_kind").val(); features.push(rec); var feats = JSON.stringify(features); /*[{ "attributes": { "NAME": "112", "KIND": "4080" }, "geometry": { "type": "point", "x": 121.29894825018249, "y": 39.72910692098025, "spatialReference": { "wkid": 4326 } } }]*/ var params = { features: feats, f: "pjson", featureserverurl: MapConfig.sdeURL }; $.ajax({ type: "post", //dataType: "json", url: getRootPath() + "handler/AddFeatureHandler.ashx", data: params, //async: false,//同步 success: function (response, textStatus) { var ret = JSON.parse(response); if (ret.addResults && ret.addResults[0].success) { promptdialog("提示", "添加告成!"); DCI.editLayers.InitSde(""); DCI.editLayers.map.infoWindow.hide(); } else { promptdialog("提示", "添加掉败!"); } }, error: function (e) { var error = e; promptdialog("提示", "响应超时!"); } });
(2)改削一笔记录:
var features = []; var rec = {}; rec.attributes = {}; rec.attributes["OBJECTID"] = parseInt(objectid); rec.attributes["NAME"] = $("#update_name").val(); rec.attributes["KIND"] = $("#update_kind").val(); features.push(rec); var feats = JSON.stringify(features); /*[{ "attributes": { "NAME": "112", "KIND": "4080" }, "geometry": { "type": "point", "x": 121.29894825018249, "y": 39.72910692098025, "spatialReference": { "wkid": 4326 } } }]*/ var params = { features: feats, f: "pjson", featureserverurl: MapConfig.sdeURL }; $.ajax({ type: "post", //dataType: "json", url: getRootPath() + "handler/UpdateFeatureHandler.ashx", data: params, //async: false,//同步 success: function (response, textStatus) { var ret = JSON.parse(response); if (ret.updateResults[0].success) { promptdialog("提示", "更新告成!"); DCI.editLayers.InitSde(""); DCI.editLayers.map.infoWindow.hide(); } else { promptdialog("提示", "更新掉败!"); } }, error: function (e) { var error = e; promptdialog("提示", "响应超时!"); } });
(3)删除一笔记录: