This article mainly describes the use of the ArcGIS API implementation layer Online editing function module, as follows:
Implementation ideas:
The layer online editing capabilities provided by the Featureserver service released by the 1.arcgis server:
2. Implementation of online editing (deletion), mainly through the front-end Ajax request Background Featureserver service to achieve
(1) Http://120.199.78.138:6080/arcgis/rest/services/dlsde/FeatureServer/0/updateFeatures
void ProcessRequest (HttpContext context) { = context. request.params["Featureserverurl"]; = Context. request.params["Features"]; = "features=" + features + "&f=json"; = Featureserverurl + "/updatefeatures"; = Postdatatourl (param, url, "application/x-www-form-urlencoded"); Context. Response.Write (ret);}
(2) Http://120.199.78.138:6080/arcgis/rest/services/dlsde/FeatureServer/0/addFeatures
void ProcessRequest (HttpContext context) { = context. request.params["Featureserverurl"]; = Context. request.params["Features"]; = "features=" + features + "&f=json"; = Featureserverurl + "/addfeatures"; = Postdatatourl (param, url, "application/x-www-form-urlencoded"); Context. Response.Write (ret); }
(3) Http://120.199.78.138:6080/arcgis/rest/services/dlsde/FeatureServer/0/deleteFeatures
void ProcessRequest (HttpContext context) { = context. request.params["Featureserverurl"]; = Context. request.params["OBJECTID"]; = "where=objectid=" + ID + "&f=json"; = Featureserverurl + "/deletefeatures"; = Postdatatourl (param, url, "application/x-www-form-urlencoded"); Context. Response.Write (ret); Context. Response.End (); }
3. Front-End AJAX requests
(1) Add a record:
varfeatures = []; varREC = {}; Rec.attributes= {};Rec.geometry=DCI.editLayers.geometry;rec.attributes["NAME"] = $ ("#update_name"). Val (); rec.attributes["KIND" = $ ("#update_kind")). Val (); Features.push (REC); varFeats =json.stringify (features); /*[{"Attributes": {"NAME": "KIND": "4080"}, "geometry": {"type": "Point", "X": 121.29894825018249, "y": 39.72 910692098025, "spatialreference": {"Wkid": 4326}}]*/ varparams = {features:feats, f: "Pjson", Featureserverurl:MapConfig.sdeURL}; $.ajax ({type:"POST", //dataType: "JSON",Url:getrootpath () + "Handler/addfeaturehandler.ashx", Data:params,//async:false,//SynchronizationSuccessfunction(response, textstatus) {varRET =Json.parse (response); if(Ret.addresults && Ret.addresults[0].success) {Promptdialog ("Prompt", "Add success!"); DCI.editLayers.InitSde (""); DCI.editLayers.map.infoWindow.hide (); } Else{Promptdialog ("Prompt", "Add failed!"); }}, Error:function(e) {varError =e; Promptdialog ("Prompt", "Response timed out!"); } });
(2) Modify a record:
varfeatures = []; varREC = {}; Rec.attributes= {};rec.attributes["OBJECTID"] =parseint (Objectid); rec.attributes["NAME"] = $ ("#update_name"). Val (); rec.attributes["KIND" = $ ("#update_kind")). Val (); Features.push (REC); varFeats =json.stringify (features); /*[{"Attributes": {"NAME": "KIND": "4080"}, "geometry": {"type": "Point", "X": 121.29894825018249, "y": 39.72 910692098025, "spatialreference": {"Wkid": 4326}}]*/ varparams = {features:feats, f: "Pjson", Featureserverurl:MapConfig.sdeURL}; $.ajax ({type:"POST", //dataType: "JSON",Url:getrootpath () + "Handler/updatefeaturehandler.ashx", Data:params,//async:false,//SynchronizationSuccessfunction(response, textstatus) {varRET =Json.parse (response); if(ret.updateresults[0].success) {Promptdialog ("Prompt", "Update succeeded!"); DCI.editLayers.InitSde (""); DCI.editLayers.map.infoWindow.hide (); } Else{Promptdialog ("Prompt", "Update failed!"); }}, Error:function(e) {varError =e; Promptdialog ("Prompt", "Response timed out!"); } });
(3) Delete a record:
varObjectid =parseint (ID); varparams ={objectid:objectid, Featureserverurl:MapConfig.sdeURL}; $.ajax ({type:"POST", //dataType: "JSON",Url:getrootpath () + "Handler/deletefeaturehandler.ashx", Data:params,//async:false,//SynchronizationSuccessfunction(response, textstatus) {varRET =Json.parse (response); if(ret.success) {Promptdialog ("Prompt", "Delete succeeded!"); DCI.editLayers.InitSde (""); DCI.editLayers.map.infoWindow.hide (); } Else{Promptdialog ("Prompt", "Delete failed!"); }}, Error:function(e) {varError =e; Promptdialog ("Prompt", "Response timed out!"); } });
ArcGIS API for JS starter Development series 19 Layers online editing