首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

arcgis api for js入门开发系列十九图层在线编辑

本篇主要讲述的是利用arcgis api实现图层在线编辑功能模块,效果图如下:

实现思路:

1.arcgis server发布的FeatureServer服务提供的图层在线编辑能力:

2.实现的在线编辑(增删改),主要是通过前端ajax请求后台FeatureServer服务来实现的

(1)http://120.199.78.138:6080/arcgis/rest/services/dlsde/FeatureServer/0/updateFeatures

publicvoidProcessRequest (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)http://120.199.78.138:6080/arcgis/rest/services/dlsde/FeatureServer/0/addFeatures

publicvoidProcessRequest (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)http://120.199.78.138:6080/arcgis/rest/services/dlsde/FeatureServer/0/deleteFeatures

publicvoidProcessRequest (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)添加一条记录:

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": "112", "KIND": "4080" }, "geometry": { "type": "point", "x": 121.29894825018249, "y": 39.72910692098025, "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,//同步success:function(response, textStatus) {varret =JSON.parse(response);

if(ret.addResults && ret.addResults[0].success) { promptdialog("提示", "添加成功!"); DCI.editLayers.InitSde(""); DCI.editLayers.map.infoWindow.hide(); }else{ promptdialog("提示", "添加失败!"); } }, error:function(e) {varerror =e; promptdialog("提示", "响应超时!"); } });

(2)修改一条记录:

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": "112", "KIND": "4080" }, "geometry": { "type": "point", "x": 121.29894825018249, "y": 39.72910692098025, "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,//同步success:function(response, textStatus) {varret =JSON.parse(response);

if(ret.updateResults[0].success) { promptdialog("提示", "更新成功!"); DCI.editLayers.InitSde(""); DCI.editLayers.map.infoWindow.hide(); }else{ promptdialog("提示", "更新失败!"); } }, error:function(e) {

varerror =e; promptdialog("提示", "响应超时!"); } });

(3)删除一条记录:

varobjectid =parseInt(id);

varparams ={ OBJECTID: objectid, featureserverurl: MapConfig.sdeURL }; $.ajax({ type:"post",//dataType: "json",url: getRootPath() + "handler/DeleteFeatureHandler.ashx", data: params,//async: false,//同步success:function(response, textStatus) {varret =JSON.parse(response);if(ret.success) { promptdialog("提示", "删除成功!"); DCI.editLayers.InitSde(""); DCI.editLayers.map.infoWindow.hide();}else{ promptdialog("提示", "删除失败!");}, error:function(e) {

varerror =e; promptdialog("提示", "响应超时!");}});

  • 发表于:
  • 原文链接http://kuaibao.qq.com/s/20180318G0W1QN00?refer=cp_1026
  • 腾讯「腾讯云开发者社区」是腾讯内容开放平台帐号(企鹅号)传播渠道之一,根据《腾讯内容开放平台服务协议》转载发布内容。
  • 如有侵权,请联系 cloudcommunity@tencent.com 删除。

扫码

添加站长 进交流群

领取专属 10元无门槛券

私享最新 技术干货

扫码加入开发者社群
领券