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
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)http://120.199.78.138: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)http://120.199.78.138: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)刪除一條記錄:
var objectid = parseInt(id);
var params = { OBJECTID: objectid, featureserverurl: MapConfig.sdeURL };
$.ajax({
type: "post",
//dataType: "json",
url: getRootPath() + "handler/DeleteFeatureHandler.ashx",
data: params,
//async: false,//同步
success: function (response, textStatus) {
var ret = JSON.parse(response);
if (ret.success) {
promptdialog("提示", "刪除成功!");
DCI.editLayers.InitSde("");
DCI.editLayers.map.infoWindow.hide();
} else {
promptdialog("提示", "刪除失敗!");
}
},
error: function (e) {
var error = e;
promptdialog("提示", "響應超時!");
}
});
GIS之家新部落格系列釋出更新在GIS之家網站,歡迎關注收藏:GIS之家網站
GIS之家作品:GIS之家
GIS之家交流諮詢:諮詢模式
相關文章
- ArcGis api配合vue開發入門系列(一)引入arcgis api以及載入地圖APIVue地圖
- ArcGIS for iOS 開發系列(5) – 基礎篇-圖層-靜態圖層iOS
- 基於ArcGIS API for Javascript的地圖編輯工具APIJavaScript地圖
- ArcGIS API for Silverlight開發入門準備API
- ArcGis api配合vue開發入門系列(二)距離以及面積的測量APIVue
- 數維圖API文件 SovitJS編輯器整合API方法APIJS
- 通俗易懂的ArcGis開發快速入門
- ArcGIS API for Silverlight 呼叫GP服務載入等值線圖層API
- openlayers入門開發系列之地圖工具欄篇地圖
- 快速開發,7個 Bootstrap 線上編輯器boot
- ArcGIS API for JS 中的styleAPIJS
- ArcGIS API for Silverlight 載入google地圖APIGo地圖
- 百度地圖API入門——(7)新增或刪除圖層地圖API
- 【ArcGIS For JS】前端geojson渲染行政區劃圖層並加標籤前端JSON
- WordPress開發入門03:編輯PHP檔案的2個方式PHP
- ArcGIS API for Silverlight中載入Google地形圖(瓦片圖)APIGo
- Dubbo 入門系列之基於 Dubbo API 開發微服務應用API微服務
- 微信小程式圖文編輯元件開發(偽富文字編輯)微信小程式元件
- ArcGIS for iOS 開發系列(1) – 基本概念iOS
- WYSISYN編輯器 Prosemirror 入門ROS
- 地圖編輯器開發中的心得地圖
- gitbook 入門教程之使用 gitbook-editor 編輯器開發電子書Git
- 雲端計算開發入門課程:Linux重器 vi編輯器Linux
- ArcGIS API for Silverlight載入google地圖(後續篇)APIGo地圖
- ArcGIS API for Silverlight載入BingMap遙感地圖API地圖
- ArcGIS Server ADF開發:根據圖層不同屬性用不同圖示定位興趣點Server
- HTML線上編輯器HTML
- Eclipse下搭建ArcGIS API for Android開發環境EclipseAPIAndroid開發環境
- 《Node.js開發指南》——Node.js入門Node.js
- iMovie 入門教程:影片編輯的利器
- AngularJS開發實戰入門教程AngularJS
- ArcGIS API for Silverlight 動態圖層(ArcGISDynamicMapServiceLayer)的顯示與隱藏API
- 開源線上視覺化流程編輯器視覺化
- vue3 快速入門系列 —— 其他APIVueAPI
- odoo 開發入門教程系列-繼承(Inheritance)Odoo繼承
- odoo 開發入門教程系列-模組互動Odoo
- odoo 開發入門教程系列-QWeb簡史OdooWeb
- arcgis怎樣把面圖層按另一面圖層分割